2012/9/12 Christian Jauvin <[email protected]>:
> Hi,
>
> As I only have an intuitive notion of how "sample_weight" (i.e. to be
> fed to certain types of classifier) should work, I'd like to know if
> this is a sound way of computing them:
>
> def get_sample_weight(y):
>     p = 1. / len(np.unique(y))
>     bc = np.bincount(y)
>     w = np.repeat(p, len(y))
>     for i, v in enumerate(y):
>         w[i] /= bc[v]
>     assert np.sum(w) == 1
>     return w

Sample weight are to be used when you have application-specific,
per-sample cost to take into account (e.g. the money you would loose
by misclassifying a specific sample).

If you just want to give a cost to account for class-imbalance, you
should use class_weight='auto' (or a class_weight on your own with
your own specific cost renormalization on a per-class basis).

-- 
Olivier
http://twitter.com/ogrisel - http://github.com/ogrisel

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to