# How to customise cost function in Scikit learn's model？

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?

• scikit-learn.org/stable/auto_examples/svm/…
– Emre
Dec 19, 2015 at 16:53
• Please kindly refer to the answer of the link below. stackoverflow.com/a/67897092/7701181 Jun 9, 2021 at 3: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 Dec 3, 2021 at 11:42

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.