【发布时间】:2021-12-30 18:07:26
【问题描述】:
在我看到的所有示例中,sklearn 的make_scorer 方法似乎都很简单,但是当我尝试在我的交叉验证中使用它时,它给了我所有的 NaN。然后我意识到make_scorer 中的某些东西不起作用,但我不知道是什么。我给你看一个小例子:
a1 = np.array([0, 9, 0])
b1 = np.array([0, 8, 0])
def my_func(y_true, y_pred):
output = y_true[1]-y_pred[1]
return output
my_fake_scorer = make_scorer(my_func)
my_fake_scorer(y_pred=b1, y_true=a1)
如果我跑:
my_func(y_pred=b1, y_true=a1) --> 1 (ok!)
如果我跑:
my_fake_scorer(y_pred=b1, y_true=a1) -->
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17304/3405218040.py in <module>
10
11 my_fake_scorer = make_scorer(my_func)
---> 12 my_fake_scorer(y_pred=b1, y_true=a1)
TypeError: __call__() got an unexpected keyword argument 'y_pred'
【问题讨论】:
标签: python machine-learning scikit-learn