質問編集履歴

1

記述するべきプログラムを記述し忘れていた

2022/01/29 03:55

投稿

soft_cream
soft_cream

スコア11

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,8 @@
5
5
  プログラムのどこかに無限ループとなっている箇所などがあるのでしょうか。
6
6
  csvファイルは、1列目にラベルがあり、それ以降の列にデータが入っているとします。
7
7
  環境はWindowsのコマンドプロンプトです
8
+ (追記)
9
+ クラスを一つ記述し忘れていました。下に追加しました。
8
10
  ```java
9
11
  import java.nio.file.Files;
10
12
  import java.nio.file.Paths;
@@ -51,3 +53,65 @@
51
53
  }
52
54
  }
53
55
  ```
56
+ ```java
57
+ public class Dataset {
58
+ private double[][] features;
59
+ private String[] labels;
60
+ private int numSamples;
61
+ private int numDimensions;
62
+
63
+ Dataset() {
64
+ this.numSamples = -1;
65
+ this.numDimensions = -1;
66
+ }
67
+
68
+ Dataset(String[] labels, double[][] features) {
69
+ this.labels = labels;
70
+ this.features = features;
71
+ this.numSamples = features.length;
72
+ this.numDimensions = features[0].length;
73
+ }
74
+
75
+ public void updateFeature(int sid, int did, double value) {
76
+ if (sid >= 0 && sid < numSamples && did >= 0 && did < numDimensions) {
77
+ this.features[sid][did] = value;
78
+ }
79
+ }
80
+
81
+ public void updateLabel(int sid, String label) {
82
+ if (sid >= 0 && sid < numSamples) {
83
+ this.labels[sid] = label;
84
+ }
85
+ }
86
+
87
+ public double getFeature(int sid, int did) {
88
+ if (sid >= 0 && sid < numSamples && did >= 0 && did < numDimensions) {
89
+ return this.features[sid][did];
90
+ }
91
+ return 0;
92
+ }
93
+
94
+ public String getLabel(int sid) {
95
+ if (sid >= 0 && sid < numSamples) {
96
+ return this.labels[sid];
97
+ }
98
+ return "";
99
+ }
100
+
101
+ public int getNumSamples() {
102
+ return this.numSamples;
103
+ }
104
+
105
+ public int getNumDimensions() {
106
+ return this.numDimensions;
107
+ }
108
+
109
+ public boolean isEmpty() {
110
+ if (this.numSamples <=0 || this.numDimensions <= 0) {
111
+ return true;
112
+ }
113
+ return false;
114
+ }
115
+ }
116
+
117
+ ```