我要使用以下代码选择型号。
import numpy as np
import pandas as pd
from math import log
from sklearn import model_selection
from sklearn.model_selection import train_test_split as split
from sklearn.metrics import accuracy_score as accuracy
import xgboost as xgb
dataframe_training = pd.read_csv("train.csv")
train_tag=dataframe_training['tags']
train_dummies_tags= train_tag.str.get_dummies(",")
dataframe_training=dataframe_training.filter(items=['review_ratio','log_date_difference','log_price'])
x_train=pd.concat([dataframe_training,train_dummies_tags], axis=1, sort=False)
y_train=dataframe_training.filter(items=['playtime_forever'])
Xtrain, Xtest, Ytrain, Ytest = split(x_train,y_train, test_size=0.25, random_state=7)
from sklearn.ensemble import *
AllRegressorModel = [xgb.XGBRegressor,AdaBoostRegressor,BaggingRegressor,ExtraTreesRegressor,GradientBoostingRegressor,RandomForestRegressor]
def Model_Selection_By_Cross_Valid():
ThisRound_SelectedModel = None,
ThisRound_SelectedModel_Name = None,
ThisRound_SelectedModel_Score = None,
for temp_select_model_name in AllRegressorModel:
kfold = model_selection.KFold(n_splits=10, random_state=7),
print (kfold),
temp_model= temp_select_model_name(),
temp_model.fit(Xtrain, Ytrain.ravel()),
results = model_selection.cross_val_score(temp_model, X_train, Y_train.ravel(), cv=kfold, scoring='neg_mean_squared_error'),
print(temp_select_model_name,results.mean()),
if (ThisRound_SelectedModel == None) or (abs(results.mean()) < ThisRound_SelectedModel_Score):
ThisRound_SelectedModel = temp_model,
ThisRound_SelectedModel_Name = temp_select_model_name,
ThisRound_SelectedModel_Score = abs(results.mean()),
print ("This round Model Name: ", temp_model,"MSE Score: ",abs(results.mean())),
print ("This Model Feature Importance",temp_model.feature_importances_),
print("This Model Do No Have Feature Importance......"),
print ("<----------------------------------->"),
print ("Selected Model Name:", ThisRound_SelectedModel, "MSE Score:",ThisRound_SelectedModel_Score),
return {"ModelName": ThisRound_SelectedModel_Name,"Model": ThisRound_SelectedModel}
运行程序时,
SelectedModel = Model_Selection_By_Cross_Valid()
AttributeError:“元组”对象没有属性“ fit”。
我该如何解决问题?
非常感谢您。