zoukankan      html  css  js  c++  java
  • MATLAB做主成分分析(PCA)

      简单的主成分分析。第一次见识PCA,我的认识是,尽量用更少的维度来描述数据,以达到理想(虽不是最好,但是''性价比''最高)的效果。

    %% 主成分分析降维
    clear;
    % 参数初始化
    inputfile = 'F:TechonolgoyMATLABfileMTALAB数据分析与挖掘实战Datasetschapter4chapter4示例程序dataprincipal_component.xls';
    outputfile = 'F:TechonolgoyMATLABfileMTALAB数据分析与挖掘实战4dimention_reducted.xls';
    proporition = 0.95;
    %% 数据读取
    [num,~] = xlsread(inputfile);
    %% 主成分分析
    [coeff,~,latent] = pca(num);    %coeff每列为特征向量,latent为对应特征值
    %% 计算累计贡献度,确认维度
    sum_latent = cumsum(latent/sum(latent));  % 累计贡献率
    dimension = find(sum_latent>proporition);
    dimension = dimension(1);
    
    %% 降维
    data = num*coeff(:,1:dimension);
    xlswrite(outputfile,data);
    
    disp('主成分特征根:');
    disp(latent');
    disp('主成分单位特征向量:');
    disp('累计贡献率');
    disp(sum_latent');
    disp(['主成分分析完成,降维后的数据在'  outputfile])
    
    %哈里路亚
    load handel
    sound(y,Fs)
    

      还有,运行到最后会播放一段振奋人心的歌曲哈!

  • 相关阅读:
    IAccessible ( 一 )
    object sender,EventArgs e的一些讲解
    C# 操作符重载
    MSAA简介
    小试NArrange
    C++宏
    Ext.form.ComboBox简单用法
    SQL SERVER 收缩数据库的命令
    ext.grid的配置属性和方法
    磁盘阵列
  • 原文地址:https://www.cnblogs.com/buzhizhitong/p/5877738.html
Copyright © 2011-2022 走看看