首页 > 解决方案 > “分割数 n_splits=3 不能大于样本数:n_samples=1”

问题描述

我正在尝试使用 k 折交叉验证来比较我的多项式回归和支持向量机模型。(x 轴 = 油耗,y 轴 = 距离)

以下是我一直在尝试但出现错误的代码

"ValueError: cannot have number of splits n_splits=3 greater than the number of samples: n_samples=1"

代码:

from sklearn.model_selection import KFold
kf = Fold(n_splits=3)
kf
x=data.iloc[:,0]
y=data.iloc[:,1]
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.3)
for train_index,test_index in kf.split([['Distance']]):
print(train_index,test_index)

样本数据(数据集是二维的):

Fuel Consumption   Distance
13.046653          444.699427
14.717947          468.604994
15.032536          464.386458

谢谢!

标签: scikit-learnsvm

解决方案


您的样本数据长度应大于 100/test_size*10,在您的情况下为 100/30 =4 例/行或更多


推荐阅读