10
10
void DataSet::ReadCSVFile (std::string file_name) {
11
11
12
12
std::ifstream file (file_name.c_str ());
13
- if (!file) {
13
+
14
+ if (!file)
15
+ {
14
16
file.open (file_name.c_str ());
15
17
}
16
18
if (!file) {
17
- std::cerr << " Error No" << file_name << " found. " << std::endl;
19
+ std::cerr << " Error: No " << file_name << " found . " << std::endl;
18
20
19
21
}
20
22
21
23
std::stringstream buffer;
22
24
buffer << file.rdbuf ();
23
25
std::string line;
26
+
24
27
std::vector<std::string>lines;
25
- while (getline (buffer, line, ' \n ' )) {
26
- lines.push_back (line);
28
+ while (getline (buffer, line,' \n ' )) {
29
+ // std::cout << line << std::endl;
30
+ // std::cout << "ses" << std::endl;
31
+ lines.push_back (line);
27
32
}
28
33
29
- // the other lines contain the features for each floaer
30
34
31
- for (int i = 1 ; i < lines.size (); ++i) {
32
- std::vector<float >features =ReadCSVLine (lines[i]);
33
- x1_.push_back (features[0 ]);
34
- x2_.push_back (features[1 ]);
35
- x3_.push_back (features[2 ]);
36
- x4_.push_back (features[3 ]);
37
- y_.push_back (features[4 ]);
35
+ // std::cout<<"lines-size "<< lines.size() << std::endl;
36
+ // /the other lines contain the features for each flower
37
+
38
+ for (int i = 1 ; i < lines.size (); ++i) {
39
+
40
+ // std::cout << lines[i] << std::endl;
41
+ std::vector<float >features = ReadCSVLine (lines[i]);
42
+
43
+
44
+
45
+ mean_.push_back (features[0 ]);
46
+ stdev_.push_back (features[1 ]);
47
+ kurtosis_.push_back (features[2 ]);
48
+ skewness_.push_back (features[3 ]);
49
+ snr_.push_back (features[4 ]);
50
+ dmsnr_.push_back (features[5 ]);
51
+ kurtosissnr_.push_back (features[6 ]);
52
+ skewsnr_.push_back (features[7 ]);
53
+ class_.push_back (features[8 ]);
38
54
39
55
}
56
+
40
57
}
41
58
42
- std::vector<float >DataSet::ReadCSVLine (std::string line) {
59
+
60
+ std::vector<float > DataSet::ReadCSVLine (std::string line) {
43
61
std::vector<float > line_data;
44
62
std::stringstream lineStream (line);
45
63
std::string cell;
@@ -48,36 +66,9 @@ std::vector<float>DataSet::ReadCSVLine(std::string line) {
48
66
if (cell != " setosa" && cell != " versicolor" && cell != " virginica" ) {
49
67
line_data.push_back (std::stod (cell.c_str ()));
50
68
}
51
- else {
52
- if (cell == " setosa" ) {
53
- line_data.push_back (0 .0f );
54
- }
55
- else if (cell == " versicolor" ) {
56
- line_data.push_back (1 .0f );
57
- }
58
- else {
59
- line_data.push_back (2 .0f );
60
- }
61
- }
69
+
62
70
}
63
- return line_data;
64
71
72
+ // std::cout << "Line data size: " << line_data.size() << std::endl;
73
+ return line_data;
65
74
}
66
-
67
-
68
- std::initializer_list<float > DataSet::input (float petal_length, float petal_width, float sepal_length, float sepal_width) {
69
- return { petal_length,petal_width,sepal_length,sepal_width };
70
- }
71
-
72
- std::string DataSet::output (std::vector<float > one_hot_encoding_species) {
73
- if (one_hot_encoding_species[0 ] == 1 ) {
74
- return " setosa" ;
75
- }
76
- else if (one_hot_encoding_species[1 ] == 1 ) {
77
- return " versicolor" ;
78
- }
79
- else {
80
- return " virginica" ;
81
- }
82
- }
83
-
0 commit comments