scikit learn机器学习包中包含了偏最小二乘回归,所以可以调用对应的函数来实现

class sklearn.cross_decomposition.PLSRegression(n_components=2, scale=True, max_iter=500, tol=1e-06, copy=True)

参数信息:

Parameters:

n_components : int, (default 2)

Number of components to keep.(要保留的主成分数量,默认为2)

scale : boolean, (default True)

whether to scale the data (是否归一化数据,默认为是)

max_iter : an integer, (default 500)

the maximum number of iterations of the NIPALS inner loop (used only if algorithm=”nipals”) (使用NIPALS时的最大迭代次数)

tol : non-negative real

Tolerance used in the iterative algorithm default 1e-06. (迭代截止条件)

copy : boolean, default True

Whether the deflation should be done on a copy. Let the default value to True unless you don’t care about side effect

Attributes:

x_weights_ : array, [p, n_components]

X block weights vectors.

y_weights_ : array, [q, n_components]

Y block weights vectors.

x_loadings_ : array, [p, n_components]

X block loadings vectors.

y_loadings_ : array, [q, n_components]

Y block loadings vectors.

x_scores_ : array, [n_samples, n_components]

X scores.

y_scores_ : array, [n_samples, n_components]

Y scores.

x_rotations_ : array, [p, n_components]

X block to latents rotations.

y_rotations_ : array, [q, n_components]

Y block to latents rotations.

coef_: array, [p, q] :

The coefficients of the linear model: Y = X coef_ + Err

n_iter_ : array-like

Number of iterations of the NIPALS inner loop for each component.

Notes

Matrices:

T: x_scores_
U: y_scores_
W: x_weights_
C: y_weights_
P: x_loadings_
Q: y_loadings__

Are computed such that:

X = T P.T + Err and Y = U Q.T + Err
T[:, k] = Xk W[:, k] for k in range(n_components)
U[:, k] = Yk C[:, k] for k in range(n_components)
x_rotations_ = W (P.T W)^(-1)
y_rotations_ = C (Q.T C)^(-1)

where Xk and Yk are residual matrices at iteration k.

Slides explaining PLS <http://www.eigenvector.com/Docs/Wise_pls_properties.pdf>

For each component k, find weights u, v that optimizes: max corr(Xk u, Yk v) * std(Xk u) std(Yk u), such that |u| = 1

Note that it maximizes both the correlations between the scores and the intra-block variances.

The residual matrix of X (Xk+1) block is obtained by the deflation on the current X score: x_score.

The residual matrix of Y (Yk+1) block is obtained by deflation on the current X score. This performs the PLS regression known as PLS2. This mode is prediction oriented.

This implementation provides the same results that 3 PLS packages provided in the R language (R-project):

  • “mixOmics” with function pls(X, Y, mode = “regression”)
  • “plspm ” with function plsreg2(X, Y)
  • “pls” with function oscorespls.fit(X, Y)

References

Jacob A. Wegelin. A survey of Partial Least Squares (PLS) methods, with emphasis on the two-block case. Technical Report 371, Department of Statistics, University of Washington, Seattle, 2000.

In french but still a reference: Tenenhaus, M. (1998). La regression PLS: theorie et pratique. Paris: Editions Technic.

Examples

>>>

>>> from sklearn.cross_decomposition import PLSRegression
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
>>> Y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
>>> pls2 = PLSRegression(n_components=2)
>>> pls2.fit(X, Y)
...
PLSRegression(copy=True, max_iter=500, n_components=2, scale=True,
        tol=1e-06)
>>> Y_pred = pls2.predict(X)

Methods

fit(X, Y) Fit model to data.
fit_transform(X[, y]) Learn and apply the dimension reduction on the train data.
get_params([deep]) Get parameters for this estimator.
predict(X[, copy]) Apply the dimension reduction learned on the train data.
score(X, y[, sample_weight]) Returns the coefficient of determination R^2 of the prediction.
set_params(**params) Set the parameters of this estimator.
transform(X[, Y, copy]) Apply the dimension reduction learned on the train data.
__init__(n_components=2scale=Truemax_iter=500tol=1e-06copy=True)[source]
fit(XY)[source]

Fit model to data.

Parameters:

X : array-like, shape = [n_samples, n_features]

Training vectors, where n_samples in the number of samples and n_features is the number of predictors.

Y : array-like of response, shape = [n_samples, n_targets]

Target vectors, where n_samples in the number of samples and n_targets is the number of response variables.

fit_transform(Xy=None**fit_params)[source]

Learn and apply the dimension reduction on the train data.

Parameters:

X : array-like of predictors, shape = [n_samples, p]

Training vectors, where n_samples in the number of samples and p is the number of predictors.

Y : array-like of response, shape = [n_samples, q], optional

Training vectors, where n_samples in the number of samples and q is the number of response variables.

copy : boolean, default True

Whether to copy X and Y, or perform in-place normalization.

Returns:

x_scores if Y is not given, (x_scores, y_scores) otherwise. :

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:

deep: boolean, optional :

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params : mapping of string to any

Parameter names mapped to their values.

predict(Xcopy=True)[source]

Apply the dimension reduction learned on the train data.

Parameters:

X : array-like of predictors, shape = [n_samples, p]

Training vectors, where n_samples in the number of samples and p is the number of predictors.

copy : boolean, default True

Whether to copy X and Y, or perform in-place normalization.

Notes

This call requires the estimation of a p x q matrix, which may be an issue in high dimensional space.

score(Xysample_weight=None)[source]

