Sto cercando di utilizzare Spark MLib ALS con feedback implicito per il filtro collaborativo. I dati di input hanno solo due campi userId
e productId
. Ho nessuna valutazione di prodotto, solo informazioni su quali prodotti gli utenti hanno acquistato, questo è tutto. Quindi, per formare la SLA che uso:Come impostare le preferenze per il feedback implicito ALS in Filtro collaborativo?
def trainImplicit(ratings: RDD[Rating], rank: Int, iterations: Int): MatrixFactorizationModel
(http://spark.apache.org/docs/1.0.0/api/scala/index.html#org.apache.spark.mllib.recommendation.ALS $)
Questa API richiede Rating
oggetto:
Rating(user: Int, product: Int, rating: Double)
D'altra documentazione mano sulla trainImplicit
dice: treno un modello a matrice fattorizzazione dato un RDD di voti 'preferenze implicite' dati dagli utenti ad alcuni prodotti, sotto forma di coppie (userID, productID, preferenza).
Quando ho creato di rating/preferenze a 1
come in:
val ratings = sc.textFile(new File(dir, file).toString).map { line =>
val fields = line.split(",")
// format: (randomNumber, Rating(userId, productId, rating))
(rnd.nextInt(100), Rating(fields(0).toInt, fields(1).toInt, 1.0))
}
val training = ratings.filter(x => x._1 < 60)
.values
.repartition(numPartitions)
.cache()
val validation = ratings.filter(x => x._1 >= 60 && x._1 < 80)
.values
.repartition(numPartitions)
.cache()
val test = ratings.filter(x => x._1 >= 80).values.cache()
E poi alleno AlSl:
val model = ALS.trainImplicit(ratings, rank, numIter)
ottengo RMSE 0.9, che è un grande errore nel caso di preferenze prendere 0 o 1 valore:
val validationRmse = computeRmse(model, validation, numValidation)
/** Compute RMSE (Root Mean Squared Error). */
def computeRmse(model: MatrixFactorizationModel, data: RDD[Rating], n: Long): Double = {
val predictions: RDD[Rating] = model.predict(data.map(x => (x.user, x.product)))
val predictionsAndRatings = predictions.map(x => ((x.user, x.product), x.rating))
.join(data.map(x => ((x.user, x.product), x.rating)))
.values
math.sqrt(predictionsAndRatings.map(x => (x._1 - x._2) * (x._1 - x._2)).reduce(_ + _)/n)
}
Quindi la mia domanda è: a quale valore ue devo impostare rating
in:
Rating(user: Int, product: Int, rating: Double)
per la formazione implicita (in ALS.trainImplicit
metodo)?
Aggiornamento
Con:
val alpha = 40
val lambda = 0.01
ottengo:
Got 1895593 ratings from 17471 users on 462685 products.
Training: 1136079, validation: 380495, test: 379019
RMSE (validation) = 0.7537217888106758 for the model trained with rank = 8 and numIter = 10.
RMSE (validation) = 0.7489005441881798 for the model trained with rank = 8 and numIter = 20.
RMSE (validation) = 0.7387672873747732 for the model trained with rank = 12 and numIter = 10.
RMSE (validation) = 0.7310003522283959 for the model trained with rank = 12 and numIter = 20.
The best model was trained with rank = 12, and numIter = 20, and its RMSE on the test set is 0.7302343904091481.
baselineRmse: 0.0 testRmse: 0.7302343904091481
The best model improves the baseline by -Infinity%.
che è ancora un grande errore, immagino. Inoltre ho uno strano miglioramento della linea di base in cui il modello di base è semplicemente meschino (1).
Qual è la 'numPartitions' qui? Questa è una domanda interessante. Anche per i dati impliciti possiamo davvero ottenere un RMSE, RMSE è molto meglio in scala di 1-5 likert, giusto? –
potresti per favore dire quale sarebbe il n qui che stai passando per computeRMSE. Grazie, –