fedden
fedden

Reputation: 319

class_weigths in claserization in lib scikit, python

I'm new in scikit so this is a simple question

I have tryed to pass class_weigths param with dict type to claserization like sklearn.svm.SVC

Can someone give me example of correct param dict, I tryed to use model.class_weight = dict(zero=100, one=1) but in SVM it gives :

TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'

in other methods I got no effect :(

Upvotes: 0

Views: 90

Answers (1)

cleros
cleros

Reputation: 4343

I am not entirely sure why you want to call the keys of the dictionary by strings. According to the documentation and this example, you want the keys to represent the indices of your classes. That is, you want them to be integers!

Taking from the example in the link above, they instantiate the SVM with the following weights (again, using integers to index the classes):

wclf = svm.SVC(kernel='linear', class_weight={1: 10})

which, for your example, would require you to use

model.class_weight = {0:100, 1:1}

Upvotes: 2

Related Questions