OPLS
Functionality for working with Orthogonal Partial Least Squares (OPLS) modeling.
- class friendly_mvda.models.opls_model.FittedOplsModel(model: OplsModel, model_id: int)
Bases:
object- property DmodX: DataFrame
Distance to the model in X space
- property DmodX_limit: DataFrame
get the critical limits of the score. Only works with evolution models.
- property Hotellings_T2: DataFrame
Hotelling’s T2 from the model
- property Q2: DataFrame
Cumulative predicted fraction of the variation of the Y-variables, according to cross-validation, get data for all components.
- property R2: DataFrame
Cumulative explained fraction of the variation, get data for all components.
- property RMSECV: DataFrame
Root Mean Square Error, computed from the selected cross-validation round.
- property RMSEE: DataFrame
Root Mean Square Error of the Estimation.
- property aligned_variable_values: DataFrame
Get the aligned variables from the model. only works with evolution models.
- property batch_limits: DataFrame
Get all limits with aligned batch length
- contributions(batch: str, time: float, contribution_type: ContributionType) ndarray[tuple[int, ...], dtype[Any]]
- property loadings: DataFrame
Loadings from the model
- property loadings_correlation_scaled: DataFrame
Loadings(correlation scaled) from the model
- property number_of_components: list[int]
Get the number of components used
- property observed_y: DataFrame
Observed values of Y-variables for observations in the model.
- classmethod open_model(path: str, model_id: int = 1) FittedOplsModel
Open an existing fitted model.
- predict(data: DataFrame) DataFrame
Use the model to get the prediction of the observation.
use the name of the variables to identify them.
Parameters
data : The observation to get the prediction of.
Returns
y_pred : The prediction of the observations.
RMSEP : The root mean square error of the predictions, require data to contains y data.
- property predicted_y: DataFrame
Predicted values of Y-variables for observations in the model.
- refit(predictive_components: int = -1, orthogonal_components: int = -1, orthogonal_y_components: int = -1) None
Refit the model with another number of components. The previous fitted model will not work anymore.
- save(path: str) None
Save the model.
parameters:
path: the path to the saved file.
- property score_limits: DataFrame
Get the critical limits of the score. Only works with evolution models.
- property scores: DataFrame
Scores from the model
- set_limit_confidence_level(confidence_level: float) None
Set the confidence level of the limits
- property variable_limits: DataFrame
Get the critical limits of the X variables. only works with evolution models.
- class friendly_mvda.models.opls_model.OplsModel(project: Project)
Bases:
object- change_missing_tolerance(tolerance: float) None
Change the tolerance for when data will be excluded because of missing value any variable of an observation with more missing values than the tolerance will be excluded.
Default is 50(%)
- change_scaling(scal_type: str, variable: str | None = None) None
Change the scaling of the model
- fit(predictive_components: int = -1, orthogonal_components: int = -1, orthogonal_y_components: int = -1) FittedOplsModel
Fit the model.
parameters:
predictive_components: the number of predictive components, -1 is auto fit
orthogonal_components: the number of orthogonal components, -1 is auto fit
orthogonal_y_component: the number of orthogonal y components, -1 is auto fit
returns:
FittedOplsModel: the fitted opls model.
example:
>>> from friendly_mvda.models.opls_model import OplsModel >>> model = OplsModel(project) >>> model.remove_variables(["pH"]) >>> model.remove_observation([46, 92]) >>> model.change_scaling("uv") >>> model.change_missing_tolerance(30) >>> fitted_model = model.fit(2, 1, 0)
here the model is modified before fitting by removing variable “pH”, removing observations 46 and 92, changing scaling to uv and changing missing tolerance to 30 %. Finally the model is fitted with 2 predictive components and 1 orthogonal component.
- classmethod open_model(path: str, model_id: int = 1) OplsModel
Open a existing model.
parameters:
path: the path to the saved file.
model_id: the index of the model. Can be used if the file contains multiple models.
- remove_batches(batches: list[str]) None
Remove batches from the model
- remove_observation(observations: list[int]) None
Remove observations from the model
- remove_variables(variables: list[str]) None
Remove variables from the model
- save(path: str) None
Save the model
parameters:
path: the path to the saved file.