inplace_column_scale#
- sklearn.utils.sparsefuncs.inplace_column_scale(X, scale)[源代码]#
CSC/CSR矩阵的就地列缩放。
假设形状为(n_samples,n_features),通过乘以调用者提供的特定比例来缩放数据矩阵的每个特征。
- 参数:
- X形状稀疏矩阵(n_samples,n_features)
使用特征方差进行规格化的矩阵。它应该是CSC或CSR格式。
- scale形状的nd数组(n_features,),dype ={np.float32,np.float64}
用于缩放的预先计算的特征值数组。
示例
>>> from sklearn.utils import sparsefuncs >>> from scipy import sparse >>> import numpy as np >>> indptr = np.array([0, 3, 4, 4, 4]) >>> indices = np.array([0, 1, 2, 2]) >>> data = np.array([8, 1, 2, 5]) >>> scale = np.array([2, 3, 2]) >>> csr = sparse.csr_matrix((data, indices, indptr)) >>> csr.todense() matrix([[8, 1, 2], [0, 0, 5], [0, 0, 0], [0, 0, 0]]) >>> sparsefuncs.inplace_column_scale(csr, scale) >>> csr.todense() matrix([[16, 3, 4], [ 0, 0, 10], [ 0, 0, 0], [ 0, 0, 0]])