Class PLSR
source code
object --+
|
bases.BaseAlgorithm --+
|
bases.ImplicitAlgorithm --+
|
object --+ |
| |
bases.IterativeAlgorithm --+
|
PLSR
A NIPALS implementation for PLS regresison.
Parameters
----------
max_iter : Non-negative integer. Maximum allowed number of iterations.
Default is 200.
eps : Positive float. The tolerance used in the stopping criterion.
Examples
--------
>>> from parsimony.algorithms.nipals import PLSR
>>> import numpy as np
>>> np.random.seed(42)
>>>
>>> X = np.random.rand(10, 10)
>>> Y = np.random.rand(10, 5)
>>> w = np.random.rand(10, 1)
>>> c = np.random.rand(5, 1)
>>> plsr = PLSR()
>>> w, c = plsr.run([X, Y], [w, c])
>>> w
array([[ 0.34682103],
[ 0.32576718],
[ 0.28909788],
[ 0.40036279],
[ 0.32321038],
[ 0.39060766],
[ 0.22351433],
[ 0.28643062],
[ 0.29060872],
[ 0.23712672]])
>>> c
array([[ 0.29443832],
[ 0.35886751],
[ 0.33847141],
[ 0.23526002],
[ 0.35910191]])
>>> C, S, W = np.linalg.svd(np.dot(Y.T, X))
>>> w_ = W[0, :].reshape(10, 1)
>>> w_ = -w_ if w_[0, 0] < 0.0 else w_
>>> w = -w if w[0, 0] < 0.0 else w
>>> round(np.linalg.norm(w - w_), 15)
1.52884e-10
>>> abs(np.dot(np.dot(X, w).T,
... np.dot(Y, c / np.linalg.norm(c)))[0, 0] - S[0]) < 5e-15
True
|
__init__(self,
max_iter=200,
eps=5e-08,
**kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature |
source code
|
|
|
run(self,
XY,
wc=None)
A NIPALS implementation for PLS regresison. |
source code
|
|
Inherited from bases.BaseAlgorithm :
get_params ,
set_params
Inherited from bases.IterativeAlgorithm :
iter_reset
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
__init__(self,
max_iter=200,
eps=5e-08,
**kwargs)
(Constructor)
| source code
|
x.__init__(...) initializes x; see help(type(x)) for signature
- Overrides:
object.__init__
- (inherited documentation)
|
A NIPALS implementation for PLS regresison.
Parameters
----------
XY : List of two numpy arrays. XY[0] is n-by-p and XY[1] is n-by-q. The
independent and dependent variables.
wc : List of numpy array. The start vectors.
Returns
-------
w : Numpy array, p-by-1. The weight vector of X.
c : Numpy array, q-by-1. The weight vector of Y.
- Overrides:
bases.ImplicitAlgorithm.run
|