- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想打印准确性,回顾网格中使用的每个参数,如何做到这一点。
我的 Gridsearch 代码
from sklearn.grid_search import GridSearchCV
rf1=RandomForestClassifier(n_jobs=-1, max_features='sqrt')
#fit_rf1=rf.fit(X_train_res,y_train_res)
# Use a grid over parameters of interest
param_grid = {
"n_estimators" : [50, 100, 150, 200],
"max_depth" : [2, 5, 10],
"min_samples_leaf" : [10,20,30]}
from sklearn.metrics import make_scorer
from sklearn.metrics import precision_score,recall_score
scoring = {'precision': make_scorer(precision_score), 'Recall': make_scorer(recall_score)}
CV_rfc = GridSearchCV(estimator=rf1, param_grid=param_grid, cv= 10,scoring=scoring)
CV_rfc.fit(X_train_res, y_train_res)
我的预期输出
{'max_depth': 10, 'min_samples_leaf': 2, 'n_estimators': 50,'accuracy':.97,'recall':.89}
{'max_depth': 5, 'min_samples_leaf':10 , 'n_estimators': 100,'accuracy':.98,'recall':.92}
最佳答案
如果您将scoring
设置为评分者列表,则可以在CV_rfc.cv_results_
中获取每个评分者的平均分数。
例如:
from sklearn.datasets import make_classification
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import RandomForestClassifier
X, y = make_classification()
base_clf = RandomForestClassifier()
param_grid = {
"n_estimators" : [50, 100, 150, 200],}
CV_rf = GridSearchCV(base_clf, param_grid, scoring=['accuracy', 'roc_auc'], refit=False)
CV_rf.fit(X, y)
print(CV_rf.cv_results_)
你会得到如下输出:
{'mean_fit_time': array([ 0.05867839, 0.10268728, 0.15536443, 0.19937317]),
'mean_score_time': array([ 0.00600123, 0.01033529, 0.0146695 , 0.02000403]),
'mean_test_accuracy': array([ 0.9 , 0.91, 0.89, 0.91]),
'mean_test_roc_auc': array([ 0.91889706, 0.94610294, 0.94253676, 0.94308824]),
'mean_train_accuracy': array([ 1., 1., 1., 1.]),
'mean_train_roc_auc': array([ 1., 1., 1., 1.]),
[...]
}
所以 mean_test_[scoring]
就是您所追求的。请注意,您可以将 cv_results_
作为 Pandas DataFrame 导入。这对可读性有很大帮助!
关于pandas - 如何打印 Sklearn 中 GridSearch 中使用的召回率和准确率以及参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47882126/
我训练了 LSTM 分类模型,但得到了奇怪的结果(0 准确率)。这是我的带有预处理步骤的数据集: import pandas as pd from sklearn.model_selection im
使用 TFlearn 构建 DNN 后,我想计算网络的准确性。 这是代码: def create_model(self): x = tf.placeholder(dtype= tf.float
Duplicate calculating Precision, Recall and F Score 我有一个带有文本描述和分类级别(即levelA和levelB)的输入文件。我想编写一个 SVM
如何计算语义分割中前 k 个准确率?在分类中,我们可以将 topk 准确率计算为: correct = output.eq(gt.view(1, -1).expand_as(output)) 最佳答案
我正在尝试解决多标签分类问题 from sklearn.preprocessing import MultiLabelBinarizer traindf = pickl
我是一名优秀的程序员,十分优秀!