中学生网站作品,一般公司建设网站布局,常用的网页制作工具有哪几种,wordpress 首页 动第一步#xff1a;下载数据集。
https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#pendigits 第二步#xff1a;改变数据格式。
注#xff1a;此数据集的各特征值均为像素#xff0c;即属于同一量纲#xff0c;故无需归一化步骤。
原格式为下载数据集。
https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multiclass.html#pendigits 第二步改变数据格式。
注此数据集的各特征值均为像素即属于同一量纲故无需归一化步骤。
原格式为8 1:88 2:92 3:2 4:99 5:16 6:66 7:94 8:37 9:70 12:24 13:42 14:65 15:100 16:100
改为88 92 2 99 16 66 94 37 70 0 0 24 42 65 100 100 8
Java代码 public class dataformat {public static void main(String[] args) throws IOException{String filename pendigits.t;String outfilename pendigits;int demension 16;try(Scanner in new Scanner(new FileInputStream(filename));PrintWriter out new PrintWriter(outfilename)){String line;while( in.hasNextLine()){line in.nextLine();//按空格将数据切分String[] subComponent line.trim().split( );//data用于记录对应维度下的特征值String[] data new String[demension];//第0个是类标所以从1开始构造样例的全部特征值for (int i 1; i subComponent.length; i){String[] kv subComponent[i].trim().split(:);//将对应维度下的特征值赋值。data[Integer.parseInt(kv[0])-1] kv[1];}//sb用来构造一行样例StringBuilder sb new StringBuilder();for (int i 0; i demension; i){if (data[i] ! null)sb.append(data[i] );elsesb.append(0 ); //如果对应维度下的字符串为null说明为0值。}sb.append(subComponent[0].trim());//末尾加类标out.println(sb.toString()); //写文件}}}
}
第三步Matlab作图。
将处理好的文件pendigits加入MATLAB路径
新建脚本pcaVisual.m代码如下
load pendigits; % 加载数据集前提是pendigits文件在MATLAB路径下
[m,n]size(pendigits); % 获得pendigts的行数m列数n
[pc, score, latent, tsquare]pca(pendigits(:,1:n-1));% pca是主成分分析算法参数是需要降维的矩阵pendigits(:,1:n-1)——除去类标列。
% 返回的结果
% pc是(n-1)*(n-1)系数矩阵用它将pendigits(:,1:n-1)转换为score
% score是转换之后的特征值大小为m*(n-1)按latent降序排列按需取前k列此处我们只需取前三列。
% latent是一维列向量大小为(n-1)*1每一个数据是对应score里相应维的贡献率降序排列plot3(0,0,0); % plot(0,0)可用于展示2维图形但用旋转按钮进行拖动的话可以看到其实际就是3维。
hold on;% 根据样例的列表来画图
for i1:mswitch pendigits(i,n)case 0plot3(score(i,1),score(i,2),score(i,3),y*);case 1plot3(score(i,1),score(i,2),score(i,3),m*);case 2plot3(score(i,1),score(i,2),score(i,3),c*);case 3plot3(score(i,1),score(i,2),score(i,3),r*);case 4plot3(score(i,1),score(i,2),score(i,3),g*);case 5plot3(score(i,1),score(i,2),score(i,3),b*);case 6plot3(score(i,1),score(i,2),score(i,3),w*);case 7plot3(score(i,1),score(i,2),score(i,3),k*);case 8plot3(score(i,1),score(i,2),score(i,3),kd);otherwiseplot3(score(i,1),score(i,2),score(i,3),kv);end
end 三维立体图 点击箭头所指按钮可以三维旋转来观察其结构。 二维平面图