【发布时间】:2020-03-11 11:27:26
【问题描述】:
在 sklearn 中,为了在线性回归中使用 fit 方法训练数据,我们必须重塑一维数组。但是,在具有多个变量的线性回归的情况下,我得到了输出而没有对目标变量进行整形。
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
df = pd.read_csv("Weather.csv",low_memory = False) # the data set I used
df1 = df[["Precip","MaxTemp"]]
reg = LinearRegression().fit(df1.head(),df.MinTemp.head()) # no error with shape of df1 is (5,2) and shape of df.MinTemp.head() is (5,)
我能知道这背后的原因吗?提前致谢。
【问题讨论】:
-
Fit 以 df1.head() 为 X(特征)和 df.MinTemp.head() 作为 Y(值),你能告诉我们错误发生在哪里吗?你的错误stackoverflow.com/questions/45704226/…
标签: python machine-learning linear-regression