mlxtend version: 0.23.1
Adaline
Adaline(eta=0.01, epochs=50, minibatches=None, random_seed=None, print_progress=0)
自适应线性神经元分类器.
请注意,此实现的自适应线性神经元分类器期望二元类别标签 {0, 1}.
Parameters
-
eta
: float (默认: 0.01)学习率 (介于 0.0 和 1.0 之间)
-
epochs
: int (默认: 50)训练数据集的遍历次数. 在每次遍历之前,如果
minibatches > 1
,数据集会被打乱以防止随机梯度下降中的循环. -
minibatches
: int (默认: None)基于梯度优化的最小批次数量. 如果为 None: 正规方程 (闭式解) 如果为 1: 梯度下降学习 如果为 len(y): 随机梯度下降 (SGD) 在线学习 如果 1 < minibatches < len(y): SGD 小批次学习
-
random_seed
: int (默认: None)设置随机状态以打乱数据和初始化权重.
-
print_progress
: int (默认: 0)如果 solver 不是 'normal equation',则打印进度到 stderr 0: 无输出 1: 已用轮数和成本 2: 1 加上已用时间 3: 2 加上预计完成时间
Attributes
-
w_
: 2d-array, shape={n_features, 1}拟合后的模型权重.
-
b_
: 1d-array, shape={1,}拟合后的偏置单元.
-
cost_
: list每次遍历后的平方误差和.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/Adaline/
Methods
fit(X, y, init_params=True)
学习训练数据中的模型.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
init_params
: bool (默认: True)在拟合之前重新初始化模型参数. 设置为 False 以继续使用先前模型拟合的权重进行训练.
Returns
self
: object
get_params(deep=True)
获取此估计器的参数.
Parameters
-
deep
: boolean, 可选如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数.
Returns
-
params
: 字符串到任意类型的映射参数名称映射到其值.
改编自 https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py 作者: Gael Varoquaux gael.varoquaux@normalesup.org 许可证: BSD 3 条款
predict(X)
预测目标值.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
-
target_values
: array-like, shape = [n_samples]预测的目标值.
score(X, y)
计算预测准确率
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量, n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值(真实类别标签).
Returns
-
acc
: float预测准确率,以 0.0 到 1.0(完美分数)之间的浮点数表示.
set_params(params)
设置此估计器的参数.
该方法适用于简单估计器以及嵌套对象(如管道).
后者具有形式为<组件>__<参数>
的参数,以便可以更新嵌套对象的每个组件.
Returns
self
改编自
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py
作者: Gael Varoquaux <gael.varoquaux@normalesup.org>
许可证: BSD 3条款
EnsembleVoteClassifier
EnsembleVoteClassifier(clfs, voting='hard', weights=None, verbose=0, use_clones=True, fit_base_estimators=True)
软投票/多数规则分类器,适用于scikit-learn估计器.
Parameters
-
clfs
: array-like, shape = [n_classifiers]分类器列表. 调用
VotingClassifier
的fit
方法将拟合这些原始分类器的克隆版本, 如果use_clones=True
(默认)且fit_base_estimators=True
(默认), 这些克隆版本将被存储在类属性中. -
voting
: str, {'hard', 'soft'} (default='hard')如果为'hard',使用预测的类别标签进行多数规则投票. 否则如果为'soft',根据预测概率之和的argmax来预测类别标签, 这推荐用于一组校准良好的分类器.
-
weights
: array-like, shape = [n_classifiers], optional (default=None
)权重序列(
float
或int
),用于加权预测类别标签的出现次数('hard'投票) 或加权平均前的类别概率('soft'投票).如果为None
,则使用均匀权重. -
verbose
: int, optional (default=0)控制构建过程的详细程度. -
verbose=0
(默认):不打印任何内容 -verbose=1
:打印正在拟合的分类器的数量和名称 -verbose=2
:打印正在拟合的分类器的参数信息 -verbose>2
:将底层分类器的verbose
参数设置为self.verbose - 2
-
use_clones
: bool (default: True)如果为True(默认),则为堆叠分类克隆分类器; 否则使用原始分类器,这些分类器将在调用
fit
方法时在数据集上重新拟合. 因此,如果use_clones=True
,在使用StackingClassifier
的fit
方法时, 原始输入分类器将保持未修改状态. 如果你使用的是支持scikit-learn fit/predict API接口但不兼容scikit-learn的clone
函数的估计器, 建议设置use_clones=False
. -
fit_base_estimators
: bool (default: True)如果为True,则重新拟合
clfs
中的分类器;否则使用对clfs
的引用(假设分类器已经拟合). 注意:fit_base_estimators=False
将强制use_clones
为False, 并且与大多数scikit-learn包装器不兼容! 例如,如果执行任何形式的交叉验证,这将需要对训练折叠重新拟合分类器, 如果fit_base_estimators=False
,则会引发NotFitterError. (在mlxtend v0.6中新增.)
Attributes
-
classes_
: array-like, shape = [n_predictions] -
clf
: array-like, shape = [n_predictions]输入分类器;如果
use_clones=False
,可能会被覆盖 -
clf_
: array-like, shape = [n_predictions]拟合的输入分类器;如果
use_clones=True
,则为克隆版本
Examples
```
>>> import numpy as np
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.naive_bayes import GaussianNB
>>> from sklearn.ensemble import RandomForestClassifier
>>> from mlxtend.sklearn import EnsembleVoteClassifier
>>> clf1 = LogisticRegression(random_seed=1)
>>> clf2 = RandomForestClassifier(random_seed=1)
>>> clf3 = GaussianNB()
>>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
>>> y = np.array([1, 1, 1, 2, 2, 2])
>>> eclf1 = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3],
... voting='hard', verbose=1)
>>> eclf1 = eclf1.fit(X, y)
>>> print(eclf1.predict(X))
[1 1 1 2 2 2]
>>> eclf2 = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3], voting='soft')
>>> eclf2 = eclf2.fit(X, y)
>>> print(eclf2.predict(X))
[1 1 1 2 2 2]
>>> eclf3 = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3],
... voting='soft', weights=[2,1,1])
>>> eclf3 = eclf3.fit(X, y)
>>> print(eclf3.predict(X))
[1 1 1 2 2 2]
>>>
更多使用示例,请参见
https://rasbt.github.io/mlxtend/user_guide/classifier/EnsembleVoteClassifier/
```
Methods
fit(X, y, sample_weight=None)
学习每个分类器的训练数据权重系数.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
sample_weight
: array-like, shape = [n_samples], 可选作为 sample_weights 传递给回归器列表中的每个回归器以及 meta_regressor 的样本权重. 如果某些回归器在 fit() 方法中不支持 sample_weight,则会引发错误.
Returns
self
: object
fit_transform(X, y=None, fit_params)
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
-
X
: array-like of shape (n_samples, n_features)Input samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs), default=NoneTarget values (None for unsupervised transformations).
-
**fit_params
: dictAdditional fit parameters.
Returns
-
X_new
: ndarray array of shape (n_samples, n_features_new)Transformed array.
get_metadata_routing()
Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
Returns
-
routing
: MetadataRequestA :class:
~sklearn.utils.metadata_routing.MetadataRequest
encapsulating routing information.
get_params(deep=True)
返回用于支持 GridSearch 的估计器参数名称.
predict(X)
预测X的类别标签.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
maj
: array-like, shape = [n_samples]预测的类别标签.
predict_proba(X)
预测X的类别概率.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
avg
: array-like, shape = [n_samples, n_classes]每个样本在每个类别上的加权平均概率.
score(X, y, sample_weight=None)
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
-
X
: array-like of shape (n_samples, n_features)Test samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs)True labels for
X
. -
sample_weight
: array-like of shape (n_samples,), default=NoneSample weights.
Returns
-
score
: floatMean accuracy of
self.predict(X)
w.r.t.y
.
set_fit_request(self: mlxtend.classifier.ensemble_vote.EnsembleVoteClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.ensemble_vote.EnsembleVoteClassifier*
Request metadata passed to the fit
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``fit`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``fit``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter infit
.
Returns
-
self
: objectThe updated object.
set_output(, transform=None)*
Set output container.
See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
for an example on how to use the API.
Parameters
-
transform
: {"default", "pandas", "polars"}, default=NoneConfigure output of
transform
andfit_transform
."default"
: Default output format of a transformer"pandas"
: DataFrame output"polars"
: Polars outputNone
: Transform configuration is unchanged
.. versionadded:: 1.4
"polars"
option was added.
Returns
-
self
: estimator instanceEstimator instance.
set_params(params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as :class:`~sklearn.pipeline.Pipeline`). The latter have
parameters of the form ``<component>__<parameter>`` so that it's
possible to update each component of a nested object.
Parameters
-
**params
: dictEstimator parameters.
Returns
-
self
: estimator instanceEstimator instance.
set_score_request(self: mlxtend.classifier.ensemble_vote.EnsembleVoteClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.ensemble_vote.EnsembleVoteClassifier*
Request metadata passed to the score
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``score`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``score``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter inscore
.
Returns
-
self
: objectThe updated object.
transform(X)
返回每个估计器对X的类别标签或概率.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
如果
voting='soft'`` : array-like = [n_classifiers, n_samples, n_classes]每个分类器计算的类别概率.
-
如果
voting='hard'`` : array-like = [n_classifiers, n_samples]每个分类器预测的类别标签.
LogisticRegression
LogisticRegression(eta=0.01, epochs=50, l2_lambda=0.0, minibatches=1, random_seed=None, print_progress=0)
逻辑回归分类器.
请注意,此逻辑回归实现期望二元类别标签为 {0, 1}.
Parameters
-
eta
: float (默认: 0.01)学习率(介于 0.0 和 1.0 之间)
-
epochs
: int (默认: 50)训练数据集上的遍历次数. 在每次遍历之前,如果
minibatches > 1
,数据集会被打乱以防止随机梯度下降中的循环. -
l2_lambda
: floatL2 正则化的正则化参数. 如果 l2_lambda=0.0,则不进行正则化.
-
minibatches
: int (默认: 1)基于梯度优化的最小批次数量. 如果为 1:梯度下降学习 如果为 len(y):随机梯度下降(SGD)在线学习 如果 1 < minibatches < len(y):SGD 小批次学习
-
random_seed
: int (默认: None)设置随机状态以打乱数据和初始化权重.
-
print_progress
: int (默认: 0)打印拟合进度到标准错误输出. 0: 无输出 1: 已用轮数和成本 2: 1 加上已用时间 3: 2 加上预计完成时间
Attributes
-
w_
: 2d-array, shape={n_features, 1}拟合后的模型权重.
-
b_
: 1d-array, shape={1,}拟合后的偏置单元.
-
cost_
: list包含每个轮次的交叉熵成本(sgd 或 gd)的浮点数列表.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/LogisticRegression/
Methods
fit(X, y, init_params=True)
学习训练数据中的模型.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
init_params
: bool (默认: True)在拟合之前重新初始化模型参数. 设置为 False 以继续使用先前模型拟合的权重进行训练.
Returns
self
: object
get_params(deep=True)
获取此估计器的参数.
Parameters
-
deep
: boolean, 可选如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数.
Returns
-
params
: 字符串到任意类型的映射参数名称映射到其值.
改编自 https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py 作者: Gael Varoquaux gael.varoquaux@normalesup.org 许可证: BSD 3 条款
predict(X)
预测目标值.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
-
target_values
: array-like, shape = [n_samples]预测的目标值.
predict_proba(X)
Predict class probabilities of X from the net input.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
Class 1 probability
: float
score(X, y)
计算预测准确率
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量, n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值(真实类别标签).
Returns
-
acc
: float预测准确率,以 0.0 到 1.0(完美分数)之间的浮点数表示.
set_params(params)
设置此估计器的参数.
该方法适用于简单估计器以及嵌套对象(如管道).
后者具有形式为<组件>__<参数>
的参数,以便可以更新嵌套对象的每个组件.
Returns
self
改编自
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py
作者: Gael Varoquaux <gael.varoquaux@normalesup.org>
许可证: BSD 3条款
MultiLayerPerceptron
MultiLayerPerceptron(eta=0.5, epochs=50, hidden_layers=[50], n_classes=None, momentum=0.0, l1=0.0, l2=0.0, dropout=1.0, decrease_const=0.0, minibatches=1, random_seed=None, print_progress=0)
多层感知器分类器,采用逻辑S形激活函数
Parameters
-
eta
: float (默认: 0.5)学习率(介于0.0和1.0之间)
-
epochs
: int (默认: 50)训练数据集的遍历次数. 在每次遍历之前,如果
minibatches > 1
,数据集会被打乱 以防止随机梯度下降中的循环. -
hidden_layers
: list (默认: [50])每个隐藏层的单元数.默认情况下,第一个隐藏层有50个单元. 目前仅支持1个隐藏层.
-
n_classes
: int (默认: None)如果部分训练集中未包含所有类别标签,则声明类别标签数量的正整数. 如果为None,则自动获取类别标签数量.
-
l1
: float (默认: 0.0)L1正则化强度
-
l2
: float (默认: 0.0)L2正则化强度
-
momentum
: float (默认: 0.0)动量常数.乘以前一时期t-1的梯度的因子,以提高 学习速度 w(t) := w(t) - (grad(t) + momentum * grad(t-1))
-
decrease_const
: float (默认: 0.0)减少常数.通过eta / (1 + epoch*decrease_const)在每次遍历后缩小学习率
-
minibatches
: int (默认: 1)将训练数据分成k个最小批次, 以加速随机梯度下降学习. 如果
minibatches
= 1,则为梯度下降学习 如果minibatches
= len(y),则为随机梯度下降学习 如果minibatches
> 1,则为小批次学习 -
random_seed
: int (默认: None)设置随机状态以进行打乱和初始化权重.
-
print_progress
: int (默认: 0)将进度打印到stderr. 0: 无输出 1: 已用遍历次数和成本 2: 1加上已用时间 3: 2加上估计的完成时间
Attributes
-
w_
: 2d-array, shape=[n_features, n_classes]拟合后的权重.
-
b_
: 1D-array, shape=[n_classes]拟合后的偏置单元.
-
cost_
: list浮点数列表;每次遍历后的平均分类交叉熵成本.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/MultiLayerPerceptron/
Methods
fit(X, y, init_params=True)
学习训练数据中的模型.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
init_params
: bool (默认: True)在拟合之前重新初始化模型参数. 设置为 False 以继续使用先前模型拟合的权重进行训练.
Returns
self
: object
get_params(deep=True)
获取此估计器的参数.
Parameters
-
deep
: boolean, 可选如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数.
Returns
-
params
: 字符串到任意类型的映射参数名称映射到其值.
改编自 https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py 作者: Gael Varoquaux gael.varoquaux@normalesup.org 许可证: BSD 3 条款
predict(X)
预测目标值.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
-
target_values
: array-like, shape = [n_samples]预测的目标值.
predict_proba(X)
Predict class probabilities of X from the net input.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
Class probabilties
: array-like, shape= [n_samples, n_classes]
score(X, y)
计算预测准确率
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量, n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值(真实类别标签).
Returns
-
acc
: float预测准确率,以 0.0 到 1.0(完美分数)之间的浮点数表示.
set_params(params)
设置此估计器的参数.
该方法适用于简单估计器以及嵌套对象(如管道).
后者具有形式为<组件>__<参数>
的参数,以便可以更新嵌套对象的每个组件.
Returns
self
改编自
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py
作者: Gael Varoquaux <gael.varoquaux@normalesup.org>
许可证: BSD 3条款
OneRClassifier
OneRClassifier(resolve_ties='first')
OneR(一规则)分类器.
Parameters
-
resolve_ties
: str (默认: 'first')用于解决两个或多个特征具有相同误差时的选项.选项包括: - 'first'(默认):选择列表中的第一个特征,即具有较低列索引的特征. - 'chi-squared':对每个特征与目标进行卡方检验,并选择具有最低p值的特征.
Attributes
-
self.classes_labels_
: array-like, shape = [n_labels]包含在训练集中找到的唯一类标签的数组.
-
self.feature_idx_
: int基于训练集中的列的规则特征的索引.
-
self.p_value_
: float给定特征的p值.仅在设置OneR属性
resolve_ties = 'chi-squared'
并调用fit
后可用. -
self.prediction_dict_
: dict包含有关特征(self.feature_idx_)的规则和总误差信息的字典.例如,
{'total error': 37, 'rules (value: class)': {0: 0, 1: 2}}
表示总误差为37,规则为 "如果特征值 == 0 分类为 0" 和 "如果特征值 == 1 分类为 2". (否则分类为类1.)使用示例请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/OneRClassifier/
Methods
fit(X, y)
学习训练数据中的规则.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
Returns
self
: object
get_metadata_routing()
Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
Returns
-
routing
: MetadataRequestA :class:
~sklearn.utils.metadata_routing.MetadataRequest
encapsulating routing information.
get_params(deep=True)
Get parameters for this estimator.
Parameters
-
deep
: bool, default=TrueIf True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns
-
params
: dictParameter names mapped to their values.
predict(X)
预测X的类别标签.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
maj
: array-like, shape = [n_samples]预测的类别标签.
score(X, y, sample_weight=None)
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
-
X
: array-like of shape (n_samples, n_features)Test samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs)True labels for
X
. -
sample_weight
: array-like of shape (n_samples,), default=NoneSample weights.
Returns
-
score
: floatMean accuracy of
self.predict(X)
w.r.t.y
.
set_params(params)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects
(such as :class:`~sklearn.pipeline.Pipeline`). The latter have
parameters of the form ``<component>__<parameter>`` so that it's
possible to update each component of a nested object.
Parameters
-
**params
: dictEstimator parameters.
Returns
-
self
: estimator instanceEstimator instance.
set_score_request(self: mlxtend.classifier.oner.OneRClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.oner.OneRClassifier*
Request metadata passed to the score
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``score`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``score``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter inscore
.
Returns
-
self
: objectThe updated object.
Perceptron
Perceptron(eta=0.1, epochs=50, random_seed=None, print_progress=0)
感知器分类器.
请注意,此感知器的实现期望二元类别标签为 {0, 1}.
Parameters
-
eta
: float (默认: 0.1)学习率(介于 0.0 和 1.0 之间)
-
epochs
: int (默认: 50)对训练数据集的遍历次数. 在每次遍历之前,数据集会被打乱以防止循环.
-
random_seed
: int用于初始化随机权重和打乱的随机状态.
-
print_progress
: int (默认: 0)将进度打印到标准错误输出. 0: 无输出 1: 已用轮数和成本 2: 1 加上已用时间 3: 2 加上预计完成时间
Attributes
-
w_
: 二维数组, shape={n_features, 1}拟合后的模型权重.
-
b_
: 一维数组, shape={1,}拟合后的偏置单元.
-
cost_
: 列表每个轮次中的错误分类数量.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/Perceptron/
Methods
fit(X, y, init_params=True)
学习训练数据中的模型.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
init_params
: bool (默认: True)在拟合之前重新初始化模型参数. 设置为 False 以继续使用先前模型拟合的权重进行训练.
Returns
self
: object
get_params(deep=True)
获取此估计器的参数.
Parameters
-
deep
: boolean, 可选如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数.
Returns
-
params
: 字符串到任意类型的映射参数名称映射到其值.
改编自 https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py 作者: Gael Varoquaux gael.varoquaux@normalesup.org 许可证: BSD 3 条款
predict(X)
预测目标值.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
-
target_values
: array-like, shape = [n_samples]预测的目标值.
score(X, y)
计算预测准确率
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量, n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值(真实类别标签).
Returns
-
acc
: float预测准确率,以 0.0 到 1.0(完美分数)之间的浮点数表示.
set_params(params)
设置此估计器的参数.
该方法适用于简单估计器以及嵌套对象(如管道).
后者具有形式为<组件>__<参数>
的参数,以便可以更新嵌套对象的每个组件.
Returns
self
改编自
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py
作者: Gael Varoquaux <gael.varoquaux@normalesup.org>
许可证: BSD 3条款
SoftmaxRegression
SoftmaxRegression(eta=0.01, epochs=50, l2=0.0, minibatches=1, n_classes=None, random_seed=None, print_progress=0)
软性最大回归分类器.
Parameters
-
eta
: float (默认: 0.01)学习率(介于0.0和1.0之间)
-
epochs
: int (默认: 50)训练数据集的遍历次数. 在每次遍历之前,如果
minibatches > 1
,数据集会被打乱 以防止随机梯度下降中的循环. -
l2
: floatL2正则化的正则化参数. 如果l2=0.0,则不进行正则化.
-
minibatches
: int (默认: 1)用于基于梯度优化的最小批次数量. 如果为1:梯度下降学习 如果为len(y):随机梯度下降(SGD)在线学习 如果1 < minibatches < len(y):SGD小批次学习
-
n_classes
: int (默认: None)一个正整数,用于声明类标签的数量 如果在部分训练集中没有所有类标签. 如果为None,则自动获取类标签的数量.
-
random_seed
: int (默认: None)设置随机状态以进行打乱和初始化权重.
-
print_progress
: int (默认: 0)打印进度到标准错误. 0: 无输出 1: 已用轮次和成本 2: 1加上已用时间 3: 2加上估计的完成时间
Attributes
-
w_
: 2d-array, shape={n_features, 1}拟合后的模型权重.
-
b_
: 1d-array, shape={1,}拟合后的偏置单元.
-
cost_
: list浮点数列表,每个轮次的平均交叉熵.
Examples
使用示例请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/SoftmaxRegression/
Methods
fit(X, y, init_params=True)
学习训练数据中的模型.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值.
-
init_params
: bool (默认: True)在拟合之前重新初始化模型参数. 设置为 False 以继续使用先前模型拟合的权重进行训练.
Returns
self
: object
get_params(deep=True)
获取此估计器的参数.
Parameters
-
deep
: boolean, 可选如果为 True,将返回此估计器及其包含的作为估计器的子对象的参数.
Returns
-
params
: 字符串到任意类型的映射参数名称映射到其值.
改编自 https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py 作者: Gael Varoquaux gael.varoquaux@normalesup.org 许可证: BSD 3 条款
predict(X)
预测目标值.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
Returns
-
target_values
: array-like, shape = [n_samples]预测的目标值.
predict_proba(X)
Predict class probabilities of X from the net input.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
Class probabilties
: array-like, shape= [n_samples, n_classes]
score(X, y)
计算预测准确率
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量, n_features 是特征数量.
-
y
: array-like, shape = [n_samples]目标值(真实类别标签).
Returns
-
acc
: float预测准确率,以 0.0 到 1.0(完美分数)之间的浮点数表示.
set_params(params)
设置此估计器的参数.
该方法适用于简单估计器以及嵌套对象(如管道).
后者具有形式为<组件>__<参数>
的参数,以便可以更新嵌套对象的每个组件.
Returns
self
改编自
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/base.py
作者: Gael Varoquaux <gael.varoquaux@normalesup.org>
许可证: BSD 3条款
StackingCVClassifier
StackingCVClassifier(classifiers, meta_classifier, use_probas=False, drop_proba_col=None, cv=2, shuffle=True, random_state=None, stratify=True, verbose=0, use_features_in_secondary=False, store_train_meta_features=False, use_clones=True, n_jobs=None, pre_dispatch='2n_jobs')*
scikit-learn 估计器的"堆叠交叉验证”分类器.
在 mlxtend v0.4.3 中新增
Parameters
-
classifiers
: 类似数组, shape = [n_classifiers]分类器列表. 调用
StackingCVClassifier
的fit
方法将拟合这些原始分类器的克隆版本, 如果use_clones=True
,这些克隆版本将存储在类属性self.clfs_
中. -
meta_classifier
: 对象用于拟合分类器集合的元分类器
-
use_probas
: 布尔值 (默认: False)如果为 True,则基于预测概率而非类别标签训练元分类器.
-
drop_proba_col
: 字符串 (默认: None)删除特征集中的额外"概率”列,因为它是冗余的: p(y_c) = 1 - p(y_1) + p(y_2) + ... + p(y_{c-1}). 这对于对完全共线特征敏感的元分类器可能很有用. 如果为 'last',则删除最后一列概率. 如果为 'first',则删除第一列概率. 仅在
use_probas=True
时相关. -
cv
: 整数, 交叉验证生成器或可迭代对象, 可选 (默认: 2)确定交叉验证分割策略. cv 的可能输入包括: - None,使用默认的 2 折交叉验证, - 整数,指定
(Stratified)KFold
中的折数, - 用作交叉验证生成器的对象. - 产生训练、测试分割的可迭代对象. 对于整数/None 输入,将根据stratify
参数的值使用KFold
或StratifiedKFold
交叉验证. -
shuffle
: 布尔值 (默认: True)如果为 True,并且
cv
参数为整数,则在交叉验证之前对训练数据进行洗牌.如果cv
参数是特定的交叉验证技术,则忽略此参数. -
random_state
: 整数, RandomState 实例或 None, 可选 (默认: None)控制 cv 分割器的随机性.当
cv
为整数且shuffle=True
时使用.在 v0.16.0 中新增. -
stratify
: 布尔值 (默认: True)如果为 True,并且
cv
参数为整数,则将使用分层 K 折交叉验证技术.如果cv
参数是特定的交叉验证技术,则忽略此参数. -
verbose
: 整数, 可选 (默认=0)控制构建过程的详细程度. -
verbose=0
(默认): 不打印任何内容 -verbose=1
: 打印正在拟合的回归器的数量和名称,以及当前用于拟合的折数 -verbose=2
: 打印正在拟合的回归器的参数信息 -verbose>2
: 将底层回归器的verbose
参数更改为 self.verbose - 2 -
use_features_in_secondary
: 布尔值 (默认: False)如果为 True,元分类器将同时基于原始分类器的预测和原始数据集进行训练. 如果为 False,元分类器将仅基于原始分类器的预测进行训练.
-
store_train_meta_features
: 布尔值 (默认: False)如果为 True,用于拟合元分类器的训练数据计算的元特征将存储在
self.train_meta_features_
数组中, 该数组可以在调用fit
后访问. -
use_clones
: 布尔值 (默认: True)如果为 True(默认),则为堆叠分类克隆分类器,否则使用原始分类器, 这些分类器将在调用
fit
方法时在数据集上重新拟合.因此,如果 use_clones=True, 在使用 StackingCVClassifier 的fit
方法时,原始输入分类器将保持未修改状态. 如果使用支持 scikit-learn fit/predict API 接口但不兼容 scikit-learn 的clone
函数的估计器, 建议设置use_clones=False
. -
n_jobs
: 整数或 None, 可选 (默认=None)用于计算的 CPU 数量.
None
表示 1,除非在joblib.parallel_backend
上下文中.-1
表示使用所有处理器. 更多详情请参阅.在 v0.16.0 中新增. -
pre_dispatch
: 整数或字符串, 可选控制并行执行期间分派的作业数量.减少此数量对于避免在分派的作业多于 CPU 可以处理时 内存消耗爆炸可能很有用.此参数可以是: - None,在这种情况下,所有作业都会立即创建并派生.对于轻量级和快速运行的作业, 使用此选项以避免由于按需派生作业而导致的延迟 - 一个整数,给出派生的总作业的确切数量 - 一个字符串,给出作为 n_jobs 函数的表达式,如 '2*n_jobs' 在 v0.16.0 中新增.
Attributes
-
clfs_
: 列表, shape=[n_classifiers]拟合的分类器(原始分类器的克隆版本)
-
meta_clf_
: 估计器拟合的元分类器(原始元估计器的克隆版本)
-
train_meta_features
: numpy 数组, shape = [n_samples, n_classifiers]训练数据的元特征,其中 n_samples 是训练数据中的样本数量, n_classifiers 是分类器数量.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/StackingCVClassifier/
Methods
decision_function(X)
预测X的类别置信度得分.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
scores
: 如果n_classes == 2,shape=(n_samples,),否则shape=(n_samples, n_classes).每个(样本, 类别)组合的置信度得分.在二分类情况下,self.classes_[1]的置信度得分,其中>0表示将预测该类别.
fit(X, y, groups=None, sample_weight=None)
拟合集成分类器和元分类器.
Parameters
-
X
: numpy数组, shape = [n_samples, n_features]训练向量, 其中n_samples是样本数量, n_features是特征数量.
-
y
: numpy数组, shape = [n_samples]目标值.
-
groups
: numpy数组/None, shape = [n_samples]每个样本所属的组.某些特定的分组策略(如GroupKFold())会使用此参数.
-
sample_weight
: 类数组, shape = [n_samples], 可选作为sample_weights传递给回归器列表中的每个回归器以及meta_regressor的样本权重. 如果某些回归器在fit()方法中不支持sample_weight,则会引发错误.
Returns
self
: 对象
fit_transform(X, y=None, fit_params)
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
-
X
: array-like of shape (n_samples, n_features)Input samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs), default=NoneTarget values (None for unsupervised transformations).
-
**fit_params
: dictAdditional fit parameters.
Returns
-
X_new
: ndarray array of shape (n_samples, n_features_new)Transformed array.
get_metadata_routing()
Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
Returns
-
routing
: MetadataRequestA :class:
~sklearn.utils.metadata_routing.MetadataRequest
encapsulating routing information.
get_params(deep=True)
返回用于网格搜索支持的估计器参数名称.
predict(X)
预测目标值.
Parameters
-
X
: numpy数组, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
labels
: 类数组, shape = [n_samples]预测的类别标签.
predict_meta_features(X)
获取测试数据的元特征.
Parameters
-
X
: numpy数组, shape = [n_samples, n_features]测试向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
meta-features
: numpy数组, shape = [n_samples, n_classifiers]返回测试数据的元特征.
predict_proba(X)
预测X的类别概率.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
proba
: array-like, shape = [n_samples, n_classes] 或一个包含n_outputs个此类数组的列表(如果n_outputs > 1).每个样本的每个类别的概率.
score(X, y, sample_weight=None)
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
-
X
: array-like of shape (n_samples, n_features)Test samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs)True labels for
X
. -
sample_weight
: array-like of shape (n_samples,), default=NoneSample weights.
Returns
-
score
: floatMean accuracy of
self.predict(X)
w.r.t.y
.
set_fit_request(self: mlxtend.classifier.stacking_cv_classification.StackingCVClassifier, , groups: Union[bool, NoneType, str] = '$UNCHANGED$', sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.stacking_cv_classification.StackingCVClassifier*
Request metadata passed to the fit
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``fit`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``fit``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
groups
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
groups
parameter infit
. -
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter infit
.
Returns
-
self
: objectThe updated object.
set_output(, transform=None)*
Set output container.
See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
for an example on how to use the API.
Parameters
-
transform
: {"default", "pandas", "polars"}, default=NoneConfigure output of
transform
andfit_transform
."default"
: Default output format of a transformer"pandas"
: DataFrame output"polars"
: Polars outputNone
: Transform configuration is unchanged
.. versionadded:: 1.4
"polars"
option was added.
Returns
-
self
: estimator instanceEstimator instance.
set_params(params)
设置此估计器的参数.
有效的参数键可以通过 ``get_params()`` 列出.
Returns
self
set_score_request(self: mlxtend.classifier.stacking_cv_classification.StackingCVClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.stacking_cv_classification.StackingCVClassifier*
Request metadata passed to the score
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``score`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``score``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter inscore
.
Returns
-
self
: objectThe updated object.
Properties
named_classifiers
None
StackingClassifier
StackingClassifier(classifiers, meta_classifier, use_probas=False, drop_proba_col=None, average_probas=False, verbose=0, use_features_in_secondary=False, store_train_meta_features=False, use_clones=True, fit_base_estimators=True)
一个用于分类的scikit-learn估计器的堆叠分类器.
Parameters
-
classifiers
: array-like, shape = [n_classifiers]分类器列表. 调用
StackingClassifier
的fit
方法将拟合这些原始分类器的克隆版本, 如果use_clones=True
(默认)且fit_base_estimators=True
(默认), 这些克隆版本将存储在类属性self.clfs_
中. -
meta_classifier
: object用于拟合分类器集合的元分类器
-
use_probas
: bool (default: False)如果为True,基于预测概率而非类别标签训练元分类器.
-
drop_proba_col
: string (default: None)删除特征集中的额外"概率”列,因为它是冗余的: p(y_c) = 1 - p(y_1) + p(y_2) + ... + p(y_{c-1}). 这对于对完全共线特征敏感的元分类器可能很有用. 如果为'last',删除最后一列概率. 如果为'first',删除第一列概率. 仅在
use_probas=True
时相关. -
average_probas
: bool (default: False)如果为True,将概率平均作为元特征. 仅在
use_probas=True
时相关. -
verbose
: int, optional (default=0)控制构建过程的详细程度. -
verbose=0
(默认):不打印任何内容 -verbose=1
:打印正在拟合的回归器的数量和名称 -verbose=2
:打印正在拟合的回归器的参数信息 -verbose>2
:将底层回归器的verbose
参数设置为self.verbose - 2 -
use_features_in_secondary
: bool (default: False)如果为True,元分类器将在原始分类器的预测结果和原始数据集上进行训练. 如果为False,元分类器仅在原始分类器的预测结果上进行训练.
-
store_train_meta_features
: bool (default: False)如果为True,用于拟合元分类器的训练数据计算出的元特征将存储在
self.train_meta_features_
数组中,该数组可以在调用fit
后访问. -
use_clones
: bool (default: True)如果为True(默认),则为堆叠分类克隆分类器;否则使用原始分类器, 这些分类器将在调用
fit
方法时在数据集上重新拟合.因此,如果use_clones=True, 在使用StackingClassifier的fit
方法时,原始输入分类器将保持不变. 如果你使用的是支持scikit-learn fit/predict API接口但不兼容scikit-learn的clone
函数的估计器, 建议设置use_clones=False
. fit_base_estimators: bool (default: True) 如果为True,则在classifiers
中重新拟合分类器;否则使用分类器的引用(假设分类器已经拟合). 注意:fit_base_estimators=False将强制use_clones为False,并且与大多数scikit-learn包装器不兼容! 例如,如果执行任何形式的交叉验证,这将需要对训练折叠重新拟合分类器, 如果fit_base_estimators=False,则会引发NotFitterError. (在mlxtend v0.6中新增.)
Attributes
-
clfs_
: list, shape=[n_classifiers]已拟合的分类器(原始分类器的克隆版本)
-
meta_clf_
: estimator已拟合的元分类器(原始元估计器的克隆版本)
-
train_meta_features
: numpy array, shape = [n_samples, n_classifiers]训练数据的元特征,其中n_samples是训练数据中的样本数量, n_classifiers是分类器的数量.
Examples
有关使用示例,请参见 https://rasbt.github.io/mlxtend/user_guide/classifier/StackingClassifier/
Methods
decision_function(X)
预测X的类别置信度得分.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
scores
: 如果n_classes == 2,shape=(n_samples,),否则shape=(n_samples, n_classes).每个(样本, 类别)组合的置信度得分.在二分类情况下,self.classes_[1]的置信度得分,其中>0表示将预测该类别.
fit(X, y, sample_weight=None)
拟合集成分类器和元分类器.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中 n_samples 是样本数量,n_features 是特征数量.
-
y
: array-like, shape = [n_samples] 或 [n_samples, n_outputs]目标值.
-
sample_weight
: array-like, shape = [n_samples], 可选作为 sample_weights 传递给回归器列表中的每个回归器以及 meta_regressor 的样本权重. 如果在 fit() 方法中某些回归器不支持 sample_weight,则会引发错误.
Returns
self
: object
fit_transform(X, y=None, fit_params)
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
-
X
: array-like of shape (n_samples, n_features)Input samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs), default=NoneTarget values (None for unsupervised transformations).
-
**fit_params
: dictAdditional fit parameters.
Returns
-
X_new
: ndarray array of shape (n_samples, n_features_new)Transformed array.
get_metadata_routing()
Get metadata routing of this object.
Please check :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
Returns
-
routing
: MetadataRequestA :class:
~sklearn.utils.metadata_routing.MetadataRequest
encapsulating routing information.
get_params(deep=True)
返回估计器参数名称以支持网格搜索.
predict(X)
预测目标值.
Parameters
-
X
: numpy数组, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
labels
: 类数组, shape = [n_samples]预测的类别标签.
predict_meta_features(X)
获取测试数据的元特征.
Parameters
-
X
: numpy数组, shape = [n_samples, n_features]测试向量,其中n_samples是样本数量, n_features是特征数量.
Returns
-
meta-features
: numpy数组, shape = [n_samples, n_classifiers]返回测试数据的元特征.
predict_proba(X)
预测X的类别概率.
Parameters
-
X
: {array-like, sparse matrix}, shape = [n_samples, n_features]训练向量,其中n_samples是样本数量,n_features是特征数量.
Returns
-
proba
: array-like, shape = [n_samples, n_classes] 或一个包含n_outputs个此类数组的列表(如果n_outputs > 1).每个样本的每个类别的概率.
score(X, y, sample_weight=None)
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.
Parameters
-
X
: array-like of shape (n_samples, n_features)Test samples.
-
y
: array-like of shape (n_samples,) or (n_samples, n_outputs)True labels for
X
. -
sample_weight
: array-like of shape (n_samples,), default=NoneSample weights.
Returns
-
score
: floatMean accuracy of
self.predict(X)
w.r.t.y
.
set_fit_request(self: mlxtend.classifier.stacking_classification.StackingClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.stacking_classification.StackingClassifier*
Request metadata passed to the fit
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``fit`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``fit``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter infit
.
Returns
-
self
: objectThe updated object.
set_output(, transform=None)*
Set output container.
See :ref:`sphx_glr_auto_examples_miscellaneous_plot_set_output.py`
for an example on how to use the API.
Parameters
-
transform
: {"default", "pandas", "polars"}, default=NoneConfigure output of
transform
andfit_transform
."default"
: Default output format of a transformer"pandas"
: DataFrame output"polars"
: Polars outputNone
: Transform configuration is unchanged
.. versionadded:: 1.4
"polars"
option was added.
Returns
-
self
: estimator instanceEstimator instance.
set_params(params)
设置此估计器的参数.
有效的参数键可以通过 ``get_params()`` 列出.
Returns
self
set_score_request(self: mlxtend.classifier.stacking_classification.StackingClassifier, , sample_weight: Union[bool, NoneType, str] = '$UNCHANGED$') -> mlxtend.classifier.stacking_classification.StackingClassifier*
Request metadata passed to the score
method.
Note that this method is only relevant if
``enable_metadata_routing=True`` (see :func:`sklearn.set_config`).
Please see :ref:`User Guide <metadata_routing>` on how the routing
mechanism works.
The options for each parameter are:
- ``True``: metadata is requested, and passed to ``score`` if provided. The request is ignored if metadata is not provided.
- ``False``: metadata is not requested and the meta-estimator will not pass it to ``score``.
- ``None``: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
- ``str``: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (``sklearn.utils.metadata_routing.UNCHANGED``) retains the
existing request. This allows you to change the request for some
parameters and not others.
.. versionadded:: 1.3
.. note::
This method is only relevant if this estimator is used as a
sub-estimator of a meta-estimator, e.g. used inside a
:class:`~sklearn.pipeline.Pipeline`. Otherwise it has no effect.
Parameters
-
sample_weight
: str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for
sample_weight
parameter inscore
.
Returns
-
self
: objectThe updated object.
Properties
named_classifiers
None