-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetflix1.java
More file actions
36 lines (35 loc) · 1.13 KB
/
Netflix1.java
File metadata and controls
36 lines (35 loc) · 1.13 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
import java.util.*;
import java.io.*;
public class Netflix1
{
public static void main(String[] args) {
try {
AllMean predict = new AllMean("training_set");
Double mean = predict.getMean();
FileInputStream fin = new FileInputStream(args[1]);
BufferedReader inFile = new BufferedReader(new InputStreamReader(fin));
ArrayList<Double> predictedRatings = new ArrayList<Double>();
ArrayList<Double> actualRatings = new ArrayList<Double>();
String nLine = inFile.readLine();
int numValues = 0;
while (nLine != null) {
if (nLine.indexOf(":") < 0) {
predictedRatings.add(mean);
actualRatings.add(Double.parseDouble(nLine));
numValues++;
}
nLine = inFile.readLine();
}
fin.close();
double eTotal = 0;
for (int i = 0; i < predictedRatings.size(); i++) {
double error = predictedRatings.get(i) - actualRatings.get(i);
eTotal += (error * error);
}
double rmse = Math.sqrt(eTotal/numValues);
System.out.println("RMSE=" + rmse);
} catch (IOException e) {
e.printStackTrace();
}
}
}