遇到库存预测算法问题

时间:2018-12-23 19:14:28

标签: python svm quantitative-finance

我正在尝试使用教程来构建基本的库存预测工具。但是,我的代码一直挂着。有人咨询吗?

import csv
import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt

dates = list(range(1,65))
prices = []

def get_data(filename):
    with open(filename,'rU') as csvfile:
        csvFileReader = csv.reader(csvfile)
        csvFileReader.next()
        for row in csvFileReader:
            prices.append(float(row[1]))
        prices.reverse()
    return

def predict_prices(dates, prices, x):
    dates = np.reshape(dates, (len(dates),1))

    svr_lin = SVR(kernel='linear',C=1e3)
    svr_poly = SVR(kernel='poly', C=1e3, degree = 2)
    svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
    svr_lin.fit(dates,prices)
    svr_poly.fit(dates,prices)
    svr_rbf.fit(dates, prices)

    plt.scatter(dates, prices, color='black',label='Data')
    plt.plot(dates, svr_rbf.predict(dates), color = 'red', label = 'RBF Model')
    plt.plot(dates, svr_lin.predict(dates), color = 'green', label = 'Linear 
    Model')
    plt.plot(dates, svr_poly.predict(dates), color = 'blue', label ='Polynomial 
    Model')
    plt.xlabel('Date')
    plt.ylabel('Price')
    plt.title('Support Vector Regression')
    plt.legend()
    plt.show()

    return svr_rbf.predict(x)[0], svr_poly.predict(x)[0], svr_lin.predict(x)[0]

get_data('HistoricalQuotes.csv')
print(len(prices))
predicted_prices = predict_prices(dates, prices, 64)

我应该如何为我的Forecast_prices函数中的fit方法使用64天的列表创建2D数组?

0 个答案:

没有答案