24小时热门版块排行榜    

Znn3bq.jpeg
查看: 2579  |  回复: 3

李琴李恺

金虫 (初入文坛)

[求助] 在MATLAB中如何用PLS确定最优主成分数 已有1人参与

在MATLAB中如何用PLS确定最优主成分数,258个样本,7个自变量,1个因变量,给出代码例子,加急,谢谢!
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Nkxz

铁杆木虫 (著名写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ...
感谢参与,应助指数 +1
李琴李恺: 金币+100, ★★★★★最佳答案 2014-03-18 17:22:32
dbb627: 编辑内容 2014-03-18 18:06
dbb627: 编辑内容 2014-03-18 18:08
用x代表自变量矩阵,y表示因变量向量,然后用以下几种方法来确定因子数:其中lv为最大因子数,您这个我建议用5-7试下,sel表示数据预处理方法,0为中心化,1为标准化,其它为不作处理,作完以后用rmsecv对因子数作图,找最低点或者拐点即可。(你有pls算法程序吧?)
CODE:
function [r,rmsecv,yp] = loocv2(x,y,lv,sel)
if nargin <4;sel = 1;end
T = size(x,1);
yp = zeros(size(y));
for i = 1:T
    x1 = x(i,:);
    ind = 1:T;ind(i) = [];
    x2 = x(ind,:);
    y2 = y(ind,:);
    if eq(sel,0)
        [x2,mx] = mncn(x2);
        x1 = scale(x1,mx);
        [y2,my] = mncn(y2);
    elseif eq(sel,1)
        [x2,mx,stdx] = auto(x2);
        x1 = scale(x1,mx,stdx);
        [y2,my,stdy] = auto(y2);
    end
    b = simpls(x2,y2,lv);
    yp0 = x1 * b(:,lv);
    if eq(sel,0)
        yp0 = rescale(yp0,my);
    elseif eq(sel,1)
        yp0 = rescale(yp0,my,stdy);
    end
    yp(i) = yp0;   
end
r = corr(yp,y);
rmsecv = rms(y-yp);

function [mcx,mx] = mncn(x)
%MNCN Mean center scales matrix to mean zero.
%  Mean centers matrix (x), returning a matrix with
%  mean zero columns (mcx) and the vector of means
%  (mx) used in the scaling.
%
%I/O: [mcx,mx] = mncn(x);
%
%See also: AUTO, MDAUTO, MDMNCN, MDRESCAL, MDSCALE, SCALE, RESCALE

%Copyright Eigenvector Research 1991-98
%Modified 11/93
%Checked on MATLAB 5 by BMW  1/4/97

[m,n] = size(x);
mx    = mean(x);
mcx   = (x-mx(ones(m,1),:));

function sx = scale(x,means,stds)
%SCALE Scales matrix as specified.
%  Scales a matrix (x) using means (mx) and standard
%  deviations (stds) specified.
%
%I/O:  sx = scale(x,mx,stdx);
%
%  If only two input arguments are supplied then the function
%  will not do variance scaling, but only vector subtraction.
%
%I/O:  sx = scale(x,mx);
%
%See also: AUTO, MDAUTO, MDMNCN, MDRESCAL, MDSCALE, MNCN, RESCALE

%Copyright Eigenvector Research, Inc. 1991-98
%Modified 11/93
%Checked on MATLAB 5 by BMW  1/4/97

[m,n] = size(x);
if nargin == 3
  sx = (x-means(ones(m,1),:))./stds(ones(m,1),:);
else
  sx = (x-means(ones(m,1),:));
end
function rx = rescale(x,mx,stdx)
%RESCALE Rescales matrix
%  Rescales a matrix (x) using the means (mx) and
%  standard deviation (stdx) vectors specified.
%
%I/O: rx = rescale(x,mx,stdx);
%
%  If only two input arguments are supplied the
%  function rescales the means only.
%
%I/O: rx = rescale(x,mx);
%
%See also:  AUTO, MDAUTO, MDMNCN, MDRESCAL, MDSCALE, MNCN, SCALE

%Copyright Eigenvector Research, Inc. 1991-98
%Modified 11/93
%Checked on MATLAB 5 by BMW  1/4/97

[m,n] = size(x);
if nargin == 3
  rx  = (x.*stdx(ones(m,1),:))+mx(ones(m,1),:);
else
  rx  = x+mx(ones(m,1),:);
end

function [ax,mx,stdx] = auto(x)
%AUTO Autoscales matrix to mean zero unit variance
%  Autoscales a matrix (x) and returns the resulting matrix (ax)
%  with mean-zero unit variance columns, a vector of means (mx)
%  and a vector of standard deviations (stdx) used in the scaling.
%
%I/O:  [ax,mx,stdx] = auto(x);
%
%See also: MDAUTO, MDMNCN, MDRESCAL, MDSCALE, MNCN, SCALE, RESCALE

%Copyright Eigenvector Research, Inc. 1991-98
%Modified 11/93
%Checked on MATLAB 5 by BMW  1/4/97

[m,n] = size(x);
mx    = mean(x);
stdx  = std(x);
ax    = (x-mx(ones(m,1),:))./stdx(ones(m,1),:);

[ Last edited by dbb627 on 2014-3-18 at 18:08 ]

» 本帖已获得的红花(最新10朵)

2楼2014-03-17 13:54:55
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

Nkxz

铁杆木虫 (著名写手)

【答案】应助回帖

笑脸用小写的:)来代替,囧。
3楼2014-03-17 13:55:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

