[英]How to do a linear regression with variables from a dataframe [Python]
我在 dataframe 中有两个变量 A 和 B。 当我尝试这个时:
x=df.['A']
y=df.['B']
M = LinearRegression()
M.fit(A,B)
我收到以下错误
Expected 2D array, got 1D array instead:
array=[86. 0. 86. ... 0. 0. 0.].
Reshape 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.
虽然当我尝试按照建议应用重塑时,我得到了一个“'系列' object 没有属性'重塑'”
我怎样才能解决这个问题?
您可以尝试将x
更改为 DataFrame 而不是 Series。
x = df[['A']]
y = df['B']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.