tensorly.regression
.CP_PLSR
- class CP_PLSR(n_components, tol=1e-09, n_iter_max=100, random_state=None, verbose=False)[source]
CP tensor regression
Learns a low rank CP tensor weight, This performs a partial least square regression to a tensor X (>= 2 modes) against a matrix Y. The first modes of X and Y will be considered coupled, and the decomposition will maximize the covariance between them.
- Parameters:
- n_componentsint
rank of the CP decomposition of the regression weights
- tolfloat
convergence value
- n_iter_maxint, optional, default is 100
maximum number of iteration
- random_stateNone, int or RandomState, optional, default is None
- verbosebool, default is False
whether to be verbose during fitting
References
[1]Rasmus Bro, “Multiway calibration. Multilinear PLS”, Chemometrics, 1996
- fit(X, Y)[source]
Fits the model to the data (X, Y)
- Parameters:
- Xndarray
tensor data of shape (n_samples, N1, …, NS)
- Y2D-array of shape (n_samples, n_predictions)
labels associated with each sample
- Attributes:
- X_factorslist of ndarray of shape (X.shape[i], n_components)
The factors of X tensor to approximate X. The first component, X_factors[0], directs to the maximal covariance with Y_factors[0]
- Y_factorslist of ndarray of shape (Y.shape[i], n_components)
The factors of Y matrix to approximate Y. The first component, Y_factors[0], directs to the maximal covariance with X_factors[0]
- coef_ndarray of shape (n_component, n_component)
The coefficients of the linear model such that Y_factors[0] is approximated as Y_factors[0] = X_factors[0] @ coef_.
- Returns:
- self
- fit_transform(X, Y)[source]
Learn and apply the dimension reduction on the train data.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
- yarray-like of shape (n_samples, n_targets), default=None
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
- Returns:
- selfndarray of shape (n_samples, n_components)
Return x_scores if Y is not given, (x_scores, y_scores) otherwise.
- get_params(**kwargs)[source]
Returns a dictionary of parameters
- predict(X)[source]
Returns the predicted labels for a new data tensor
- Parameters:
- Xndarray
tensor data of shape (n_samples, N1, …, NS)
- score(X, Y)[source]
Calculate the R^2 of prediction on X compared to the ground truth Y provided.
- Parameters:
- Xndarray
tensor data of shape (n_samples, N1, …, NS), same dimension as the X in self.fit() all except the first dimension
- Y2D-array of shape (n_samples, n_predictions)
the ground truth labels associated with each sample
- set_params(**parameters)[source]
Sets the value of the provided parameters
- transform(X, Y=None)[source]
Apply the dimension reduction from fitting to a new tensor.
- Parameters:
- Xarray-like of shape (n_samples, n_features)
Samples to transform.
- Yarray-like of shape (n_samples, n_targets), default=None
Target vectors.
- Returns:
- X_scores, Y_scoresarray-like or tuple of array-like
Return X_scores if Y is not given, (X_scores, Y_scores) otherwise.