public class MatrixFactorizationModel extends java.lang.Object implements Saveable, scala.Serializable
Note: If you create the model directly using constructor, please be aware that fast prediction requires cached user/product features and their associated partitioners.
param: rank Rank for the features in this model. param: userFeatures RDD of tuples where each tuple represents the userId and the features computed for this user. param: productFeatures RDD of tuples where each tuple represents the productId and the features computed for this product.
Modifier and Type | Class and Description |
---|---|
static class |
MatrixFactorizationModel.SaveLoadV1_0$ |
Constructor and Description |
---|
MatrixFactorizationModel(int rank,
RDD<scala.Tuple2<java.lang.Object,double[]>> userFeatures,
RDD<scala.Tuple2<java.lang.Object,double[]>> productFeatures) |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
formatVersion()
Current version of model save/load format.
|
protected static void |
initializeLogIfNecessary(boolean isInterpreter) |
protected static boolean |
isTraceEnabled() |
static MatrixFactorizationModel |
load(SparkContext sc,
java.lang.String path)
Load a model from the given path.
|
protected static org.slf4j.Logger |
log() |
protected static void |
logDebug(scala.Function0<java.lang.String> msg) |
protected static void |
logDebug(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logError(scala.Function0<java.lang.String> msg) |
protected static void |
logError(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static java.lang.String |
logName() |
protected static void |
logTrace(scala.Function0<java.lang.String> msg) |
protected static void |
logTrace(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
double |
predict(int user,
int product)
Predict the rating of one user for one product.
|
JavaRDD<Rating> |
predict(JavaPairRDD<java.lang.Integer,java.lang.Integer> usersProducts)
Java-friendly version of
MatrixFactorizationModel.predict . |
RDD<Rating> |
predict(RDD<scala.Tuple2<java.lang.Object,java.lang.Object>> usersProducts)
Predict the rating of many users for many products.
|
RDD<scala.Tuple2<java.lang.Object,double[]>> |
productFeatures() |
int |
rank() |
Rating[] |
recommendProducts(int user,
int num)
Recommends products to a user.
|
RDD<scala.Tuple2<java.lang.Object,Rating[]>> |
recommendProductsForUsers(int num)
Recommends top products for all users.
|
Rating[] |
recommendUsers(int product,
int num)
Recommends users to a product.
|
RDD<scala.Tuple2<java.lang.Object,Rating[]>> |
recommendUsersForProducts(int num)
Recommends top users for all products.
|
void |
save(SparkContext sc,
java.lang.String path)
Save this model to the given path.
|
RDD<scala.Tuple2<java.lang.Object,double[]>> |
userFeatures() |
public static MatrixFactorizationModel load(SparkContext sc, java.lang.String path)
The model should have been saved by Saveable.save
.
sc
- Spark context used for loading model files.path
- Path specifying the directory to which the model was saved.protected static java.lang.String logName()
protected static org.slf4j.Logger log()
protected static void logInfo(scala.Function0<java.lang.String> msg)
protected static void logDebug(scala.Function0<java.lang.String> msg)
protected static void logTrace(scala.Function0<java.lang.String> msg)
protected static void logWarning(scala.Function0<java.lang.String> msg)
protected static void logError(scala.Function0<java.lang.String> msg)
protected static void logInfo(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logDebug(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logTrace(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logWarning(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logError(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static boolean isTraceEnabled()
protected static void initializeLogIfNecessary(boolean isInterpreter)
public int rank()
public RDD<scala.Tuple2<java.lang.Object,double[]>> userFeatures()
public RDD<scala.Tuple2<java.lang.Object,double[]>> productFeatures()
public double predict(int user, int product)
public RDD<Rating> predict(RDD<scala.Tuple2<java.lang.Object,java.lang.Object>> usersProducts)
usersProducts
- RDD of (user, product) pairs.public JavaRDD<Rating> predict(JavaPairRDD<java.lang.Integer,java.lang.Integer> usersProducts)
MatrixFactorizationModel.predict
.usersProducts
- (undocumented)public Rating[] recommendProducts(int user, int num)
user
- the user to recommend products tonum
- how many products to return. The number returned may be less than this.Rating
objects, each of which contains the given user ID, a product ID, and a
"score" in the rating field. Each represents one recommended product, and they are sorted
by score, decreasing. The first returned is the one predicted to be most strongly
recommended to the user. The score is an opaque value that indicates how strongly
recommended the product is.public Rating[] recommendUsers(int product, int num)
product
- the product to recommend users tonum
- how many users to return. The number returned may be less than this.Rating
objects, each of which contains a user ID, the given product ID, and a
"score" in the rating field. Each represents one recommended user, and they are sorted
by score, decreasing. The first returned is the one predicted to be most strongly
recommended to the product. The score is an opaque value that indicates how strongly
recommended the user is.protected java.lang.String formatVersion()
Saveable
formatVersion
in interface Saveable
public void save(SparkContext sc, java.lang.String path)
This saves: - human-readable (JSON) model metadata to path/metadata/ - Parquet formatted data to path/data/
The model may be loaded using Loader.load
.
public RDD<scala.Tuple2<java.lang.Object,Rating[]>> recommendProductsForUsers(int num)
num
- how many products to return for every user.public RDD<scala.Tuple2<java.lang.Object,Rating[]>> recommendUsersForProducts(int num)
num
- how many users to return for every product.