-
Notifications
You must be signed in to change notification settings - Fork 0
/
CategoricalFeature.java
36 lines (30 loc) · 1.22 KB
/
CategoricalFeature.java
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.ArrayList;
import java.util.Arrays;
class CategoricalFeature extends Feature {
protected ArrayList<String> categoricalOptions;
/* Creates a CategoricalFeature, parsing out the categorical feature's options and storing them
* in an arraylist to be "mapped" to int values for easier use.
*
* @param featureName string containing the name of the feature
* @param a string containing the categorical options for the feature
*/
public CategoricalFeature(String featureName, String categoricalOptionsString) {
super(featureName);
categoricalOptionsString = categoricalOptionsString.substring(1, categoricalOptionsString.length()-1);
this.categoricalOptions = new ArrayList(Arrays.asList(categoricalOptionsString.split(",")));
}
public String getNameOfCategoricalFeatureValue(int index) {
return this.categoricalOptions.get(index);
}
public int getIndexOfCategoricalFeatureValue(String categoricalValue) {
return this.categoricalOptions.indexOf(categoricalValue);
}
public int getNumberOfOptions() {
return categoricalOptions.size();
}
@Override
public String toString() {
return ("FeatureName: " + this.name +
" options: " + this.categoricalOptions);
}
}