Search code examples
c#logistic-regressionaccord.netliblinear

Using Accord.Net and Liblinear change class weights


How do I specify class weights for Accord.Net for classification (any model) using Liblinear implementation. Further is there automatic balancing that I can use for unbalanced data similar to sciKit.Learn's implementation.

Thanks in advance


Solution

  • Almost all SVM learning algorithms in Accord.NET provide NegativeWeight and PositiveWeight properties that you can set to the ratio of negatives and positives in your data. For example if you have 2 negative examples for each positive example, you can set NegativeWeight to 2 and PositiveWeight to 1.

    Furthermore, you can also set the UseClassProportions property to true, achieving a behavior similar to Scikit-learn's implementation.