在Python中线性回归中获取每一行的系数

时间:2018-07-03 07:56:51

标签: python python-2.7 extjs scikit-learn linear-regression

所以我正在读取CSV文件,并尝试使用获取每一行的系数

df = pd.read_csv(os.path.join(path))
X = df['param_a']
y= df['param_b']
X_train, X_test, y_train, y_test= train_test_split(X,y)
reg = linear_model.LinearRegression()
reg.fit(X_train, y_train)


print('Coefficients: \n', reg.coef_)

这将返回错误:

"Expected 2D array, got 1D array instead:\narray=[-100    0    0  100  -20  250  200 -125 -250    0   20 -250 -200  125  -10].\nReshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample."

我正在尝试将每一行的系数添加到网格中。please see grid image here

有人,请帮忙吗?谢谢

1 个答案:

答案 0 :(得分:0)

问题取决于您同时定义visibilityX的方式。 您应该尝试添加额外的一对方括号。 从而改变了这一点:

y

对此:

X = df['param_a']
y= df['param_b']

希望这会有所帮助