【问题标题】:User criterion and of "make_scorer"用户标准和“make_scorer”
【发布时间】:2018-10-30 22:48:01
【问题描述】:
  1. 我是否需要将参数(y_true, y_pred)传递给函数«make_scorer»? 如果是这样,它们是如何传播的..?如果可以举个例子。
  2. 如何在“评分”中设置自定义标准?
  3. 每次迭代的结果是训练还是测试的结果?

_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 

【问题讨论】:

  • 第 1 点见此问题:- stackoverflow.com/q/43523210/3374996
  • 对于第 2 点:您在谈论哪个自定义标准?你有自己的得分/损失函数吗?在此处发布。
  • 第 3 点:哪个迭代?折叠迭代?分数将在测试集上计算。
  • 请详细解释(可能有例子)。什么是“z”?
  • 以上更正了第一条消息。

标签: python scikit-learn


【解决方案1】:

试试这个:

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)

【讨论】:

  • 值不匹配。不清楚变量来自哪里(y_true,y_pred)? **kwargs(非活动,灰色。)
  • @user287629,请在您的问题中提供一个小的可重复样本数据集和您想要的数据集(分数)
  • 谢谢!一般理解)
猜你喜欢
  • 2017-03-26
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
  • 1970-01-01
  • 2018-04-23
  • 2015-10-09
  • 1970-01-01
  • 2013-01-13
相关资源
最近更新 更多