Python 尝试对信用卡默认数据进行列车测试拆分时出现错误消息
我尝试对来自的信用卡默认数据进行列车测试拆分 这是我的代码:Python 尝试对信用卡默认数据进行列车测试拆分时出现错误消息,python,arrays,train-test-split,Python,Arrays,Train Test Split,我尝试对来自的信用卡默认数据进行列车测试拆分 这是我的代码: import sklearn import pandas as pd data = pd.read_excel("default of credit card clients.xls", sep=";") x = data.drop(columns=['ID', 'default payment next month'], axis=1) y = data['default payment next month'] x_tra
import sklearn
import pandas as pd
data = pd.read_excel("default of credit card clients.xls", sep=";")
x = data.drop(columns=['ID', 'default payment next month'], axis=1)
y = data['default payment next month']
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(test_size=0.1)
当我尝试运行它时,会收到以下消息:
File "C:\Users\Kizo\Anaconda3\envs\tensorflow\lib\site-packages\sklearn\model_selection\_split.py",
line 2086, in train_test_split
raise ValueError("At least one array required as input")
ValueError: At least one array required as input
在我看来,x&y并没有传递给train test split函数,因为当我打印变量时,它们看起来像数组。请帮忙 正如您所说,
x
和y
没有在您提供的代码行中传递。您只传递参数test\u size
的值,但缺少x
和y
值。你应该试试:
x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x,y,test_size=0.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.1)