Compute and plot Receiver Operating Characteristic (ROC) and Precision-Recall (PR) curve

From Jstacs
Jump to navigationJump to search
Sample[] test;
AbstractScoreBasedClassifier trainedClassifier;

// TODO load data and create trained classifier

Measure[] m = { Measure.ReceiverOperatingCharacteristicCurve, Measure.PrecisionRecallCurve };
MeasureParameters mp = new MeasureParameters( true );
for( Measure s : m ) {
	mp.setSelected( s, true );
}
ResultSet rs = trainedClassifier.evaluateAll( mp, true, test );

REnvironment r = null;
try {
	r = new REnvironment( host, login, password );
	for( Measure s : m )  {
		DoubleTableResult dtr = (DoubleTableResult) rs.getResultAt( rs.findColumn( s.getNameString() ) );
		ImageResult ir = DoubleTableResult.plot( r, dtr );
		REnvironment.showImage( s.getNameString(), ir.getResult() );
	}
} catch( Exception e ) {
	e.printStackTrace();
} finally {
	if( r != null ) {
		r.close();
	}
}