简体   繁体   中英

Scikit-Learn Classification and Regression with Weights

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?

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 (ie the same dimension as y in most tasks):

estimator.fit(X, y, sample_weight=some_array)

Not all models support this, check the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM