【发布时间】:2015-06-19 16:12:45
【问题描述】:
我有以下型号:
case class Product(price:Int,distance:Int)
如果距离为 y(真/假),我有数据告诉我客户是否愿意以价格 x 购买产品。
我在 spark 上使用了逻辑回归,现在可以预测(价格,距离)对。如果我现在想知道距离 x 可以收取的最高价格怎么办?
代码:
val products:List[(Product,Double)] = getProductVotes()
val points:List[LabeledPoints] = products.map{ case (product,vote) =>
LabeledPoint(vote,Vectors.dense(product.price,product.distance)) }
val data: RDD[LabeledPoint] = sc.parallelize(points)
val splits = data.randomSplit(Array(0.6, 0.4), seed = 11L)
val training = splits(0).cache()
val test = splits(1).cache()
val model = new LogisticRegressionWithLBFGS()
.setNumClasses(10)
.run(training)
【问题讨论】:
-
您可以在您的问题中添加一些代码吗?你是如何实现预测的?
标签: scala machine-learning apache-spark logistic-regression