【发布时间】:2015-01-22 07:06:39
【问题描述】:
我有一个“.dat”文件,其中保存了 X 和 Y 的值(所以是一个元组 (n,2),其中 n 是行数)。
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as interp
from sklearn import linear_model
in_file = open(path,"r")
text = np.loadtxt(in_file)
in_file.close()
x = np.array(text[:,0])
y = np.array(text[:,1])
我为linear_model.LinearRegression() 创建了一个实例,但是当我调用.fit(x,y) 方法时,我得到了
IndexError: 元组索引超出范围
regr = linear_model.LinearRegression()
regr.fit(x,y)
我做错了什么?
【问题讨论】:
-
对不起,我完全误读了你的问题:(我已经删除了答案,如果我能得到修复,那么我将取消删除编辑后的答案。但是你能提供更多信息吗?比如你的完整代码?
-
这是你需要的代码,没有其他重要的了。
-
真的吗?
linear_model是什么?你是怎么得到它的? -
现在就这些了,感谢您的帮助。
-
x 和 Y 的长度是否相同?
标签: python scikit-learn