Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';随机回归器';对象没有属性';最佳参数';_Python_Scikit Learn_Random Forest_Grid Search - Fatal编程技术网

Python 属性错误:';随机回归器';对象没有属性';最佳参数';

Python 属性错误:';随机回归器';对象没有属性';最佳参数';,python,scikit-learn,random-forest,grid-search,Python,Scikit Learn,Random Forest,Grid Search,我在使用随机林对我的分类进行网格搜索时遇到此错误 from sklearn.ensemble import RandomForestRegressor rf2 = RandomForestRegressor(random_state = 50) rf2.fit(X_train1, y_train1) ### Grid Search ### num_leafs = [1, 5, 10, 20, 50, 100] parameters3 = [{'n_estimators' : range(10

我在使用随机林对我的分类进行网格搜索时遇到此错误

from sklearn.ensemble import RandomForestRegressor
rf2 = RandomForestRegressor(random_state = 50)
rf2.fit(X_train1, y_train1)

### Grid Search ###
num_leafs = [1, 5, 10, 20, 50, 100]

parameters3 = [{'n_estimators' : range(100,800,20),
             'max_depth': range(1,20,2),
             'min_samples_leaf':num_leafs
             }]


gs3 = GridSearchCV(estimator=rf2,
                  param_grid=parameters3,
                  cv = 10,
                  n_jobs = -1)

gs3 = rf2.fit(X_train1, y_train1)

gs3.best_params_ # <- thats where I get the Error
从sklearn.employ导入随机森林回归器
rf2=随机森林回归器(随机_状态=50)
rf2.装配(X_系列1,y_系列1)
###网格搜索###
num_leafs=[1,5,10,20,50,100]
参数3=[{'n_估计量]:范围(100800,20),
“最大深度”:范围(1,20,2),
“min\u示例叶”:num\u叶
}]
gs3=GridSearchCV(估计器=rf2,
参数网格=参数3,
cv=10,
n_作业=-1)
gs3=rf2.配合(X\U列1,y\U列1)
gs3.best_params#替换此:
gs3=rf2.fit(X\U列1,y\U列1)

据此:
gs3.fit(X\U列1,y\U列1)

然后您将能够使用:
gs3.最佳参数


您的错误是由于您将
gs3
重新分配给
RandomForest()
调用而导致的,因此
gs3
不再是
GridSearchCV
对象。

嗯,您不适合
GridSearch
对象,而是适合
模型(rf2)然后将其分配给
gs3
参数。

你有:

gs3 = GridSearchCV(estimator=rf2,
                  param_grid=parameters3,
                  cv = 10,
                  n_jobs = -1)
gs3 = rf2.fit(X_train1, y_train1)
gs3.best_params_ # <- thats where I get the Error
gs3=GridSearchCV(估计器=rf2,
参数网格=参数3,
cv=10,
n_作业=-1)
gs3=rf2.配合(X\U列1,y\U列1)

谢谢,这就是问题所在!
gs3 = GridSearchCV(estimator=rf2,
                  param_grid=parameters3,
                  cv = 10,
                  n_jobs = -1)
gs3.fit(X_train1, y_train1) # fit the GridSearchCV object
gs3.best_params_ # <- thats where I get the Error