-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategory.java
More file actions
97 lines (85 loc) · 2.85 KB
/
Copy pathCategory.java
File metadata and controls
97 lines (85 loc) · 2.85 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Write a description of class Category here.
*
* @author Tracy Oguni
* @version 2
*/
import java.util.ArrayList;
import java.util.HashMap;
class Category{
public String name;
public int[] stars = new int[6];
public ArrayList<String> businesses = new ArrayList<String>();
public int count =0;
public int getTotalRating(){
return stars[1] + (stars[2] *2) + (stars[3]*3) + (stars[4]*4) + (stars[5]*5);
}
public double getAverageRating(){
return getTotalRating()/count;
}
public double getAverage(){
int total = stars[0] + stars[1] + stars[2] + stars[3] + stars[4] + stars[5];
return (double)total/(double)count;
}
public double getPriorProb(int totalBusinesses){
return (double)count/(double)totalBusinesses;
}
public double getAveRatingCondProb(double value, HashMap<String, Business> businessMap, HashMap<String, Category> categoryMap){
int valueCount =0;
int totalCount =0;
for (String bus: businesses){
Business business = businessMap.get(bus);
if (business == null){
continue;
}
totalCount++;
double businessAve = business.getAverageRating();
int ave = NaiveBayes.smoothRating(businessAve, (new Double(businessAve)).intValue());
if (ave == value){
valueCount++;
}
}
if (totalCount ==0){
return 0;
}
return (double)(valueCount+1)/(double)(totalCount+categoryMap.size());
}
public double getModeRatingCondProb(int value, HashMap<String, Business> businessMap, HashMap<String, Category> categoryMap){
int valueCount =0;
int totalCount =0;
for (String bus: businesses){
Business business = businessMap.get(bus);
if (business == null){
continue;
}
totalCount++;
int mode = business.getModeRating();
if (mode == value){
valueCount++;
}
}
if (totalCount ==0){
return 0;
}
return (double)(valueCount+1)/(double)(totalCount+categoryMap.size());
}
public double getMedianRatingCondProb(int value, HashMap<String, Business> businessMap, HashMap<String, Category> categoryMap){
int valueCount =0;
int totalCount =0;
for (String bus: businesses){
Business business = businessMap.get(bus);
if (business == null){
continue;
}
totalCount++;
int median = business.getMedianRating();
if (median == value){
valueCount++;
}
}
if (totalCount ==0){
return 0;
}
return (double)(valueCount+1)/(double)(totalCount+categoryMap.size());
}
}