-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogisticRegressionEvaluator.java
More file actions
39 lines (35 loc) · 1.17 KB
/
LogisticRegressionEvaluator.java
File metadata and controls
39 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cs475;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Scanner;
import java.util.Iterator;
import java.math.*;
//import java.lang.Math;
import java.util.Collections;
public class LogisticRegressionEvaluator extends Evaluator {
private double evaluatorValue = 0.0;
public double evaluate(List<Instance> instances, Predictor predictor){
int correct = 0;
int total = instances.size();
LogisticRegression lr = (LogisticRegression)predictor;
for(int i = 0; i< instances.size();i++){
ClassificationLabel preLabel = lr.predict(instances.get(i));
ClassificationLabel realLabel = (ClassificationLabel)instances.get(i).getLabel();
if(realLabel == null){
break;
}
if(preLabel.getLabelValue() == realLabel.getLabelValue()){
correct +=1;
}
}
System.out.println("correct: " + correct);
System.out.println("total: " + instances.size());
evaluatorValue = ((double)correct / total);
System.out.println("correct/total: " + evaluatorValue);
return evaluatorValue;
}
}