<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Super—thanks for the advice,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Mike<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Pkg-ExpPsy-PyMVPA [mailto:pkg-exppsy-pymvpa-bounces+michael.browning=psych.ox.ac.uk@lists.alioth.debian.org]
<b>On Behalf Of </b>Richard Dinga<br>
<b>Sent:</b> 13 August 2015 15:31<br>
<b>To:</b> pkg-exppsy-pymvpa@lists.alioth.debian.org<br>
<b>Subject:</b> Re: [pymvpa] Altering the weights of classes in binary SVM classifier<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">> My sample is not balanced (there happens to have been 22 responders<br>
> and 13 non-responders) and is not particularly large. I would like,<br>
> if possible, to use all the data and adjust the classifier to the<br>
> unbalanced set rather than selecting a subset of the responders.<br>
<br>
You don't have to downsample, you can upsample by repeating balanced sampling n times, therefore all your data would be used. There is a balancer feature for it in pymvpa.<br>
<br>
> I've seen recommendations for SVMs in unbalanced data suggesting that <br>
> the weights of the outcome can be adjusted to reflect the sample size<br>
> (essentially the weights of each class can be set as 1/(total number > in class)).<br>
<br>
Yes, you can also move a decision threshold for some classifiers that outputs probability, so you will not predict class A if the prob of A is > 0.5 but if the prob of A > is number of A / number of total. I know you can do this with gaussian process clf, but
i don't know about others<br>
<br>
> I've tried to do this in pyMVPA using the following code:<br>
> wts=[ 1/numnonresp, 1/numresp]<br>
> wts_labels=[0,1]<br>
> clf = LinearCSVMC(weight=wts, weight_label=wts_labels)<br>
<br>
> I then embed the classifier in a crossvalidation call which includes > a feature selector.<br>
<br>
> The code runs without error but the performance of the classifier<br>
> does not alter (at all) regardless of the weights I use (e.g. using<br>
> weights of [0 100000000000] or whatever. I'm concerned that I have<br>
> not set this up correctly, and that the weights are not being<br>
> incorporated into the SVM.<br>
<br>
It didn't work for me either. You can try implementation from scikit-learn with pymvpa sklearn adaptor. There you can just put class_weight to auto and it should adjust them proportionally to class frequencies automatically<br>
<br>
Best wishes,<br>
Richard<o:p></o:p></p>
</div>
</div>
</body>
</html>