Apache Spark MLLib获得最大价值

时间:2015-04-14 06:42:15

标签: scala machine-learning apache-spark logistic-regression

我有以下型号:

case class Product(price:Int,distance:Int)

我有数据告诉我,如果距离是y(真/假),客户是否愿意以x的价格购买产品。

我在火花上使用了逻辑回归,现在可以预测(价格,距离)对。如果我现在想知道距离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)

1 个答案:

答案 0 :(得分:0)

知道给定距离X的最高价格。

  1. 获取您的训练数据的子集,其中vote = True
  2. 构建标签点,标签为" Price"并且特征是"距离"
  3. 在标记点集上训练线性回归模型以预测" Price"鉴于"距离"
相关问题