李琴李恺

金虫 (初入文坛)

送红花一朵
引用回帖:
2楼: Originally posted by Nkxz at 2014-03-17 13:54:55
用x代表自变量矩阵,y表示因变量向量,然后用以下几种方法来确定因子数:其中lv为最大因子数,您这个我建议用5-7试下,sel表示数据预处理方法,0为中心化,1为标准化,其它为不作处理,作完以后用rmsecv对因子数作图 ...

您好,我是MATLAB新手,我没有pls算法程序,您可以给我吗?
您建议用5-7试下,是什么意思啊?
4楼2014-03-17 16:37:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 李琴李恺 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿安大生物学07初试322、本科二本、调剂求助 +10 李多米lee. 2026-04-12 11/550 2026-04-12 22:58 by yuyin1233
[考研] 0856专硕求调剂 希望是a区院校 +22 好好休息好不好 2026-04-09 25/1250 2026-04-12 17:09 by ajpv风雷
[考研] 322求调剂 +6 123安康 2026-04-12 13/650 2026-04-12 15:51 by 123安康
[考研] 材料与化工300求调剂 +39 肖开文 2026-04-09 43/2150 2026-04-12 01:30 by 秋豆菜芽
[教师之家] 请问地理、遥感方面,可以做哪些横向项目啊,纵向完不成考核啊 +3 锦衣卫寒战 2026-04-07 5/250 2026-04-11 20:51 by 豫椒
[考研] 求调剂 +6 archer.. 2026-04-09 8/400 2026-04-11 10:55 by zhq0425
[考研] 080100力学316求调剂 +8 L_Hairui 2026-04-07 8/400 2026-04-11 10:00 by zhq0425
[考研] 一志愿211,化学学硕,310分,本科重点双非,求调剂 +17 努力奋斗112 2026-04-06 20/1000 2026-04-11 00:31 by wangjihu
[考研] 一志愿华南理工大学331分材料求调剂 +9 天下ww 2026-04-09 9/450 2026-04-10 22:58 by Ftglcn90
[考研] 071000生物学调剂求助 +17 zzzzwww 2026-04-09 20/1000 2026-04-10 15:55 by 求调剂zz
[考研] 一志愿华东师范生物学326分,求调剂 +8 刘墨墨 2026-04-09 8/400 2026-04-10 12:00 by pengliang8036
[考研] 江苏大学 工科调剂 捡漏 +3 Evan_Liu 2026-04-09 5/250 2026-04-10 10:22 by Evan_Liu
[考研] 本科西工大 0856 324求调剂 +10 wysyjs25 2026-04-09 11/550 2026-04-10 08:37 by 5268321
[考研] 1U盾记得记得就 +9 sanjin020722 2026-04-08 10/500 2026-04-09 14:11 by 诗与自由
[考研] 招收有机化学、化工,药学,食品灯专业学生 +3 yrfhjgdj 2026-04-08 3/150 2026-04-09 10:15 by QYQX_123
[考研] 353求调剂 +8 晴空万里air 2026-04-07 8/400 2026-04-09 00:18 by GouQ
[考研] 生物学学硕,初试351分,求调剂 +4 …~、王…~ 2026-04-08 5/250 2026-04-08 21:49 by limeifeng
[考研] 323求调剂 +3 林zlu 2026-04-07 4/200 2026-04-07 23:21 by lbsjt
[考研] 331求调剂 +5 张元一 2026-04-07 6/300 2026-04-07 22:13 by hemengdong
[考研] 本科生物信息学,总分362 求07 08调剂 +6 q小倩1210 2026-04-06 6/300 2026-04-07 19:40 by macy2011
信息提示
请填处理意见