Exemplo n.º 1
0
func AlgorithmRunOnDataSet(classifier algo.Classifier, train_dataset, test_dataset *core.DataSet, pred_path string, params map[string]string) (float64, []*eval.LabelPrediction) {

	if train_dataset != nil {
		classifier.Train(train_dataset)
	}

	predictions := []*eval.LabelPrediction{}
	var pred_file *os.File
	if pred_path != "" {
		pred_file, _ = os.Create(pred_path)
	}
	for _, sample := range test_dataset.Samples {
		prediction := classifier.Predict(sample)
		if pred_file != nil {
			pred_file.WriteString(strconv.FormatFloat(prediction, 'g', 5, 64) + "\n")
		}
		predictions = append(predictions, &(eval.LabelPrediction{Label: sample.Label, Prediction: prediction}))
	}
	if pred_path != "" {
		defer pred_file.Close()
	}

	auc := eval.AUC(predictions)
	return auc, predictions
}
Exemplo n.º 2
0
func (algo *SAOptAUC) TrainAUC(samples []*core.Sample) float64 {
	predictions := []*eval.LabelPrediction{}
	for _, sample := range samples {
		pred := algo.Predict(sample)
		predictions = append(predictions, &(eval.LabelPrediction{Label: sample.Label, Prediction: pred}))
	}
	return eval.AUC(predictions)
}
Exemplo n.º 3
0
func (c *CategoryFeatureCombination) OneCVAUC(dataset0 *core.RawDataSet, combines []core.CombinedFeature, total_cv, cv int) float64 {
	dataset := dataset0.ToDataSet(nil, combines)

	train := dataset.Split(func(i int) bool { return i%total_cv != cv })

	c.algo.Train(train)

	test := dataset.Split(func(i int) bool { return i%total_cv == cv })

	predictions := []*eval.LabelPrediction{}
	for _, sample := range test.Samples {
		pred := c.algo.Predict(sample)
		lp := eval.LabelPrediction{Label: sample.Label, Prediction: pred}
		predictions = append(predictions, &lp)
	}
	auc := eval.AUC(predictions)
	c.algo.Clear()
	return auc
}