Returns the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as (1 - u/v), where u is the regression sum of squares ((y_true - y_pred) ** 2).sum() and v is the residual sum of squares ((y_true - y_true.mean()) ** 2).sum(). Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters:

X : array-like, shape = (n_samples, n_features)

Test samples.

y : array-like, shape = (n_samples) or (n_samples, n_outputs)

True values for X.

sample_weight : array-like, shape = [n_samples], optional

Sample weights.

Returns:

score : float

R^2 of self.predict(X) wrt. y.

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns: self :
transform(XY=Nonecopy=True)[source]

Apply the dimension reduction learned on the train data.

Parameters:

X : array-like of predictors, shape = [n_samples, p]

Training vectors, where n_samples in the number of samples and p is the number of predictors.

Y : array-like of response, shape = [n_samples, q], optional

Training vectors, where n_samples in the number of samples and q is the number of response variables.

copy : boolean, default True

Whether to copy X and Y, or perform in-place normalization.

Returns:

x_scores if Y is not given, (x_scores, y_scores) otherwise. :

Python偏最小二乘回归(PLSR)测试相关推荐

  1. python 偏最小二乘回归实现

    用自己数据实现偏最小二乘回归.用Hitters数据集做演示如何使用自己的数据实现偏最小二乘回归. 此数据集有322个运动员的20个变量的数据, 其中的变量Salary(工资)是我们关心的. 数据下载 ...

  2. 【数学建模学习】偏最小二乘回归PLSR原理和板子

    解决问题方向:对于n个自变量,m个因变量的建模问题. 原理:首先在自变量集中提出第一主成分u1(PCA,x1-xn的线性组合),同时在因变量中集中提出第一主成分v1,并要求u1,v1的相关程度达到最大 ...

  3. python 偏最小二乘回归

    用sklearn库带的Linnerud数据集做示例 Linnerud数据集包含三个因变量和三个自变量 import pandas as pd from sklearn.cross_decomposit ...

  4. 偏最小二乘回归(PLSR)

    个人理解,有误请指出.

  5. matlab偏最小二乘截距,matlab代写偏最小二乘回归(PLSR)和主成分回归(PCR)

    原标题:matlab代写偏最小二乘回归(PLSR)和主成分回归(PCR) 原文:http://tecdat.cn/?p=2655 此示例显示如何在matlab中应用偏最小二乘回归(PLSR)和主成分回 ...

  6. 偏最小二乘回归(PLSR)和主成分回归(PCR)

    本项目中我们被要求显示如何在matlab中应用偏最小二乘回归(PLSR)和主成分回归(PCR),并讨论这两种方法的有效性.当存在大量预测变量时,PLSR和PCR都是对因变量建模的方法,并且这些预测变量 ...

  7. MATLAB中的偏最小二乘回归(PLSR)和主成分回归(PCR)

    通过Matlab示例来解释偏最小二乘的原理 此示例显示如何在matlab中应用偏最小二乘回归(PLSR)和主成分回归(PCR),并讨论这两种方法的有效性. 当存在大量预测变量时,PLSR和PCR都是对 ...

  8. python pls_【建模应用】PLS偏最小二乘回归原理与应用

    1.回归 "回归"一词来源于对父母身高对于子女身高影响的研究.有人对父母的身高与子女身高做统计,发现除了父母高则子女普遍高的常识性结论外,子女的身高总是"趋向" ...

  9. 偏最小二乘回归(partial least squares regression,PLSR)

    参考博客:典型相关分析.偏最小二乘回归 给定数据自变量XXX和因变量YYY, 最小二乘回归:找的是一个线性变换AAA,让∥Y−XA∥F\|Y - XA\|_F∥Y−XA∥F​最小 典型相关分析:找的是 ...

最新文章

  1. thrift RPC接口请求超时
  2. 图解Numpy的tile函数
  3. javafx css颜色_JavaFX技巧7:使用CSS颜色常量/派生颜色
  4. python prettytable表格列数太多_excel列数太多了怎么办
  5. 阿里云总裁张建锋:新型计算体系结构正在形成
  6. python三种变量方式_python2.x 3种变量形式调用
  7. 日本的“电力路由器”概述
  8. 爬取TAPTAP游戏应用榜单
  9. selenium tips
  10. SpringBoot使用Jib将应用快速打包成Docker镜像
  11. 计算机科学与技术学院老师颁奖词,各种颁奖词收集与各类奖学金、各种称号、各种职位中英文对照(个人简历用得上)合集.doc...
  12. JVM|记一次生产环境 CPU 占用飙高问题解决
  13. 三周爆赚千万 电竞选手在无聊猿游戏赢麻了
  14. 防御sql注入之参数化查询
  15. Win10怎么关闭smartscreen筛选器检测功能?
  16. android如何使用gif动画效果,Android中用GifView显示Gif动画及Gifview简介
  17. 阿里easyexcel通过模板导出excel
  18. 物联网卡拉开智能家居变革序幕
  19. Fiddler(三)- Fiddler命令行和HTTP断点调试
  20. android知乎日报中的动画,开发Android知乎日报(一)简介

热门文章

  1. 电影《人工智能》观后感
  2. IDEA如何导入jar包
  3. 中国地址英文书写格式
  4. vuecli3打包规范
  5. OpenJudge_P8207 和为给定数
  6. 【针对产品说测试】之测试“用户登录”
  7. leetcode:518. 零钱兑换 II
  8. 【深度学习】最大熵马尔科夫、CRF、条件随机场、最大匹配法
  9. 卡特兰数 卡塔兰数 概念 代码实现 模型分析全集
  10. 机器学习笔记 一:机器学习思路