- Python Machine Learning Cookbook(Second Edition)
- Giuseppe Ciaburro Prateek Joshi
- 119字
- 2021-06-24 15:40:59
There's more…
C is a hyperparameter that determines the penalty for the incorrect classification of an observation. So, we used a weight for the classes to manage unbalanced classes. In this way, we will assign a new value of C to the classes, defined as follows:
Where C is the penalty, wi is a weight inversely proportional to class i's frequency, and Ci is the C value for class i. This method suggests increasing the penalty to classify the less represented classes so as to prevent them from being outclassed by the most represented class.
In the scikit-learn library, when using SVC, we can set the values for Ci automatically by setting class_weight='balanced'.