火花流:经过ALS
我是新来的火花流。当我在ALS上训练Spark流媒体:它是佩戴的。
java.lang.illegalgumentException:要求失败:在streaming.scala in andursplit上,Mappartitionsrdd [4]中没有可用的评分。Scala:15 \
import org.apache.spark.mllib.recommendation.ALS\
import org.apache.spark.mllib.recommendation.Rating\
import org.apache.spark.SparkConf\
import org.apache.spark.SparkContext\
import org.apache.spark.streaming.{Seconds, StreamingContext}\
import org.apache.spark.streaming._\
object streaming {\
def main(args: Array[String]) {\
val conf = new SparkConf().setAppName("ALS").setMaster("local[2]")\
val ssc = new StreamingContext(conf, Seconds(1))\
val ratingStream = ssc.textFileStream(directory="/home/chiao/Downloads/streaming/").map(_.split(',') match {case Array(user,item,rate)=>Rating(user.toInt,item.toInt,rate.toInt)})\
val rank = 100\
val numIterations = 12\
val lambda = 0.01\
ratingStream.foreachRDD(ratingRDD => {val testTrain = ratingRDD.randomSplit(Array(0.3, 0.7))\
val model = ALS.train(testTrain(1), rank,numIterations, lambda)\
val test = testTrain(0).map {case Rating(subject, activity, freq) =>(subject, activity)}\
val prediction = model.predict(test)
})
ssc.start()
ssc.awaitTermination
}}
I'm new to spark streaming. When I trained spark Streaming on ALS:it was worng.
java.lang.IllegalArgumentException: requirement failed: No ratings available from MapPartitionsRDD[4] at randomSplit at streaming.scala:15\
import org.apache.spark.mllib.recommendation.ALS\
import org.apache.spark.mllib.recommendation.Rating\
import org.apache.spark.SparkConf\
import org.apache.spark.SparkContext\
import org.apache.spark.streaming.{Seconds, StreamingContext}\
import org.apache.spark.streaming._\
object streaming {\
def main(args: Array[String]) {\
val conf = new SparkConf().setAppName("ALS").setMaster("local[2]")\
val ssc = new StreamingContext(conf, Seconds(1))\
val ratingStream = ssc.textFileStream(directory="/home/chiao/Downloads/streaming/").map(_.split(',') match {case Array(user,item,rate)=>Rating(user.toInt,item.toInt,rate.toInt)})\
val rank = 100\
val numIterations = 12\
val lambda = 0.01\
ratingStream.foreachRDD(ratingRDD => {val testTrain = ratingRDD.randomSplit(Array(0.3, 0.7))\
val model = ALS.train(testTrain(1), rank,numIterations, lambda)\
val test = testTrain(0).map {case Rating(subject, activity, freq) =>(subject, activity)}\
val prediction = model.predict(test)
})
ssc.start()
ssc.awaitTermination
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的数据是:
1,10,100
1,12,100
1,13,100
2,10,100
2,11,100
2,13,100
3,10,100
3,12,100
在文件中另存为user.txt:/home/chiao/downloads/streaming
my data is:
1,10,100
1,12,100
1,13,100
2,10,100
2,11,100
2,13,100
3,10,100
3,12,100
save as user.txt in file:/home/chiao/Downloads/streaming