均值中心化:在NumPy数组上基于列的均值中心化
一个执行基于列的均值中心化的NumPy数组的变换器对象。
> from mlxtend.preprocessing import MeanCenterer
示例 1 - 翻转 NumPy 数组
使用 fit
方法将数据集(例如训练数据集)的列均值拟合到一个新的 MeanCenterer
对象。然后,在同一数据集上调用 transform
方法,以使其围绕样本均值进行中心化。
import numpy as np
from mlxtend.preprocessing import MeanCenterer
X_train = np.array(
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
mc = MeanCenterer().fit(X_train)
mc.transform(X_train)
array([[-3., -3., -3.],
[ 0., 0., 0.],
[ 3., 3., 3.]])
API
MeanCenterer()
Column centering of vectors and matrices.
Attributes
-
col_means
: numpy.ndarray [n_columns]NumPy array storing the mean values for centering after fitting the MeanCenterer object.
Examples
For usage examples, please see https://rasbt.github.io/mlxtend/user_guide/preprocessing/MeanCenterer/
Methods
fit(X)
Gets the column means for mean centering.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]Array of data vectors, where n_samples is the number of samples and n_features is the number of features.
Returns
self
fit_transform(X)
Fits and transforms an arry.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]Array of data vectors, where n_samples is the number of samples and n_features is the number of features.
Returns
-
X_tr
: {array-like, sparse matrix}, shape = [n_samples, n_features]A copy of the input array with the columns centered.
transform(X)
Centers a NumPy array.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]Array of data vectors, where n_samples is the number of samples and n_features is the number of features.
Returns
-
X_tr
: {array-like, sparse matrix}, shape = [n_samples, n_features]A copy of the input array with the columns centered.
ython