PLSSVD#
- class sklearn.cross_decomposition.PLSSVD(n_components=2, *, scale=True, copy=True)[source]#
Partial Least Square SVD。
此转换器仅对交叉协方差矩阵
X'y执行 SVD。它能够同时投影训练数据X和目标y。训练数据X被投影到左奇异向量上,而目标被投影到右奇异向量上。在 用户指南 中阅读更多内容。
在版本 0.8 中添加。
- 参数:
- n_componentsint, default=2
要保留的组件数。应在
[1, min(n_samples, n_features, n_targets)]范围内。- scalebool, default=True
是否对
X和y进行缩放。- copy布尔值, 默认为 True
在应用中心化(以及可能的缩放)之前,是否复制
X和y。如果为False,则这些操作将就地执行,修改这两个数组。
- 属性:
- x_weights_ndarray of shape (n_features, n_components)
交叉协方差矩阵 SVD 的左奇异向量。用于在
transform中投影X。- y_weights_形状为 (n_targets, n_components) 的 ndarray
交叉协方差矩阵 SVD 的右奇异向量。用于在
transform中投影y。- n_features_in_int
在 拟合 期间看到的特征数。
- feature_names_in_shape 为 (
n_features_in_,) 的 ndarray 在 fit 期间看到的特征名称。仅当
X具有全部为字符串的特征名称时才定义。1.0 版本新增。
另请参阅
PLSCanonicalPartial Least Squares 转换器和回归器。
CCA典型相关分析。
示例
>>> import numpy as np >>> from sklearn.cross_decomposition import PLSSVD >>> X = np.array([[0., 0., 1.], ... [1., 0., 0.], ... [2., 2., 2.], ... [2., 5., 4.]]) >>> y = np.array([[0.1, -0.2], ... [0.9, 1.1], ... [6.2, 5.9], ... [11.9, 12.3]]) >>> pls = PLSSVD(n_components=2).fit(X, y) >>> X_c, y_c = pls.transform(X, y) >>> X_c.shape, y_c.shape ((4, 2), (4, 2))
- fit(X, y)[source]#
用数据拟合模型。
- 参数:
- Xshape 为 (n_samples, n_features) 的 array-like
训练样本。
- yshape 为 (n_samples,) 或 (n_samples, n_targets) 的 array-like
目标。
- 返回:
- selfobject
拟合的估计器。
- fit_transform(X, y=None)[source]#
学习并应用降维。
- 参数:
- Xshape 为 (n_samples, n_features) 的 array-like
训练样本。
- y形状为 (n_samples,) 或 (n_samples, n_targets) 的 array-like,默认为 None
目标。
- 返回:
- outarray-like 或 array-like 元组
如果
y is not None,则返回转换后的数据X_transformed;否则返回(X_transformed, y_transformed)。
- get_feature_names_out(input_features=None)[source]#
获取转换的输出特征名称。
The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are:
["class_name0", "class_name1", "class_name2"].- 参数:
- input_featuresarray-like of str or None, default=None
Only used to validate feature names with the names seen in
fit.
- 返回:
- feature_names_outstr 对象的 ndarray
转换后的特征名称。
- get_metadata_routing()[source]#
获取此对象的元数据路由。
请查阅 用户指南,了解路由机制如何工作。
- 返回:
- routingMetadataRequest
封装路由信息的
MetadataRequest。
- get_params(deep=True)[source]#
获取此估计器的参数。
- 参数:
- deepbool, default=True
如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- set_output(*, transform=None)[source]#
设置输出容器。
有关如何使用 API 的示例,请参阅引入 set_output API。
- 参数:
- transform{“default”, “pandas”, “polars”}, default=None
配置
transform和fit_transform的输出。"default": 转换器的默认输出格式"pandas": DataFrame 输出"polars": Polars 输出None: 转换配置保持不变
1.4 版本新增: 添加了
"polars"选项。
- 返回:
- selfestimator instance
估计器实例。