Python
1feature_df01 = get_train("OpenBCI-RAW-ita01.txt", 6.67, list01) 2feature_df02 = get_train("OpenBCI-RAW-ita02.txt", 7.14, list02) 3feature_df03 = get_train("OpenBCI-RAW-ita03.txt", 7.52, list03) 4 5train_feature = pd.concat([feature_df01, feature_df02]) 6 7labels_t = feature_df03['labels'] 8labels_t = np.array(labels_t.values.flatten()) 9del feature_df03['labels'] 10 11labels = train_feature['labels'] 12labels = np.array(labels.values.flatten()) 13del train_feature['labels'] 14 15y_train = labels[:90] 16y_test = labels_t 17 18pca = PCA(n_components=50) 19pca.fit(train_feature) 20X_train = pca.transform(train_feature) 21 22train_feature = pd.DataFrame(train_feature) 23 24lda = LDA(n_components=2) 25lda.fit(X_train, y_train) 26X_train = lda.transform(X_train) 27 28X_test = np.empty((45, 2), dtype='float32') 29 30for i in range(1, 45): 31 X = feature_df03.ix[i, :] 32 X = X.reshape(1, -1) 33 X = pca.transform(X) 34 X = lda.transform(X) 35 36 np.append(X_test, X) 37 38X_test1 = X_test[:15, :] 39y_test1 = y_test[:15] 40X_test2 = X_test[15:30, :] 41y_test2 = y_test[15:30] 42X_test3 = X_test[30:45, :] 43y_test3 = y_test[30:45] 44 45print(X_test1.shape,X_test2.shape,X_test3.shape) 46print(len(y_test1),len(y_test2),len(y_test3)) 47forest = RandomForestClassifier(n_estimators=300, min_samples_split=2, max_depth=3, max_features='auto') 48forest.fit(X_train, y_train) 49 50w1 = f1_score(y_test1, forest.predict(X_test1),average = 'micro') 51 52w2 = f1_score(y_test2, forest.predict(X_test2),average = 'micro') 53 54w3 = f1_score(y_test3, forest.predict(X_test3),average = 'micro') 55 56print(w1,w2,w3)
以上のようなコードを書いたのですが、
Traceback (most recent call last): File "forest_pca1.4.py", line 376, in <module> w1 = f1_score(y_test1, forest.predict(X_test1),average = 'micro') File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/ensemble/forest.py", line 538, in predict proba = self.predict_proba(X) File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/ensemble/forest.py", line 578, in predict_proba X = self._validate_X_predict(X) File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/ensemble/forest.py", line 357, in _validate_X_predict return self.estimators_[0]._validate_X_predict(X, check_input=True) File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/tree/tree.py", line 373, in _validate_X_predict X = check_array(X, dtype=DTYPE, accept_sparse="csr") File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/utils/validation.py", line 453, in check_array _assert_all_finite(array) File "/Users/beta/.pyenv/versions/anaconda3-4.1.1/lib/python3.5/site-packages/sklearn/utils/validation.py", line 44, in _assert_all_finite " or a value too large for %r." % X.dtype) ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
以上のようなエラーが出たり出なかったりします。
どのようなことが原因なのでしょうか。
よろしくお願いいたします。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/01 10:44
2018/05/01 10:59
2018/05/01 11:11
2018/05/01 11:27 編集
2018/05/01 11:33
2018/05/01 11:39 編集