Package quickml.supervised.crossValidation.crossValLossFunctions

Source Code of quickml.supervised.crossValidation.crossValLossFunctions.NonWeightedAUCCrossValLossFunction

package quickml.supervised.crossValidation.crossValLossFunctions;
import org.apache.mahout.classifier.evaluation.Auc;
import quickml.data.PredictionMap;

import java.util.List;

/**
* Created by alexanderhawk on 5/17/14.
*/
public class NonWeightedAUCCrossValLossFunction implements CrossValLossFunction<PredictionMap> {

    @Override
    public double getLoss(List<LabelPredictionWeight<PredictionMap>> labelPredictionWeights)  {
        Auc auc = new Auc();
        for (LabelPredictionWeight<PredictionMap> labelPredictionWeight : labelPredictionWeights) {
            int trueValue = (Double) labelPredictionWeight.getLabel() == 1.0 ? 1 : 0;
            PredictionMap classifierPrediction = labelPredictionWeight.getPrediction();
            double probabilityOfCorrectInstance = classifierPrediction.get(labelPredictionWeight.getLabel());
            double score = 0;
            score = (trueValue == 1) ? probabilityOfCorrectInstance: 1 - probabilityOfCorrectInstance;
            auc.add(trueValue, score);
        }
        return 1 - auc.auc();
    }
}
TOP

Related Classes of quickml.supervised.crossValidation.crossValLossFunctions.NonWeightedAUCCrossValLossFunction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.