问题
首先,我对机器学习还很陌生。我决定在一些金融数据上测试我学到的一些东西我的机器学习模型如下:
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
df = pd.read_csv("/Users/Documents/Trading.csv")
poly_features = PolynomialFeatures(degree=2, include_bias=False)
linear_reg = LinearRegression(fit_intercept = True)
X = df_copy[["open","volume", "base volume", "RSI_14"]]
X_poly = poly_features.fit_transform(X)[1]
y = df_copy[["high"]]
linear_reg.fit(X_poly, y)
x = linear_reg.predict([[1.905E-05, 18637.07503453,0.35522205, 69.95820948552947]])
print(x)
一切都很好,直到我努力实现
PolynomialFeatures
这将导致以下错误:
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.
试图解决问题:
Atempt 1号
我试过添加.values到
X
但同样的错误仍然会出现:
X_poly = poly_features.fit_transform(X.values)[1]
Atempt 2号
我试着通过添加
reshape(-1, 1)
结束时
X_poly
:
X_poly = poly_features.fit_transform(X)[1].reshape(-1, 1)
但它只是用以下错误替换了先前的错误:
ValueError: Found input variables with inconsistent numbers of samples: [14, 5696]
非常感谢你的帮助。