【发布时间】:2020-02-28 09:49:26
【问题描述】:
大家好,世界你好。这是我的第一个 StackOverflow 问题,任何帮助都会很棒!
我正在尝试使用本地股票和 sklearn.svm's SVR 为股票预测创建一个简单的支持向量回归 (SVR) 模型。
train 是我的训练数据框,而
数据框只有日期和收盘价作为其列
GSCV() 是一个函数,它返回使用GridSearchCV 派生的最佳C 和gamma
train["Date"]=pd.to_datetime(train["Date"])
dates = pd.DataFrame.to_numpy(train["Date"]).reshape(-1,1)
closing_prices = (pd.DataFrame.to_numpy(train[' Close'])).reshape(-1,1)
c,g = GSCV('rbf',dates, closing_prices)
svr_rbf = SVR('rbf', C=c, gamma = g, cache_size=20000)
c,g = GSCV('linear',dates, closing_prices)
svr_lin = SVR(kernel= 'linear', C= c, gamma = g,cache_size=20000)
c,g = GSCV('poly',dates, closing_prices)
svr_poly = SVR(kernel= 'poly', C= c, degree= 2, gamma = g,cache_size=20000)
svr_rbf.fit(dates, closing_prices)
svr_lin.fit(dates, closing_prices)
svr_poly.fit(dates, closing_prices)
我想提一下,我有两种类型的数据集:低方差股票和高方差股票。当喂入低方差股票时,模型会立即终止,尽管始终保持不变的预测。另一方面,高方差股票导致了我的非终止问题。
我的实验需要根据 2、4、6、8、10 年的数据创建模型。最多,我有 2100 多个数据点,但即使只有 400 多个数据点,代码似乎也不会终止。这是不是太多了?
我试过了
1.使用StandardScaler缩放数据
2. 设置cache=20000 希望加速
感谢您的任何意见!
【问题讨论】:
标签: python scikit-learn svm stock