gpt4 book ai didi

python - GridSearchCV - FitFailedWarning : Estimator fit failed

转载 作者:行者123 更新时间:2023-12-03 19:15:53 32 4
gpt4 key购买 nike

我正在运行这个:

# 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)

我收到此警告:
.../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'

为什么会这样,我该如何解决?

最佳答案

我有类似的 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]}
这肯定会通过,对我来说它发生在 XGBClassifier 中,不知何故值数据类型混淆了
还有一种是如果值超出范围,比如XGBClassifier中的'subsample'参数最大值是1.0,如果设置为1.1,就会出现FitFailedWarning

关于python - GridSearchCV - FitFailedWarning : Estimator fit failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60671083/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com