Takahiro Yoshizawa
Takahiro Yoshizawa

Reputation: 111

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.

Upvotes: 4

Views: 11464

Answers (1)

σηγ
σηγ

Reputation: 1314

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.

Upvotes: 4

Related Questions