使用SVR预测比特币价格时,如何使r2为正?

时间:2018-11-23 07:54:30

标签: svm bitcoin

我尝试使用SVR预测比特币价格,并且包含30多个变量,但是预测结果很差。我该如何改善它或至少使R2为正?

from sklearn.svm import SVR
from sklearn.model_selection import GridSearchCV
import pandas as pd
from sklearn import preprocessing
from sklearn.metrics import mean_squared_error,r2_score
import numpy as np
def mean_absolute_percentage_error(y_true, y_pred):
    y_true, y_pred = np.array(y_true), np.array(y_pred)
    return np.mean(np.abs((y_true - y_pred) / y_true))

data=pd.read_excel(r'X:\final.xlsx')
start_train='2014-01-01'
end_train='2017-12-31'
start_test='2018-01-01'
end_test='2018-12-31'
data=data.set_index('Date')
data_train=data.ix[start_train:end_train]
x_columns=list(data.drop((['next_price']),axis=1).columns)
y_column='next_price'

x_train=data_train[x_columns]
y_train=data_train[y_column]
x_train = preprocessing.scale(x_train)
data_test=data.ix[start_test:end_test]
x_test=data_test[x_columns]
y_test=data_test[y_column]
x_test = preprocessing.scale(x_test)

svr=SVR(kernel='linear')
svr.fit(x_train,y_train)
predictions=svr.predict(x_test)

print('MAPE: {0:.3f}'.format(mean_absolute_percentage_error(y_test,predictions)))
print('RMSE: {0:.3f}'.format((mean_squared_error(y_test,predictions))**0.5))
print('R^2: {0:.3f}'.format(r2_score(y_test,predictions)))

MAPE:0.889; m / z。 RMSE:7836.500; R ^ 2:-11.642

dates=data_test.index.values
plot_truth,=plt.plot(dates,y_test,'k')
plot_svr,=plt.plot(dates,predictions,'g')
plt.title('Real price VS Predicted price')
plt.show()

<code>[enter image description here][1]</code>

原始数据在这里[1]:https://drive.google.com/open?id=1Na0WB5zrCbafb4xnBM9ggRsm8p1LsvXi

0 个答案:

没有答案