我正在使用以下代码通过
现在,我想将调整的参数应用于
gridsearchcv
获取randomforest
的优化参数。x_train, x_test, y_train, y_test = train_test_split(X, y, random_state=0)
rfc = RandomForestClassifier(random_state=42, class_weight = 'balanced')
param_grid = {
'n_estimators': [200, 500],
'max_features': ['auto', 'sqrt', 'log2'],
'max_depth' : [4,5,6,7,8],
'criterion' :['gini', 'entropy']
}
k_fold = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
CV_rfc = GridSearchCV(estimator=rfc, param_grid=param_grid, cv= 10, scoring = 'roc_auc')
CV_rfc.fit(x_train, y_train)
print(CV_rfc.best_params_)
print(CV_rfc.best_score_)
现在,我想将调整的参数应用于
X_test
。为此,我执行了以下操作:pred = CV_rfc.decision_function(x_test)
print(roc_auc_score(y_test, pred))
然而,decision_function
不支持randomforest
,我得到了以下错误:
属性错误:'RandomForestClassifier'对象没有属性 'decision_function'。
还有其他的方法吗?
需要更多细节,请告诉我。
CV_rfc.predict(x_test)
吗? - gmds