Skip to content

Model must be trained before starting prediction #2

@chapter09

Description

@chapter09

My code is as follows, mostly just like the code given in the Usage of README.md. I find there is a if to justify whether the model is empty in LatentMatrixFactorization.scala. Currently I don't know to run this prediction since it seems hard to make the training and prediction in sequential.

val ratings: DStream[Rating[Long]] =
  inputFile.map(line => Rating(line.split(",")(0).toInt,
                               line.split(",")(1).toInt,
                               line.split(",")(2).toFloat)) // Your input stream of Ratings

val algorithm = new StreamingLatentMatrixFactorization(streamingMFParams)
algorithm.trainOn(ratings)

val pInputFile = ssc.socketTextStream("10.2.3.7", 10088)

val testStream: DStream[(Long, Long)] =  // stream of (user, product) pairs to predict on
 pInputFile.map(line => (line.split(",")(0).toInt, line.split(",")(1).toInt))

val predictions: DStream[Rating[Long]] = algorithm.predictOn(testStream)
predictions.print()
ssc.start()
ssc.awaitTermination()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions