9

For example, when I have a problem that false negative should be penalised more, how can I incorporate that requirement in the algorithm such as SVM?

Ghostintheshell
  • 431
  • 1
  • 4
  • 7
  • http://scikit-learn.org/stable/auto_examples/svm/plot_weighted_samples.html – Emre Dec 19 '15 at 16:53
  • Please kindly refer to the answer of the link below. https://stackoverflow.com/a/67897092/7701181 – yangyangliu Jun 09 '21 at 03:27
  • This is possible in scikit-learn only if you use GridSearchCV and cross_val_score, not for a single model trained with the .fit method – Ric S Dec 03 '21 at 11:42

1 Answers1

3

There are several ways in which you can achieve your desired result:

  • Implement the make_scorer function from Scikit learn
  • Make modification to the class_weight argument

In regards to your SVM question take a look at the below code:

 class sklearn.svm.SVC(C=1.0, kernel='rbf', degree=4, gamma=0.0,
 coef0=0.0, shrinking=True, probability=False, tol=0.003,
 cache_size=300, class_weight=None, verbose=False, max_iter=-1,
 random_state=None)

In the above example, the class_weight function can be changed to 'auto' or you can pass dictionary values which have the user-defined class weights.