-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathDiscreteDataSet.java
More file actions
47 lines (41 loc) · 1.36 KB
/
DiscreteDataSet.java
File metadata and controls
47 lines (41 loc) · 1.36 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
import java.io.*;
/**
* This is a subclass of <tt>DataSet</tt> representing a dataset all
* of whose attributes are discrete. In addition to all of the fields
* and methods inherited from <tt>DataSet</tt>, the class includes a
* constructor that reads in data from data files and converts all
* numeric attributes to discrete.
**/
public class DiscreteDataSet extends DataSet {
/** This constructor reads in data from the files
* <tt>filestem.names</tt>, <tt>filestem.train</tt> and
* <tt>filestem.test</tt>, converts all attributes to discrete
* format, and sets up all of the public fields.
**/
public DiscreteDataSet(String filestem)
throws FileNotFoundException, IOException {
super(filestem);
int[][] cont_vals = getContVals();
for (int j = 0; j < numAttrs; j++) {
if (attrVals[j] != null)
continue;
attrVals[j] = new String[cont_vals[j].length];
for (int k = 0; k < cont_vals[j].length; k++) {
attrVals[j][k] = Integer.toString(cont_vals[j][k]);
}
for (int traintest = 0; traintest < 2; traintest++) {
int[][] exs = (traintest == 1 ? trainEx : testEx);
for (int i = 0; i < exs.length; i++) {
int k = 0;
while(exs[i][j] != cont_vals[j][k])
k++;
exs[i][j] = k;
}
}
}
}
/** This constructor creates an empty discrete dataset. */
public DiscreteDataSet() {
super();
}
}