質問編集履歴
2
要請に基づいて修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,8 +6,6 @@
|
|
6
6
|
どうすればいいか皆目見当がつきません。
|
7
7
|
どうかご助力お願いします。
|
8
8
|
|
9
|
-
コード
|
10
|
-
#########################
|
11
9
|
```python
|
12
10
|
import numpy as np
|
13
11
|
import random #擬似乱数を生成するライブラリー
|
@@ -26,14 +24,10 @@
|
|
26
24
|
|
27
25
|
np.random.seed(0) #乱数のシードの設定
|
28
26
|
|
29
|
-
|
30
27
|
def main():
|
31
28
|
path_train = glob.glob("*****/*.jpg")
|
32
|
-
|
33
29
|
df_val = pd.read_csv("******/train.csv", index_col=0)
|
34
30
|
print(df_val)
|
35
|
-
|
36
|
-
|
37
31
|
df = pd.DataFrame({})
|
38
32
|
|
39
33
|
for item in path_train:
|
@@ -49,15 +43,11 @@
|
|
49
43
|
peace = pd.DataFrame(list_value, columns=["image", "data"])
|
50
44
|
peace = peace.set_index("image")
|
51
45
|
df = pd.concat([df, peace], axis=0)
|
52
|
-
|
53
|
-
|
54
|
-
print(df)
|
46
|
+
print(df)
|
55
47
|
|
56
48
|
X_train, X_test, y_train, y_test = train_test_split(df, df_val, test_size=0.2, random_state=0)
|
57
49
|
|
58
|
-
|
59
50
|
N_dim = 100 # 100列に落とし込む
|
60
|
-
|
61
51
|
pca = PCA(n_components=N_dim, random_state=0)
|
62
52
|
pca.fit(X_train)
|
63
53
|
|
@@ -73,20 +63,54 @@
|
|
73
63
|
|
74
64
|
エラーメッセージ
|
75
65
|
###############################
|
76
|
-
--------------------------------------------------------------------------
|
66
|
+
---------------------------------------------------------------------------
|
77
67
|
TypeError Traceback (most recent call last)
|
78
68
|
TypeError: only size-1 arrays can be converted to Python scalars
|
79
69
|
|
80
70
|
The above exception was the direct cause of the following exception:
|
81
71
|
|
82
72
|
ValueError Traceback (most recent call last)
|
83
|
-
<ipython-input-
|
73
|
+
<ipython-input-17-8d81aa9fba70> in <module>
|
84
|
-
|
74
|
+
57
|
85
|
-
|
75
|
+
58 if __name__ == "__main__":
|
86
|
-
---> 9
|
76
|
+
---> 59 main()
|
87
|
-
97
|
88
77
|
|
89
78
|
5 frames
|
79
|
+
<ipython-input-17-8d81aa9fba70> in main()
|
80
|
+
49
|
81
|
+
50 pca = PCA(n_components=N_dim, random_state=0)
|
82
|
+
---> 51 pca.fit(X_train)
|
83
|
+
52
|
84
|
+
53 X_train_pca = pca.transform(X_train)
|
85
|
+
|
86
|
+
/usr/local/lib/python3.7/dist-packages/sklearn/decomposition/_pca.py in fit(self, X, y)
|
87
|
+
380 Returns the instance itself.
|
88
|
+
381 """
|
89
|
+
--> 382 self._fit(X)
|
90
|
+
383 return self
|
91
|
+
384
|
92
|
+
|
93
|
+
/usr/local/lib/python3.7/dist-packages/sklearn/decomposition/_pca.py in _fit(self, X)
|
94
|
+
429
|
95
|
+
430 X = self._validate_data(
|
96
|
+
--> 431 X, dtype=[np.float64, np.float32], ensure_2d=True, copy=self.copy
|
97
|
+
432 )
|
98
|
+
433
|
99
|
+
|
100
|
+
/usr/local/lib/python3.7/dist-packages/sklearn/base.py in _validate_data(self, X, y, reset, validate_separately, **check_params)
|
101
|
+
564 raise ValueError("Validation should be done on X, y or both.")
|
102
|
+
565 elif not no_val_X and no_val_y:
|
103
|
+
--> 566 X = check_array(X, **check_params)
|
104
|
+
567 out = X
|
105
|
+
568 elif no_val_X and not no_val_y:
|
106
|
+
|
107
|
+
/usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator)
|
108
|
+
744 array = array.astype(dtype, casting="unsafe", copy=False)
|
109
|
+
745 else:
|
110
|
+
--> 746 array = np.asarray(array, order=order, dtype=dtype)
|
111
|
+
747 except ComplexWarning as complex_warning:
|
112
|
+
748 raise ValueError(
|
113
|
+
|
90
114
|
/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in __array__(self, dtype)
|
91
115
|
1991
|
92
116
|
1992 def __array__(self, dtype: NpDtype | None = None) -> np.ndarray:
|
1
要請に基づいて修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
|
9
9
|
コード
|
10
10
|
#########################
|
11
|
+
```python
|
11
12
|
import numpy as np
|
12
13
|
import random #擬似乱数を生成するライブラリー
|
13
14
|
from PIL import Image, ImageOps #画像処理ライブラリー
|
@@ -67,7 +68,7 @@
|
|
67
68
|
|
68
69
|
if __name__ == "__main__":
|
69
70
|
main()
|
70
|
-
|
71
|
+
```
|
71
72
|
|
72
73
|
|
73
74
|
エラーメッセージ
|