本文共 1562 字,大约阅读时间需要 5 分钟。
支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本、非线性及高维模式识别中表现出许多特有的优势,并能够推广应用到函数拟合等其他机器学习问题中。
1 数学部分 1.1 二维空间clear;clc;%load financial data of the stock price of Apple company%The data is from Nov 18 1982-Nov 18 2012%The data contains six collums:Open, High, Low, Close, Volume, Adj Closesh = dlmread('yahoo.csv');%The data needs to flip because the data is from latest to earliest.sh = flipdim(sh,1);%extract data[m,n] = size(sh);ts = sh(2:m,1);tsx = sh(1:m-1,:);original = ts(length(sh)*0.7+1:end,:);% Draw the original graphic of the stock pricefigure;plot(ts,'LineWidth',1);title('Yahoo Stock Price(1996.4.12-2012.11.16) before mapping','FontSize',12);grid on;fprintf('Plot the stock price before mapping.\n');fprintf('Program paused. Press enter to continue.\n');pause;%data preprocessingts = ts';tsx = tsx';% mapminmax is an mapping function in matlab%Use mapminmax to do mapping[TS,TSps] = mapminmax(ts);% The scale of the data from 1 to 2TSps.ymin = 1;TSps.ymax = 2;%normalization[TS,TSps] = mapminmax(ts,TSps);% plot the graphic of the stock price after mappingfigure;plot(TS,'LineWidth',1);title('Yahoo Stock price after mapping','FontSize',12);grid on;fprintf('\nPlot the stock price after mapping.\n');fprintf('Program paused. Press enter to continue.\n');pause;% Transpose the data in order to meet the requirement of libsvmfprintf('\n Initializing.......\n');TS = TS';[TSX,TSXps] = mapminmax(tsx);TSXps.ymin = 1;TSXps.ymax = 2;[TSX,TSXps] = mapminmax(tsx,TSXps);TSX = TSX';
版本:2014a
完整代码或代写加QQ912100926转载地址:http://bqjrz.baihongyu.com/