Poe*_*dit 7 python scikit-learn grid-search
我正在运行这个:
# Hyperparameter tuning - Random Forest #
# Hyperparameters' grid
parameters = {'n_estimators': list(range(100, 250, 25)), 'criterion': ['gini', 'entropy'],
'max_depth': list(range(2, 11, 2)), 'max_features': [0.1, 0.2, 0.3, 0.4, 0.5],
'class_weight': [{0: 1, 1: i} for i in np.arange(1, 4, 0.2).tolist()], 'min_samples_split': list(range(2, 7))}
# Instantiate random forest
from sklearn.ensemble import RandomForestClassifier
classifier = RandomForestClassifier(random_state=0)
# Execute grid search and retrieve the best classifier
from sklearn.model_selection import GridSearchCV
classifiers_grid = GridSearchCV(estimator=classifier, param_grid=parameters, scoring='balanced_accuracy',
cv=5, refit=True, n_jobs=-1)
classifiers_grid.fit(X, y)
Run Code Online (Sandbox Code Playgroud)
我收到此警告:
.../anaconda/lib/python3.7/site-packages/sklearn/model_selection/_validation.py:536:
FitFailedWarning: Estimator fit failed. The score on this train-test partition for these parameters will be set to nan. Details:
TypeError: '<' not supported between instances of 'str' and 'int'
Run Code Online (Sandbox Code Playgroud)
这是为什么?我该如何解决它?
我有类似的 FitFailedWarning 问题,但细节不同,经过多次运行后发现,参数值传递有错误,请尝试
parameters = {'n_estimators': [100,125,150,175,200,225,250],
'criterion': ['gini', 'entropy'],
'max_depth': [2,4,6,8,10],
'max_features': [0.1, 0.2, 0.3, 0.4, 0.5],
'class_weight': [0.2,0.4,0.6,0.8,1.0],
'min_samples_split': [2,3,4,5,6,7]}
Run Code Online (Sandbox Code Playgroud)
这肯定会通过,对我来说,它发生在 XGBClassifier 中,不知何故,值数据类型混合在一起
还有一个就是如果数值超出范围,比如XGBClassifier的subsample参数最大值是1.0,如果设置为1.1,就会出现FitFailedWarning
| 归档时间: |
|
| 查看次数: |
23604 次 |
| 最近记录: |