AttributeError:'tuple'对象没有属性'fit'

时间:2018-12-16 20:13:28

标签: python machine-learning regression xgboost mlp

我想对XGBoost使用袋装Mlpregression 如果我使用一种算法,它将正常工作

XGBRegressor_bagging_model = BaggingRegressor(XGBRegressor_model,
                                              n_estimators=100,                                              
                                              max_samples=1.0, 
                                              max_features=1.0, 
                                              bootstrap=True,
                                              oob_score=True, 
                                              warm_start=False,
                                              n_jobs=-1,
                                              verbose=0)

MLP = BaggingRegressor(MLPRegressor_Model,
                       n_estimators=1000,
                       max_samples=1.0,
                       max_features=1.0,
                       bootstrap=True,
                       oob_score=True,
                       warm_start=False,
                       n_jobs=-1,
                       verbose=0)

XGBRegressor_bagging_model.fit(X_train, y_train)
MLP.fit(X_train, y_train)

print("XGBRegressor_bagging_model Predicted Is:", XGBRegressor_bagging_model.predict(X_test)[0:5])

print("MLP Predicted Is:", MLP.predict(X_test)[0:5])

print("XGBRegressor_bagging_model Score Is:", XGBRegressor_bagging_model.oob_score_)
print("MLP Score Is:", MLP.oob_score_)

但是如果我这样使用它

bagging_model = BaggingRegressor((XGBRegressor_model, MLPRegressor_Model), n_estimators=100,max_samples=1.0, max_features=1.0, bootstrap=True, oob_score=True, warm_start=False, n_jobs=-1, verbose=0)

它将无法正常工作并显示此错误

AttributeError: 'tuple' object has no attribute 'fit'

我该怎么做才能解决此问题?

1 个答案:

答案 0 :(得分:2)

在第二版中,您将PrintData( Buffer + iphdrlen + tcpheader->data_offset*4, ( Size - tcpheader->data_offset*4 - iphdr->ip_header_len*4 ) ); 作为回归器。这不是回归变量,而是元组(恰好由回归变量组成)。该错误指出元组不具有方法(XGBRegressor_model, MLPRegressor_Model)

您应该传递这些回归器之一,或从这两个回归器创建复合回归器。