Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Sklearn:ValueError:找到样本数不一致的输入变量:[500,1]_Python_Pandas_Machine Learning_Scikit Learn - Fatal编程技术网

Python Sklearn:ValueError:找到样本数不一致的输入变量:[500,1]

Python Sklearn:ValueError:找到样本数不一致的输入变量:[500,1],python,pandas,machine-learning,scikit-learn,Python,Pandas,Machine Learning,Scikit Learn,我正在使用python的sklearn库解决一个机器学习问题 我正在使用pandas dataframe,我想使用本地数据训练一个线性回归模型,并预测新的值。这是我的代码示例 customers= pd.read_csv('Ecommerce Customers') X= customers[['Avg. Session Length', 'Time on App','Time on Website', 'Length of Membership']] y=['Yearly Amount Spe

我正在使用python的sklearn库解决一个机器学习问题

我正在使用pandas dataframe,我想使用本地数据训练一个线性回归模型,并预测新的值。这是我的代码示例

customers= pd.read_csv('Ecommerce Customers')
X= customers[['Avg. Session Length', 'Time on App','Time on Website', 'Length of Membership']]
y=['Yearly Amount Spent']
当我尝试运行下面的代码时

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, random_state=101)
这给了我一个错误

Found input variables with inconsistent numbers of samples: [500, 1]
在我的数据集中,它有500行和8列 斯克威瑞恩是

import sklearn
format(sklearn.__version__)
'0.20.1'
请帮帮我。
提前感谢

仔细查看您的代码,您不会像您可能想做的那样,将
y
作为数据帧
客户的一列;照你说的

y=['Yearly Amount Spent']
y
只是一个单元素列表:

y
# ['Yearly Amount Spent']
因此,scikit learn有理由抱怨标签的长度
y
仅为1

换成

y=customers['Yearly Amount Spent']

仔细查看您的代码,您不会像您可能想做的那样,将
y
作为数据框
客户的一列;照你说的

y=['Yearly Amount Spent']
y
只是一个单元素列表:

y
# ['Yearly Amount Spent']
因此,scikit learn有理由抱怨标签的长度
y
仅为1

换成

y=customers['Yearly Amount Spent']