个人博客转至:tybai.com

无聊就想打码,打码使我快乐


Fork me on GitHub

spark org.apache.spark.ml.linalg.DenseVector cannot be cast to org.apache.spark.ml.linalg.SparseVector

在使用 import org.apache.spark.ml.feature.VectorAssembler 转换特征后,想要放入 import org.apache.spark.mllib.classification.SVMWithSGD 去训练的时候出现错误:

Caused by: java.lang.ClassCastException: org.apache.spark.ml.linalg.DenseVector cannot be cast to org.apache.spark.ml.linalg.SparseVector

修改如下:

val trainDataFrame = dataframe.rdd.map(r => LabeledPoint(
  r.getAs[Double]("label"),
org.apache.spark.mllib.linalg.Vectors.fromML(r.getAs[org.apache.spark.ml.linalg.SparseVector]("features").toDense)

))

posted on 2019-07-05 10:13 TTyb 阅读(...) 评论(...) 编辑 收藏

导航


不用多久

我就会升职加薪

当上总经理

出任CEO

迎娶白富美

走上人生巅峰

Pulpit rock