我写了一小段代码来使用sklearn进行线性回归。TypeError:难以置信的类型
我创建了一个2列csv文件(列名为X,Y有一些数字),当我读取文件时,我看到内容已正确读取 - 如下所示。
但是,我得到“unhashable型”的错误,当我尝试使用命令datafile[:,:]
或datafile[:,-1]
等来指代一列..
当我尝试使用X作为回应,Y为预测中sklearn的线性回归,我得到如下所示的Value错误。
我在网上查找,但无法弄清楚我的代码或文件出了什么问题。请帮忙。
import pandas as pd
datafile=pd.read_csv('samplelinear.csv')
datafile
X Y
0 0 1.440000
1 1 33.220000
. . .
print datafile.__class__
<class 'pandas.core.frame.DataFrame'>
datafile[:,:]
TypeError: unhashable type
datafile[:,:1]
TypeError: unhashable type
from sklearn.linear_model import LinearRegression
model=LinearRegression()
model.fit(datafile.X,datafile.Y)
ValueError: Found arrays with inconsistent numbers of samples: [ 1 14]
非常感谢你.. – qurious