Я пытаюсь это учебное моделирование с использованием train_test_split и дерева решений регрессор:ValueError: Не может иметь ряд расколы n_splits = 3 больше, чем число образцов: 1
import sklearn
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import cross_val_score
# TODO: Make a copy of the DataFrame, using the 'drop' function to drop the given feature
new_data = samples.drop('Fresh', 1)
# TODO: Split the data into training and testing sets using the given feature as the target
X_train, X_test, y_train, y_test = train_test_split(new_data, samples['Fresh'], test_size=0.25, random_state=0)
# TODO: Create a decision tree regressor and fit it to the training set
regressor = DecisionTreeRegressor(random_state=0)
regressor = regressor.fit(X_train, y_train)
# TODO: Report the score of the prediction using the testing set
score = cross_val_score(regressor, X_test, y_test, cv=3)
print score
При выполнении этого, я набираюсь ошибка:
ValueError: Cannot have number of splits n_splits=3 greater than the number of samples: 1.
Если изменить значение сорта 1, я получаю:
ValueError: k-fold cross-validation requires at least one train/test split by setting n_splits=2 or more, got n_splits=1.
Некоторые сэм Данные ряда выглядят так:
Fresh Milk Grocery Frozen Detergents_Paper Delicatessen
0 14755 899 1382 1765 56 749
1 1838 6380 2824 1218 1216 295
2 22096 3575 7041 11422 343 2564
Сколько строк у вас в 'new_data'? Можете ли вы вывести это и проверить один раз? –