【发布时间】:2016-11-12 03:01:07
【问题描述】:
我正在尝试预测我的系列第二天的股价,但我不知道如何“查询”我的模型。这是我的 Python 代码:
# Define my period
d1 = datetime.datetime(2016,1,1)
d2 = datetime.datetime(2016,7,1)
# Get the data
df = web.DataReader("GOOG", 'yahoo', d1, d2)
# Calculate some indicators
df['20d_ma'] = pandas.rolling_mean(df['Adj Close'], window=20)
df['50d_ma'] = pandas.rolling_mean(df['Adj Close'], window=50)
# Create the model
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import train_test_split
X = df[list(df.columns)[6:]] # Adj Close and indicators...
y = df['Adj Close']
X_train, X_test, y_train, y_test = train_test_split(X, y)
model = LinearRegression()
model.fit(X_train,y_train)
好的,我需要查询模型( model.predict(..¿?..) )来预测“下一天”的股价。
我该怎么做?
先谢谢了!!!
【问题讨论】:
标签: python machine-learning sklearn-pandas