【发布时间】:2021-12-26 01:59:40
【问题描述】:
在下面的代码中,我尝试使用EnsembleVoteClassifier() 实现加权投票分类器。
from mlxtend.classifier import EnsembleVoteClassifier
import copy
eclf = EnsembleVoteClassifier(clfs=[s1, s2], weights=[1,1],refit=False)
其中 s1 和 s2 是 PySpark 管道模型。输入是图像数据集。 S1 是特征化器和 LogisticRegression 的流水线模型。 S2是特征化器和NaiveBayes分类器的流水线模型。
为了适应分类器,我需要图像和标签的特征。为了获得功能,我使用了变压器功能。并转换为 pandas 对象。
qa = featurizer.transform(train)
pandas_df3=qa.toPandas()
y_pred3 = np.array(pandas_df3['features'])
y_true3 = np.array(pandas_df3['label'])
eclf.fit(y_pred3,y_true3)
要使用学习投票分类器 eclf 在测试集上进行预测,我需要测试图像的特征。要获得特征,我使用了转换器函数。并转换为 pandas 对象。
qa1 = featurizer.transform(df1)
pandas_df4=qa1.toPandas()
y_pred4 = np.array(pandas_df4['features'])
# used predict () for prediction on test set
eclf.predict(y_pred4)
# here y_pred4 is array([DenseVector([0.0205, 0.0206, 0.1201, 0.9808, 2.3941, 0.1696, 0.2612, 0.2964, 0.3071, 0.0961, 0.2314, 0.0729, 0.0445, 0.0, 0.0, 0.0585, 0.025, 0.3339, 0.2257, 0.0, 0.7522, 0.0, 0.1125, 0.6402, 0.2077, 0.0101, 0.4223, 0.1546, 0.195, 0.5894, 0.3867, 0.0298, 0.0, 0.3882, 0.086, 2.026, 0.3705, 0.1113, 0.452, 0.0056, 0.0, 0.6452, 0.4749, 0.3708, 0.1639,[DenseVector([.......... which is actually features of an image.
# but this gives me error 'PipelineModel' object has no attribute 'predict'
# so I thought of converting it into array([],[]) form
另外,PySpark 中是否有类似EnsembleVoteclassifier 的投票分类器函数来实现加权集成分类器?
【问题讨论】:
标签: python arrays pyspark numpy-ndarray