Кросс-валидация в Python
Нужно получить кросс-валидацию на трёх равных по размеру блоках. Делаю так и получаю ошибку "ValueError: Expected 2D array, got 1D array instead":
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
data = pd.read_csv('/datasets/heart.csv')
features = data.drop(['target'], axis=1)
target = data['target']
scores = []
sample_size = int(len(data)/3)
for i in range(0, len(data), sample_size):
valid_indexes = data.iloc[i: i + sample_size].index
train_indexes = (data.iloc[:i] + data.iloc[i + sample_size:]).index
features_train = features.iloc[train_indexes]
features_valid = features.iloc[valid_indexes]
target_train = target.iloc[train_indexes]
target_valid = target.iloc[valid_indexes]
model = DecisionTreeClassifier(random_state=0)
model = model.fit(features_train, target_train)
score = model.score(target_valid, features_valid)
scores.append(score)
final_score = score.mean()
print('Средняя оценка качества модели:', final_score)
ValueError: Expected 2D array, got 1D array instead:
array=[0. 1. 1. 1. 0. 1. 0. 0. 0. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. 0. 1. 0. 0. 1.
0. 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1. 1. 0. 0. 1. 0. 0. 0. 0. 0. 1. 1.