Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set sample weight in sklearn logistic regression?

I have a problem when I do the logistic regression in scikit learn python package.

When the data it has a different number of samples for 1 or 0, I want to do logistic regression with concerning sample weight. But, I have a few data, so I can't get the same number of samples for each.

like image 920
Takahiro Yoshizawa Avatar asked Oct 16 '25 09:10

Takahiro Yoshizawa


1 Answers

As the documentation of sklearn's LogisticRegression says, there are two options to assign weights to samples.

The classifier accepts a class_weight parameter which can be used to set the weight of all samples belonging to a certain class. One can also apply class_weight='balanced' to automatically adjust the class weights based on the number of samples in each class.

The fit method of the classifier also accepts a sample_weight array which assigns weights to individual samples.

like image 111
σηγ Avatar answered Oct 19 '25 01:10

σηγ