stacked_ensemble_classifier#
栈式集成分类器。
模块内容#
类摘要#
栈式集成分类器。 |
目录#
- class evalml.pipelines.components.ensemble.stacked_ensemble_classifier.StackedEnsembleClassifier(final_estimator=None, n_jobs=-1, random_seed=0, **kwargs)[source]#
栈式集成分类器。
- 参数
final_estimator (Estimator 或 子类) – 用于组合基础估计器的分类器。如果为 None,则使用 ElasticNetClassifier。
n_jobs (int 或 None) – 用于流水线的并行度级别。None 和 1 是等效的。如果设置为 -1,则使用所有 CPU。对于小于 -1 的 n_jobs 值,使用 (n_cpus + 1 + n_jobs) 个 CPU。默认为 -1。- 注意:对于 n_jobs != 1 的值,可能会抛出一些多进程错误。如果发生这种情况,请使用 n_jobs = 1。
random_seed (int) – 随机数生成器的种子。默认为 0。
示例
>>> from evalml.pipelines.component_graph import ComponentGraph >>> from evalml.pipelines.components.estimators.classifiers.decision_tree_classifier import DecisionTreeClassifier >>> from evalml.pipelines.components.estimators.classifiers.elasticnet_classifier import ElasticNetClassifier ... >>> component_graph = { ... "Decision Tree": [DecisionTreeClassifier(random_seed=3), "X", "y"], ... "Decision Tree B": [DecisionTreeClassifier(random_seed=4), "X", "y"], ... "Stacked Ensemble": [ ... StackedEnsembleClassifier(n_jobs=1, final_estimator=DecisionTreeClassifier()), ... "Decision Tree.x", ... "Decision Tree B.x", ... "y", ... ], ... } ... >>> cg = ComponentGraph(component_graph) >>> assert cg.default_parameters == { ... 'Decision Tree Classifier': {'criterion': 'gini', ... 'max_features': 'sqrt', ... 'max_depth': 6, ... 'min_samples_split': 2, ... 'min_weight_fraction_leaf': 0.0}, ... 'Stacked Ensemble Classifier': {'final_estimator': ElasticNetClassifier, ... 'n_jobs': -1}}
属性
hyperparameter_ranges
{}
model_family
ModelFamily.ENSEMBLE
modifies_features
True
modifies_target
False
name
栈式集成分类器
supported_problem_types
[ ProblemTypes.BINARY, ProblemTypes.MULTICLASS, ProblemTypes.TIME_SERIES_BINARY, ProblemTypes.TIME_SERIES_MULTICLASS,]
training_only
False
方法
使用相同的参数和随机状态构造新的组件。
返回栈式集成类的默认参数。
描述一个组件及其参数。
未对 StackedEnsembleClassifier 和 StackedEnsembleRegressor 实现此方法。
将估计器拟合到数据。
使用已拟合的回归器查找预测区间。
从文件路径加载组件。
返回一个布尔值,指示组件在调用 predict, predict_proba, transform 或 feature_importances 之前是否需要拟合。
返回用于初始化组件的参数。
使用选定的特征进行预测。
对标签进行概率估计。
将组件保存到文件路径。
更新组件的参数字典。
- clone(self)#
使用相同的参数和随机状态构造新的组件。
- 返回
一个具有相同参数和随机状态的此组件的新实例。
- default_parameters(cls)#
返回栈式集成类的默认参数。
- 返回
此组件的默认参数。
- 返回类型
dict
- describe(self, print_name=False, return_dict=False)#
描述一个组件及其参数。
- 参数
print_name (bool, optional) – 是否打印组件名称
return_dict (bool, optional) – 是否以 {"name": name, "parameters": parameters} 格式将描述作为字典返回
- 返回
如果 return_dict 为 True,则返回字典,否则返回 None。
- 返回类型
None 或 dict
- property feature_importance(self)#
未对 StackedEnsembleClassifier 和 StackedEnsembleRegressor 实现此方法。
- fit(self, X: pandas.DataFrame, y: Optional[pandas.Series] = None)#
将估计器拟合到数据。
- 参数
X (pd.DataFrame) – 输入训练数据,形状为 [n_samples, n_features]。
y (pd.Series, optional) – 目标训练数据,长度为 [n_samples]。
- 返回
self
- get_prediction_intervals(self, X: pandas.DataFrame, y: Optional[pandas.Series] = None, coverage: List[float] = None, predictions: pandas.Series = None) Dict[str, pandas.Series] #
使用已拟合的回归器查找预测区间。
此函数获取已拟合估计器的预测结果,并使用窗口大小为 5 计算所有预测的滚动标准差。通过取每个边界处下尾概率的百分位数(分位数)函数乘以滚动标准差来确定预测的下限和上限。
- 参数
X (pd.DataFrame) – 数据,形状为 [n_samples, n_features]。
y (pd.Series) – 目标数据。忽略。
coverage (list[float]) – 一个介于 0 和 1 之间的浮点数列表,用于计算预测区间的上限和下限。
predictions (pd.Series) – 可选的预测列表,供使用。如果为 None,将使用 X 生成预测。
- 返回
预测区间,键格式为 {coverage}_lower 或 {coverage}_upper。
- 返回类型
dict
- 抛出
MethodPropertyNotFoundError – 如果估计器不支持时间序列回归作为问题类型。
- static load(file_path)#
从文件路径加载组件。
- 参数
file_path (str) – 加载文件的位置。
- 返回
ComponentBase 对象
- needs_fitting(self)#
返回一个布尔值,指示组件在调用 predict, predict_proba, transform 或 feature_importances 之前是否需要拟合。
对于不需要拟合或其拟合方法不执行任何操作的组件,此方法可以被重写为 False。
- 返回
True。
- property parameters(self)#
返回用于初始化组件的参数。
- predict(self, X: pandas.DataFrame) pandas.Series #
使用选定的特征进行预测。
- 参数
X (pd.DataFrame) – 数据,形状为 [n_samples, n_features]。
- 返回
预测值。
- 返回类型
pd.Series
- 抛出
MethodPropertyNotFoundError – 如果估计器没有 predict 方法或没有实现 predict 的 component_obj。
- predict_proba(self, X: pandas.DataFrame) pandas.Series #
对标签进行概率估计。
- 参数
X (pd.DataFrame) – 特征。
- 返回
概率估计。
- 返回类型
pd.Series
- 抛出
MethodPropertyNotFoundError – 如果估计器没有 predict_proba 方法或没有实现 predict_proba 的 component_obj。
- save(self, file_path, pickle_protocol=cloudpickle.DEFAULT_PROTOCOL)#
将组件保存到文件路径。
- 参数
file_path (str) – 保存文件的位置。
pickle_protocol (int) – pickle 数据流格式。
- update_parameters(self, update_dict, reset_fit=True)#
更新组件的参数字典。
- 参数
update_dict (dict) – 要更新的参数字典。
reset_fit (bool, optional) – 如果为 True,会将 _is_fitted 设置为 False。