Scikit-学习带权重的分类和回归 [英] Scikit-Learn Classification and Regression with Weights
本文介绍了Scikit-学习带权重的分类和回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想对每个样本进行不同的加权,如何在sklearn中进行分类或回归?有没有一种使用自定义损失函数的方法?如果是这样,那么该损失函数通常是什么样的?有更简单的方法吗?
How can I do classification or regression in sklearn if I want to weight each sample differently? Is there a way to do it with a custom loss function? If so, what does that loss function look like in general? Is there an easier way?
推荐答案
要称量单个样品,请喂 sample_weight
数组到估算器的 fit
方法。这应该是长度为 n_samples
的一维数组(即在大多数任务中与 y
相同的维度):
To weigh individual samples, feed a sample_weight
array to the estimator's fit
method. This should be a 1-d array of length n_samples
(i.e. the same dimension as y
in most tasks):
estimator.fit(X, y, sample_weight=some_array)
并非所有型号都支持此功能,请查看文档。
Not all models support this, check the documentation.
这篇关于Scikit-学习带权重的分类和回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文