Scikit-Learn Classification and Regression with Weights

谁都会走 提交于 2019-12-07 04:20:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/17265512/scikit-learn-classification-and-regression-with-weights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!