-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeature.java
More file actions
56 lines (54 loc) · 2.15 KB
/
Feature.java
File metadata and controls
56 lines (54 loc) · 2.15 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dataminingproject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.stream.IntStream;
/**
*
* @author user
*/
public class Feature {
private String name=null;
private String[][] data=null;
private HashSet<FeatureValue> featureValues=new HashSet<FeatureValue>();
private double probability;
public Feature(String[][] data, int column){
this.name=data[0][column];
this.data=data;
IntStream.range(1, data.length).forEach(row -> featureValues.add(new FeatureValue(data[row][column])));
featureValues.stream().forEach(featureValue -> {
int counter =0;
for(int row=1;row<data.length; row++)
if(featureValue.getName()==data[row][column] )featureValue.setOccurences(++counter);
});
}
public Feature calcProb(String featureValueName, HashMap<String, String> logMap){
if(getFeatureValue(featureValueName)!=null){
probability=(((double)getFeatureValue(featureValueName).getOccurences())/(data.length-1));
logMap.put(this.name, getFeatureValue(featureValueName).getOccurences()+"/"+(data.length-1));
}
else{
probability=0;
logMap.put(this.name, "0/"+(data.length-1));
}
return this;
}
public FeatureValue getFeatureValue(String featureValueName){
FeatureValue returnValue=null;
Iterator<FeatureValue> iterator=featureValues.iterator();
while(iterator.hasNext()){
FeatureValue featureValue=iterator.next();
if(featureValue.getName().equals(featureValueName)) { returnValue=featureValue; break;}
}
return returnValue;
}
public double getProbability() {return probability;}
public String getName() {return name;}
public HashSet<FeatureValue> getFeatureValues() {return featureValues;}
public String toString(){return name;}
}