現在、クロスバリデーションのよる学習方法について勉強しています。
作成したコードの学習部分が以下の通りです。
python
1for dataset in train_list: 2 X = dataset[[col for col in dataset.columns if col not in ['TARGET']]] 3 y = dataset.TARGET 4 5 X = StandardScaler().fit_transform(X) 6 7 folds = StratifiedKFold(n_splits= 5, shuffle=False) 8 9 for n_fold, (train_idx, test_idx) in enumerate(folds.split(X, y)): 10 print('{0}fold'.format(n_fold)) 11 print('TRAIN', train_idx) 12 print('VALID', test_idx) 13 print(X[train_idx].shape) 14 #print(X.iloc[train_idx].shape) #dfはindex指定で読み込むときilocを使う 15 logreg = LogisticRegression() 16 model = logreg.fit(X[train_idx], y[train_idx]) 17 model_list.append(model) 18 pred = logreg.predict_proba(X)[: , 1] 19 fpr, tpr, thresholds = roc_curve(y[test_idx], pred) 20 auc_score = roc_auc_score(y[test_idx], pred) 21 print('auc_score: ' , auc_score) 22 print() 23 pred_class = logreg.predict(X[test_idx]) 24 classes = [1, 0] 25 cm = confusion_matrix(y, pred_class, labels=classes) 26 print(cm) 27 print() 28コード
予めデータセットをいくつかに分け、それをtrain_listに保存しいます。
上記コードを実行したところ以下のようなエラーが発生してしまいます。
error: Input contains NaN, infinity or a value too large for dtype('float64').
データセット内にnull値がないことは確認し、また、同じデータセットリストを使ってtrain_test_splitによりtrainデータとtestデータに分け学習させた場合はうまく学習させることができました。
エラーの対処法について教えていただけると助かります。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー