做集成学习的时候出现`AttributeError: 'list' object has no attribute 'set_params'`不知道怎么解决

做集成学习的时候出现AttributeError: 'list' object has no attribute 'set_params'不知道怎么解决

from sklearn.ensemble import AdaBoostRegressor
estimator=[
    ExtraTreesRegressor(random_state=42),
    RandomForestRegressor(random_state=42),
    GradientBoostingRegressor(random_state=42)]
AdaBoost=AdaBoostRegressor(estimator)
AdaBoost.fit(X_train2,Y_train2)
y_pred=AdaBoost.predict(X_test2)
r2_score(Y_test,y_pred)

以下是报错的内容

AttributeError                            Traceback (most recent call last)
 in 
      5     GradientBoostingRegressor(random_state=42)]
      6 AdaBoost=AdaBoostRegressor(estimator)
----> 7 AdaBoost.fit(X_train2,Y_train2)
      8 y_pred=AdaBoost.predict(X_test2)
      9 r2_score(Y_test,y_pred)

~\Anaconda3\lib\site-packages\sklearn\ensemble\_weight_boosting.py in fit(self, X, y, sample_weight)
    992 
    993         # Fit
--> 994         return super().fit(X, y, sample_weight)
    995 
    996     def _validate_estimator(self):

~\Anaconda3\lib\site-packages\sklearn\ensemble\_weight_boosting.py in fit(self, X, y, sample_weight)
    140                 X, y,
    141                 sample_weight,
--> 142                 random_state)
    143 
    144             # Early termination

~\Anaconda3\lib\site-packages\sklearn\ensemble\_weight_boosting.py in _boost(self, iboost, X, y, sample_weight, random_state)
   1037             If None then boosting has terminated early.
   1038         """
-> 1039         estimator = self._make_estimator(random_state=random_state)
   1040 
   1041         # Weighted sampling of the training set with replacement

~\Anaconda3\lib\site-packages\sklearn\ensemble\_base.py in _make_estimator(self, append, random_state)
    146         """
    147         estimator = clone(self.base_estimator_)
--> 148         estimator.set_params(**{p: getattr(self, p)
    149                                 for p in self.estimator_params})
    150 

AttributeError: 'list' object has no attribute 'set_params'

初步怀疑是X_train 的数据格式不对

你可能感兴趣的:(python,大数据,机器学习,python)