SkewedChi2Sampler#

class sklearn.kernel_approximation.SkewedChi2Sampler(*, skewedness=1.0, n_components=100, random_state=None)[源代码]#

“偏斜卡方”核的近似特征图。

用户指南 中阅读更多内容。

参数:
skewednessfloat, default=1.0

核的“偏度”参数。需要进行交叉验证。

n_componentsint, default=100

每个原始特征的蒙特卡洛样本数量。等于计算出的特征空间的维度。

random_stateint, RandomState instance or None, default=None

用于控制拟合训练数据时随机权重和随机偏移生成的伪随机数生成器。传入一个整数以获得跨多个函数调用的可复现输出。请参阅 术语表

属性:
random_weights_ndarray of shape (n_features, n_components)

权重数组,从双曲正割分布中采样,将用于线性变换数据的对数。

random_offset_ndarray of shape (n_features, n_components)

偏差项,将添加到数据中。它在 0 和 2*pi 之间均匀分布。

n_features_in_int

拟合 期间看到的特征数。

0.24 版本新增。

feature_names_in_shape 为 (n_features_in_,) 的 ndarray

fit 期间看到的特征名称。仅当 X 具有全部为字符串的特征名称时才定义。

1.0 版本新增。

另请参阅

AdditiveChi2Sampler

加性卡方核的近似特征图。

Nystroem

使用训练数据的子集近似核图。

RBFSampler

使用随机傅里叶特征近似 RBF 核特征图。

SkewedChi2Sampler

“偏斜卡方”核的近似特征图。

sklearn.metrics.pairwise.chi2_kernel

精确的卡方核。

sklearn.metrics.pairwise.kernel_metrics

List of built-in kernels.

References

请参阅 Fuxin Li, Catalin Ionescu 和 Cristian Sminchisescu 的“Random Fourier Approximations for Skewed Multiplicative Histogram Kernels”。

示例

>>> from sklearn.kernel_approximation import SkewedChi2Sampler
>>> from sklearn.linear_model import SGDClassifier
>>> X = [[0, 0], [1, 1], [1, 0], [0, 1]]
>>> y = [0, 0, 1, 1]
>>> chi2_feature = SkewedChi2Sampler(skewedness=.01,
...                                  n_components=10,
...                                  random_state=0)
>>> X_features = chi2_feature.fit_transform(X, y)
>>> clf = SGDClassifier(max_iter=10, tol=1e-3)
>>> clf.fit(X_features, y)
SGDClassifier(max_iter=10)
>>> clf.score(X_features, y)
1.0
fit(X, y=None)[源代码]#

使用 X 拟合模型。

根据 n_features 对随机投影进行采样。

参数:
Xarray-like, shape (n_samples, n_features)

训练数据,其中 n_samples 是样本数,n_features 是特征数。

yarray-like, shape (n_samples,) or (n_samples, n_outputs), default=None

目标值(对于无监督转换,为 None)。

返回:
selfobject

返回实例本身。

fit_transform(X, y=None, **fit_params)[源代码]#

拟合数据,然后对其进行转换。

使用可选参数 fit_params 将转换器拟合到 Xy,并返回 X 的转换版本。

参数:
Xshape 为 (n_samples, n_features) 的 array-like

输入样本。

y形状为 (n_samples,) 或 (n_samples, n_outputs) 的类数组对象,默认=None

目标值(对于无监督转换,为 None)。

**fit_paramsdict

额外的拟合参数。仅当估计器在其 fit 方法中接受额外的参数时才传递。

返回:
X_newndarray array of shape (n_samples, n_features_new)

转换后的数组。

get_feature_names_out(input_features=None)[源代码]#

获取转换的输出特征名称。

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()[源代码]#

获取此对象的元数据路由。

请查阅 用户指南,了解路由机制如何工作。

返回:
routingMetadataRequest

封装路由信息的 MetadataRequest

get_params(deep=True)[源代码]#

获取此估计器的参数。

参数:
deepbool, default=True

如果为 True,将返回此估计器以及包含的子对象(如果它们是估计器)的参数。

返回:
paramsdict

参数名称映射到其值。

set_output(*, transform=None)[源代码]#

设置输出容器。

有关如何使用 API 的示例,请参阅引入 set_output API

参数:
transform{“default”, “pandas”, “polars”}, default=None

配置 transformfit_transform 的输出。

  • "default": 转换器的默认输出格式

  • "pandas": DataFrame 输出

  • "polars": Polars 输出

  • None: 转换配置保持不变

1.4 版本新增: 添加了 "polars" 选项。

返回:
selfestimator instance

估计器实例。

set_params(**params)[源代码]#

设置此估计器的参数。

此方法适用于简单的估计器以及嵌套对象(如 Pipeline)。后者具有 <component>__<parameter> 形式的参数,以便可以更新嵌套对象的每个组件。

参数:
**paramsdict

估计器参数。

返回:
selfestimator instance

估计器实例。

transform(X)[源代码]#

将近似特征映射应用于 X。

参数:
Xarray-like, shape (n_samples, n_features)

新数据,其中 n_samples 是样本数量,n_features 是特征数量。X 的所有值必须严格大于“-skewedness”。

返回:
X_newarray-like, shape (n_samples, n_components)

返回实例本身。