Tôi đã cố gắng chia nhỏ tập dữ liệu mẫu bằng cách sử dụng Scikit-learn's Stratified Shuffle Split. Tôi làm theo các ví dụ hiển thị trên Scikit-học tài liệu heresklearn.cross_validation.StratifiedShuffleSplit - error: "chỉ số là out-of-bounds"
import pandas as pd
import numpy as np
# UCI's wine dataset
wine = pd.read_csv("https://s3.amazonaws.com/demo-datasets/wine.csv")
# separate target variable from dataset
target = wine['quality']
data = wine.drop('quality',axis = 1)
# Stratified Split of train and test data
from sklearn.cross_validation import StratifiedShuffleSplit
sss = StratifiedShuffleSplit(target, n_iter=3, test_size=0.2)
for train_index, test_index in sss:
xtrain, xtest = data[train_index], data[test_index]
ytrain, ytest = target[train_index], target[test_index]
# Check target series for distribution of classes
ytrain.value_counts()
ytest.value_counts()
Tuy nhiên, khi chạy kịch bản này, tôi nhận được lỗi sau:
IndexError: indices are out-of-bounds
thể ai đó hãy chỉ ra những gì tôi đang làm sai ở đây ? Cảm ơn!
Dường như lỗi chỉ mục của bạn sẽ xảy ra ở đây: 'xtrain, xtest = data [train_index], dữ liệu [test_index]'. Nếu vậy, bạn có thể chỉnh sửa câu hỏi của mình để giúp người khác xác định sự cố. – Scott