python - 用户标准和“make_scorer”
问题描述
- 我需要将参数(y_true,y_pred)传递给函数«make_scorer»吗?如果是这样,它们是如何传播的..?如果可以举个例子。
- 如何在“评分”中设置自定义标准?
- 每次迭代的结果是训练还是测试的结果?
_scorer = make_scorer(f1_score,pos_label=0)
grid_searcher = GridSearchCV(clf, parameter_grid, verbose=200, scoring=_scorer)
grid_searcher.fit(X_train, y_train)
clf_best = grid_searcher.best_estimator_
- 在流程中产生的每次迭代:
[CV] class_weight=balanced, max_depth=10, n_estimators=100 ...........
[CV] class_weight=balanced, max_depth=10, n_estimators=100, score=0.4419706300331596, total= 16.4s
[Parallel(n_jobs=1)]: Done 12 out of 12 | elapsed: 1.7min remaining: 0.0s
[CV] class_weight=balanced, max_depth=10, n_estimators=150 > – user287629 47 mins ago
y_pred = clf.predict (X_test)
r = np.sum (y_pred == 0) & (y_pred == y_test)
s = np.sum (y_pred == 1) & (y_pred! = y_test)
z = r / s #I need to get a z
解决方案
试试这个:
def T_scorer(y_true, y_pred, **kwargs):
epsilon = 1e-8 # think of the "computational stability" ("ZeroDivisionError")
r = np.sum((y_pred == 0) & (y_pred == y_true))
s = np.sum((y_pred == 1) & (y_pred != y_true))
z = r / (s + epsilon) # I need to get a z
return z
_scorer = make_scorer(T_scorer)
grid_searcher = GridSearchCV(clf, parameter_grid, verbose=2, scoring=_scorer)
推荐阅读
- javascript - 如何在 VS Code IDE 中查看文件的历史记录?
- excel - 在 2 个子程序之间传递值时出错
- node.js - 文件路径不同
- python - 在 Python 程序中显示 PyQt 窗口内容的轻微延迟
- ssl - tls:服务器选择不支持的协议版本 301
- java - assertEquals 与 assertTrue 的布尔值
- java - 无法将大于 2000 字节的 LOB 作为缓冲消息排队到 Oracle AQ
- php - 已安装 intl 扩展,但在 phpinfo() 中看不到
- css - 多行块的百分比填充
- javascript - Bootbox - 如何动态添加按钮?