<div dir="ltr"><span style="font-size:12.8px">Hi pyMVPAers,</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">I can't seem to figure out what is probably a very simple question: is there a way to get the individual confusion matrices for each classification (each run) that results from using the halfpartitioner generator? I'm guessing it has something to do with the attributes/parameters of the generator?  I'm trying to do this both for a whole brain classification and for a searchlight. I have 2 runs/chunks (each run has 72 trials and each trial is associated with an Ingroup/Outgroup target). But I only want it to train on run 1 and test on run 2 (I'm not theoretically interested in the results from train run 2 and test run 1 and thus would just want to look at the confusion matrix for train run1, test run2 - ie an Ingroup/Outgroup classification with 72 trials rather than 144 classifications).</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">I've tried it 3 different ways and I'm getting different results for each way so just wanted to know if any of these ways is valid:</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">1) Using the manual split example from the tutorial and calling the "training_stats" conditional attribute in the classifier</span><br style="font-size:12.8px"><span style="font-size:12.8px">In the tutorial we can get the individual accuracies for each run through cv_results.samples but I'm interested in the TPR (True Positive Rate) for Ingroup and Outgroup separately so I'm looking to print the confusion matrix to calculate these numbers</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">ds_split1 = ds[ds.sa.chunks == 1.]</span><br style="font-size:12.8px"><span style="font-size:12.8px">ds_split2 = ds[ds.sa.chunks == 2.]</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf = LinearCSVMC(enable_ca=</span><b style="font-size:12.8px">['<wbr>training_stats']</b><span style="font-size:12.8px">)</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf.set_postproc(BinaryFxNode(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">mean_mismatch_error,'targets')</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">)</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf.train(ds_split1)</span><br style="font-size:12.8px"><span style="font-size:12.8px">err = clf(ds_split2)</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf.ca.training_stats.as_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">string(description=True)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">2) Using the HalfPartitioner function's "count" argument</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px"> clf = LinearCSVMC(enable_ca=['</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">training_stats']) #The training_stats confusion matrix from this method doesn't match the one above</span><br style="font-size:12.8px"><span style="font-size:12.8px"> hpart = HalfPartitioner(</span><b style="font-size:12.8px">count=1</b><span style="font-size:12.8px">, attr='chunks')</span><br style="font-size:12.8px"><span style="font-size:12.8px"> cvte = CrossValidation(clf,hpart,</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">errorfx=lambda p,t: np.mean(p==t),enable_ca=['</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">stats'])</span><br style="font-size:12.8px"><span style="font-size:12.8px"> cv_results = cvte(ds)</span><br style="font-size:12.8px"><span style="font-size:12.8px"> cvte.ca.stats.as_string(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">description=True)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">3) Doing manual counters of the predicted vs actual targets</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">ds_split1 = ds[ds.sa.chunks == 1.]</span><br style="font-size:12.8px"><span style="font-size:12.8px">ds_split2 = ds[ds.sa.chunks == 2.]</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf = LinearCSVMC()</span><br style="font-size:12.8px"><span style="font-size:12.8px">clf.train(ds_split1)</span><br style="font-size:12.8px"><span style="font-size:12.8px">predictions=clf.predict(ds_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">split2.samples)</span><br style="font-size:12.8px"><span style="font-size:12.8px">prediction_values=predictions=</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">=ds_split2.sa.targets</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">counter=0</span><br style="font-size:12.8px"><span style="font-size:12.8px">        for stimulus in ds_split2.sa.targets:</span><br style="font-size:12.8px"><span style="font-size:12.8px">            current_prediction_value=</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">prediction_values[counter]</span><br style="font-size:12.8px"><span style="font-size:12.8px">            print current_prediction_value</span><br style="font-size:12.8px"><span style="font-size:12.8px">            if stimulus=='I': #Ingroup</span><br style="font-size:12.8px"><span style="font-size:12.8px">                if current_prediction_value==</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">True:</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    num_correct_ingroup+=1.0</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    counter+=1</span><br style="font-size:12.8px"><span style="font-size:12.8px">                else:</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    counter+=1</span><br style="font-size:12.8px"><span style="font-size:12.8px">            elif stimulus=='O': #Outgroup</span><br style="font-size:12.8px"><span style="font-size:12.8px">                if current_prediction_value==</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">True:</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    num_correct_outgroup+=1.0</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    counter+=1</span><br style="font-size:12.8px"><span style="font-size:12.8px">                else:</span><br style="font-size:12.8px"><span style="font-size:12.8px">                    counter+=1</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">        sensitivity_ingroup=float(num_</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">correct_ingroup/36.0)</span><br style="font-size:12.8px"><span style="font-size:12.8px">        sensitivity_outgroup=float(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">num_correct_outgroup/36.0)</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">I'm getting different results (Ingroup/Outgroup TPRs) for each of these methods so just wondering which, if any, of the above mentioned methods would be the correct method for getting the confusion matrices or TPRs for Ingroup/Outgroup only training on run 1 and testing on run 2? The last method I wouldn't be able to use for a searchlight but might be valid for a wholebrain?</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">The confusion matrix that I get from method 1 has highly accurate predictions, which makes me doubt that's the confusion matrix I'm looking for.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">Thank you for your help!</span><div style="font-size:12.8px">Lynda</div></div>