public class MFModel extends Object implements Serializable
Common model for matrix factorization (SVD) recommendation.
Modifier and Type | Field and Description |
---|---|
protected int |
featureCount |
protected int |
itemCount |
protected KeyIndex |
itemIndex |
protected org.apache.commons.math3.linear.RealMatrix |
itemMatrix |
protected int |
userCount |
protected KeyIndex |
userIndex |
protected org.apache.commons.math3.linear.RealMatrix |
userMatrix |
Constructor and Description |
---|
MFModel(org.apache.commons.math3.linear.RealMatrix umat,
org.apache.commons.math3.linear.RealMatrix imat,
KeyIndex uidx,
KeyIndex iidx)
Construct a matrix factorization model.
|
Modifier and Type | Method and Description |
---|---|
int |
getFeatureCount()
Get the model’s feature count.
|
int |
getItemCount()
The number of items.
|
double |
getItemFeature(long iid,
int feature)
Get a particular feature value for an item.
|
KeyIndex |
getItemIndex()
The item index mapping.
|
org.apache.commons.math3.linear.RealMatrix |
getItemMatrix()
Get the item matrix.
|
org.apache.commons.math3.linear.RealVector |
getItemVector(long item) |
int |
getUserCount()
The number of users.
|
double |
getUserFeature(long uid,
int feature)
Get a particular feature value for an user.
|
KeyIndex |
getUserIndex()
The user index mapping.
|
org.apache.commons.math3.linear.RealMatrix |
getUserMatrix()
Get the user matrix.
|
org.apache.commons.math3.linear.RealVector |
getUserVector(long user) |
String |
toString() |
protected int featureCount
protected int userCount
protected int itemCount
protected org.apache.commons.math3.linear.RealMatrix userMatrix
protected org.apache.commons.math3.linear.RealMatrix itemMatrix
protected KeyIndex userIndex
protected KeyIndex itemIndex
public MFModel(org.apache.commons.math3.linear.RealMatrix umat, org.apache.commons.math3.linear.RealMatrix imat, KeyIndex uidx, KeyIndex iidx)
Construct a matrix factorization model. The matrices are not copied, so the caller should make sure they won’t be modified by anyone else.
umat
- The user feature matrix (users x features).imat
- The item feature matrix (items x features).uidx
- The user index mapping.iidx
- The item index mapping.public int getFeatureCount()
Get the model’s feature count.
public int getUserCount()
The number of users.
public int getItemCount()
The number of items.
public KeyIndex getItemIndex()
The item index mapping.
public KeyIndex getUserIndex()
The user index mapping.
public org.apache.commons.math3.linear.RealMatrix getUserMatrix()
Get the user matrix.
public org.apache.commons.math3.linear.RealMatrix getItemMatrix()
Get the item matrix.
@Nullable public org.apache.commons.math3.linear.RealVector getUserVector(long user)
@Nullable public org.apache.commons.math3.linear.RealVector getItemVector(long item)
public double getUserFeature(long uid, int feature)
Get a particular feature value for an user.
uid
- The item ID.feature
- The feature.public double getItemFeature(long iid, int feature)
Get a particular feature value for an item.
iid
- The item ID.feature
- The feature.