-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.java
More file actions
237 lines (164 loc) · 4.43 KB
/
Data.java
File metadata and controls
237 lines (164 loc) · 4.43 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
public class Data {
protected List<Double> attributes = new ArrayList<>();
static HashMap<String,Double> h1=new HashMap<>();
static HashMap<Integer,Double> h2=new HashMap<>();
// static HashMap<String,Double> h3=new HashMap<>();
static List a2=new ArrayList();
public Data()
{
}
public List getAttributes() {
return attributes;
}
public void setAttributes(List attributes) {
this.attributes = attributes;
}
public static Data parseTrainData(String line)
{
Data data=new Data();
String[] fields = line.split(",");
int j=fields.length-1;
/*while(!((Integer)Integer.parseInt(fields[j]) instanceof Integer)) {
r=new Random();
j=r.nextInt(5);
}*/
for(int i=0;i<fields.length;i++) {
/* if(i==0) {
Random r=new Random();
j=r.nextInt(5);
}*/
if(i!=j) {
if(NumberUtils.isNumber(fields[i] )){
data.attributes.add(Double.parseDouble(fields[i]));
}
else {
if(h1.containsKey(fields[i])) {
data.attributes.add(h1.get(fields[i]));
}
else {
if(h2.containsKey(i)) {
Double n1=h2.get(i);
h2.put(i, n1+1.0);
h1.put(fields[i], h2.get(i));
data.attributes.add(h1.get(fields[i]));
}
else {
h2.put(i, 0.0);
h1.put(fields[i], h2.get(i));
data.attributes.add(h1.get(fields[i]));
}
}
}
}
else {
if(NumberUtils.isNumber(fields[i] )){
a2.add(Double.parseDouble(fields[i]));
}
else {
if(h2.containsKey(i)) {
Double n1=h2.get(i);
h2.put(i, n1+1.0);
h1.put(fields[i], h2.get(i));
data.attributes.add(h1.get(fields[i]));
}
else {
h2.put(i, 0.0);
h1.put(fields[i], h2.get(i));
data.attributes.add(h1.get(fields[i]));
}
/*if(h3.size()==0){
h3.put(fields[i], 0.0);
a2.add(h3.get(fields[i]));
}
else {
if(h3.containsKey(fields[i])) {
a2.add(h3.get(fields[i]));
}
else {
double n2=h3.get(key)
}
}*/
}
}
}
return data;
}
/* if(fields.length==14) {
}
if (fields.length != numberOfColumns)
throw new IllegalArgumentException("Invalid number of columns in train file: " + fields.length);
for (int i = 0; i < fields.length; i++)
{
if (i == 0)
data.m_subjectID = Integer.parseInt(fields[i]);
else
if (i >= 0 && i <= 2)
data.attributes.add(Double.parseDouble(fields[i]));
if (i >= 4 && i <= 7)
data.attributes.add(Double.parseDouble(fields[i]));
if (i >= 9 && i <= 13)
data.attributes.add(Double.parseDouble(fields[i]));
else if (i == 28)
{
int classValue = Integer.parseInt(fields[i]);
if (classValue == 1)
data.m_class = DataSet.DataClass.PARKINSON;
else if (classValue == 0)
data.m_class = DataSet.DataClass.HEALTHY;
else
throw new IllegalArgumentException("Invalid class value in train file: " + classValue);
}
}
}
*/
/* public static void main(String[] args) {
String[][] s=new String[2][5];
String []s1= {"1","2","4.5","ram","male"};
s[0][0]= "1";
s[0][1]="2";
s[0][2]="male";
s[0][3]="1.2";
s[0][4]="wer";
s[1][0]="2";
s[1][1]="4";
s[1][2]="female";
s[1][3]="2.0";
s[1][4]="qer";
Data data= parseTrainData(s1);
for(int i=0;i<data.attributes.size();i++) {
System.out.println(data.attributes.get(i));
}
}
*/
public List<Double> getTargetList(List a2)
{
List<Double> targetList = new ArrayList<>();
int min=(int) a2.get(0);
int max=(int)a2.get(0);
for(int j=1;j<a2.size();j++) {
if((int)a2.get(j) < min)
min=(int) a2.get(j);
if((int)a2.get(j) > max)
max=(int) a2.get(j);
}
int average=(max-min)/2;
for(int i=0;i<a2.size();i++) {
if((int)a2.get(i)>average)
targetList.add(1.0);
else {
if((int)a2.get(i)<average)
targetList.add(0.0);
}
}
return targetList;
}
}