mprod.MeanDeviationForm¶
- class mprod.MeanDeviationForm[source]¶
Standardize the data by subtracting the mean (or empiric mean) sample The mean deviation form of a tensor \(X \in \mathbb{R}^{m \times p \times n}\) is calculated as:
Z = X - U
where U is the mean sample of X , calculated as follows:
\[U = \frac{1}{m} \sum_{i=1}^{m} X[i,:,:]\]and for the empiric mean deviation form:
\[U = \frac{1}{m-1} \sum_{i=1}^{m} X[i,:,:]\]- Attributes
- _mean_samplendarray of shape (p_features, n_repeats), or None
The mean sample of the dataset
Methods
fit:
Fits a MeanDeviationForm transformer by computing the mean sample of a training dataset
transform:
Shift dataset by fitted sample mean
fit_transform:
Compute the mean sample of a dataset and transform it to its mean deviation form
inverse_transform:
Add precomputed mean sample to a dataset
- fit(X, y=None, **fit_param)[source]¶
Compute the mean (or empiric mean) sample of a tensor
- Parameters
- X{array-like} of shape (m_samples, p_features, n_repeats)
The data used to compute the mean sample used for later cantering along the features-repeats axes.
- yNone
Ignored.
- Returns
- selfobject
Fitted MeanDeviationForm object
Examples
>>> from mprod import MeanDeviationForm >>> import numpy as np >>> X = np.random.randn(10,20,4) >>> mdf = MeanDeviationForm() >>> mdf = mdf.fit(X)
- fit_transform(X, y=None, **fit_params)[source]¶
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
- Parameters
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters.
- Returns
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- inverse_transform(Y)[source]¶
Undo the centering of X according to mean sample.
- Parameters
- Xarray-like of shape (m_samples, p_features, n_repeats)
Input data that will be transformed.
- Returns
- Xtndarray of shape (m_samples, p_features, n_repeats)
Transformed data.
Examples
>>> from mprod import MeanDeviationForm >>> import numpy as np >>> X = np.random.randn(10,20,4) >>> mdf = MeanDeviationForm() >>> Xt = mdf.fit_transform(X) >>> mdf.inverse_transform(Xt) - X
- transform(X, y=None)[source]¶
Perform standardization by centering.
- Parameters
- Xarray-like of shape (k_samples, p_features, n_repeats)
The data used to center along the features-repeats axes.
- Returns
- X_trndarray of shape (k_samples, p_features, n_repeats)
Transformed tensor.
Examples
>>> from mprod import MeanDeviationForm >>> import numpy as np >>> X = np.random.randn(10,20,4) >>> y = np.random.randn(50,20,4) >>> mdf = MeanDeviationForm() >>> mdf_fit = mdf.fit(X) >>> yt = mdf.transform(yt)