我正在研究二进制分类问题并使用SparkML,我使用随机森林和Logistic回归模型训练和评估我的数据,现在我想检查SVM对我的数据进行分类的程度。
我的培训数据片段: -
+----------+------+
| spam | count|
+----------+------+
| No|197378|
| Yes| 7652|
+----------+------+
Note:- My dependent variable: 'spam': string (nullable = true)
+-----+------+
|label| count|
+-----+------+
| 0.0|197488|
| 1.0| 7650|
+-----+------+
Note:- label: double (nullable = false)
更新我的问题: -
trainingData.select('label').distinct().show()
+-----+
|label|
+-----+
| 0.0|
| 1.0|
+-----+
所以,我使用下面的代码来使用线性SVC来拟合我的训练数据: -
pyspark.ml.classification import LinearSVC
lsvc = LinearSVC()
# Fit the model
lsvcModel = lsvc.fit(trainingData)
在我的数据框架中,标签和因变量只有2个类,但是我得到一个错误,说明检测到更多的类。不确定导致此异常的原因。 任何帮助深表感谢!
错误:-
IllegalArgumentException: u'requirement failed: LinearSVC only supports
binary classification. 3 classes detected in
LinearSVC_4240bb949b9fad486ec0__labelCol'
您可以尝试使用带有OnehotEncoder
参数的handleInvalid
将标签值转换为分类数据为“保持”
我有同样的问题。
scala> TEST_DF_37849c70_7cd3_4fd6_a9a0_df4de727df25.select("si_37849c70_7cd3_4fd6_a9a0_df4de727df25_logicProp1_lable_left").distinct.show
+-------------------------------------------------------------+
|si_37849c70_7cd3_4fd6_a9a0_df4de727df25_logicProp1_lable_left|
+-------------------------------------------------------------+
| 0.0|
| 1.0|
+-------------------------------------------------------------+
错误:要求失败:LinearSVC仅支持二进制分类。在linearsvc_d18a38204551__labelCol中检测到3个类
但在我的情况下,使用StringIndexer和setHandleInvalid(“skip”)选项,它的工作原理。也许LeanerSVM在StringIndexer“保持”选项的情况下有一些错误。