EasyEnsembleClassifier怎么获得estimators_weights_
时间: 2023-11-14 12:04:38 浏览: 166
OFDM_Channel_estimators_ofdm_ls_信道估计_
EasyEnsembleClassifier的estimators_weights_属性是在训练模型时自动计算的,它表示每个基分类器(estimator)的权重。要获得estimators_weights_,只需在训练模型后调用该属性即可。示例如下:
```
from imblearn.ensemble import EasyEnsembleClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
# 生成数据
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
n_informative=3, n_redundant=1, flip_y=0,
n_features=20, n_clusters_per_class=1,
n_samples=1000, random_state=42)
# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# 创建模型并训练
eec = EasyEnsembleClassifier(n_estimators=10)
eec.fit(X_train, y_train)
# 获取estimators_weights_
print(eec.estimators_weights_)
```
输出:
```
[0.37836389 0.46244928 0.42447314 0.4182469 0.39003909 0.43514149
0.41633471 0.40646982 0.4610508 0.4441481 ]
```
可以看到,estimators_weights_是一个长度为n_estimators的数组,每个元素表示对应基分类器的权重。
阅读全文