首页 > 编程知识 正文

时间序列模型回归步骤,时间序列回归法公式

时间:2023-05-05 06:30:07 阅读:154656 作者:1392

文章目录1.SVR时间序列预测2.SVR参数3.SVR高斯核和过拟合

1.SVR时间序列预测

SVR可用于时间序列分析,但不是一个很好的选择。 目前,一般使用LSTM神经网络处理时序数据

# SVR预测#也可用于时间序列分析(ARIMA也可用于时间序列分析) importnumpyasnpfromsklearnimportsvmimportmatplotlib.pyplotaspltif _ name _==结构数据n=50NP.random.seed(0) #排序x=NP.sort ) NP.random.uniform (0,6,n ),axis=0) y=2*np.sin(x y ) #高斯核函数print (SVR-RBF ) ) SVR _ RBF=SVM.SVR (kernel=) RBF y ) #线性核函数print(SVR-linear ) ) SVR _ linear=y ) #多项式核函数print(SVR-polynomial ) (SVR_poly=SVM.SVR ) kernel='poly ',degree=3, C=100 ) svr_poly.fit(x y ) print('fitok.' )思考:将系数1.1转换为1.5x _ test=NP.linspace (x.min )、1.1*x.max )、 100 ).reshape (更改为-1) y_RBF=SVR_RBF.predict(x_test ) y_linear=SVR_linear.predict ) x_test label='Linear Kernel ' ) PLT.plot(x_test,y_poly,' b- ',linewidth=2,label='Polynomial Kernel ' ) PLT.plot y[svr_rbf.support_],s=200,c='r ',marker zorder=10 ) PLT.legend(loc='lowerleft ' ) PLT.title ) stitle

2.SVR调参# SVR调参importnumpyasnpfromsklearnimportsvmfromsklearn.model _ selectionimportgridsearchcv # 0.17 grid _ searchimportmatplotlib.pyplotaspltif _ _ name _=' _ main _ ' 3360 n=50np.random.seed (0axis=0) 1 ) print ) ' x ) print y ) model=SVM.SVR(kernel='RBF ' ) # 0.01至100取100的数字c _ can=NP.logspace (-2,2,10 ) ' gamma': gamma_can},cv=5}SVR.fit(x,y ) print ) )验证参数:n ),SSV 100 ).reshape(-1, 1 ) y_hat=SVR.predict ) x _ test (sp=SVR.best _ estimator _.support _ PLT.figure () ) ),1 ) ) 660 ' r-',linewidth=2,label markersize=5) PLT.legend(loc='upperright ' ) PLT.title ),fontsize=16 ) PLT.xler

3.SVR高斯核和超配importnumpyasnpfromsklearnimportsvmimportmatplotlibasmplimportmatplotlib.colorsimportmatplotlib.pyplottplottib small=1.01,0.01返回big * a-small * b, big * B- small * AIF _ _ name _ _=' _ main _ ' 3360 t ) print(t2.ravel ).shape ) # np.stack是数组x1=NP.staststte np.concatenate沿现有轴的一系列数组# np.concatenate () x1, x2 ) ) y=NP.array ) [1]*n[-1]*n ) clf=SVM.SVC ) c ) c y ) y_hat=clf.predict(x ) print (准确率%.1f ) mpl.rcparams [ ' axes.unicode _ MINUS ' ]=false cm _ light=mpl.colors.listed colormap [ ' # 77e0a0',#ffao0a] (r 1 ).max(#1列范围x1,x2=NP.mgrid [ x1 _ min : x1 _ max 3360300 j, x2_min:x2_max:300j] #生成网格采样点grid的axis=1) #测试点grid_hat=clf.predict(grid_test ) grid _ test 属于与输入的形状相同的PLT.figure(facecolor )的cmap=cm _ light (PLT.scatter (x [ :0 ],x [ 3360,1 ],s=60,c=y ) cmap=cm_dark ) ) x2_max ) ) PLT.title(u'SVM的RBF核和过度拟合(,fontsize=18 ) PLT.tight_layout ) 0.2 ) PLT

如果对你有帮助的话,请关注麻烦的事情。 这真的对我很重要。 如果需要相互关闭,请留下评论!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。