scikit-learn - “分割数 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
谢谢!
解决方案
您的样本数据长度应大于 100/test_size*10,在您的情况下为 100/30 =4 例/行或更多
推荐阅读
- google-cloud-platform - 请求失败的影响,因为 HTTP 响应格式错误或与实例的连接有错误
- c# - 如何在 Xamarin.Forms 中复制本地数据库?
- android - 几乎每次启动应用程序时都会出现 Admob 同意对话框。状态未知
- java - 图像、PDF 下载在 Java Rest Api 中不起作用
- angular - Auth0 的 Apollo 订阅 ngModule 事件循环麻烦
- frameworks - 我想知道任何特定 apk 的语言?
- reactjs - react-hook-form 中出现错误消息的问题
- python-3.x - 卷积自动编码器 CIFAR10 PyTorch - RuntimeError
- flutter - Navigator Pushnamed not found route inside listview.builder in flutter
- css - Fas fa 竖起大拇指消失