Class ALSModel
- All Implemented Interfaces:
Serializable,org.apache.spark.internal.Logging,Params,HasBlockSize,HasPredictionCol,ALSModelParams,Identifiable,MLWritable
Model fitted by ALS.
param: rank rank of the matrix factorization model
param: userFactors a DataFrame that stores user factors in two columns: id and features
param: itemFactors a DataFrame that stores item factors in two columns: id and features
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter -
Method Summary
Modifier and TypeMethodDescriptionfinal IntParamParam for block size for stacking input data in matrices.Param for strategy for dealing with unknown or new users/items at prediction time.Creates a copy of this instance with the same UID and some extra params.longitemCol()Param for the column name for item ids.static ALSModelParam for prediction column name.intrank()read()recommendForAllItems(int numUsers) Returns topnumUsersusers recommended for each item, for all items.recommendForAllUsers(int numItems) Returns topnumItemsitems recommended for each user, for all users.recommendForItemSubset(Dataset<?> dataset, int numUsers) Returns topnumUsersusers recommended for each item id in the input data set.recommendForUserSubset(Dataset<?> dataset, int numItems) Returns topnumItemsitems recommended for each user id in the input data set.setBlockSize(int value) Set block size for stacking input data in matrices.setColdStartStrategy(String value) setItemCol(String value) setPredictionCol(String value) setUserCol(String value) toString()Transforms the input dataset.transformSchema(StructType schema) Check transform validity and derive the output schema from the input schema.uid()An immutable unique ID for the object and its derivatives.userCol()Param for the column name for user ids.write()Returns anMLWriterinstance for this ML instance.Methods inherited from class org.apache.spark.ml.Transformer
transform, transform, transformMethods inherited from class org.apache.spark.ml.PipelineStage
paramsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.spark.ml.recommendation.ALSModelParams
checkIntegers, getColdStartStrategy, getItemCol, getUserColMethods inherited from interface org.apache.spark.ml.param.shared.HasBlockSize
getBlockSizeMethods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionColMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface org.apache.spark.ml.util.MLWritable
saveMethods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, estimateMatadataSize, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
-
Method Details
-
read
-
load
-
userCol
Description copied from interface:ALSModelParamsParam for the column name for user ids. Ids must be integers. Other numeric types are supported for this column, but will be cast to integers as long as they fall within the integer value range. Default: "user"- Specified by:
userColin interfaceALSModelParams- Returns:
- (undocumented)
-
itemCol
Description copied from interface:ALSModelParamsParam for the column name for item ids. Ids must be integers. Other numeric types are supported for this column, but will be cast to integers as long as they fall within the integer value range. Default: "item"- Specified by:
itemColin interfaceALSModelParams- Returns:
- (undocumented)
-
coldStartStrategy
Description copied from interface:ALSModelParamsParam for strategy for dealing with unknown or new users/items at prediction time. This may be useful in cross-validation or production scenarios, for handling user/item ids the model has not seen in the training data. Supported values: - "nan": predicted value for unknown ids will be NaN. - "drop": rows in the input DataFrame containing unknown ids will be dropped from the output DataFrame containing predictions. Default: "nan".- Specified by:
coldStartStrategyin interfaceALSModelParams- Returns:
- (undocumented)
-
blockSize
Description copied from interface:HasBlockSizeParam for block size for stacking input data in matrices. Data is stacked within partitions. If block size is more than remaining data in a partition then it is adjusted to the size of this data..- Specified by:
blockSizein interfaceHasBlockSize- Returns:
- (undocumented)
-
predictionCol
Description copied from interface:HasPredictionColParam for prediction column name.- Specified by:
predictionColin interfaceHasPredictionCol- Returns:
- (undocumented)
-
uid
Description copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
uidin interfaceIdentifiable- Returns:
- (undocumented)
-
rank
public int rank() -
userFactors
-
itemFactors
-
setUserCol
-
setItemCol
-
setPredictionCol
-
setColdStartStrategy
-
setBlockSize
Set block size for stacking input data in matrices. Default is 4096.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
transform
Description copied from class:TransformerTransforms the input dataset.- Specified by:
transformin classTransformer- Parameters:
dataset- (undocumented)- Returns:
- (undocumented)
-
transformSchema
Description copied from class:PipelineStageCheck transform validity and derive the output schema from the input schema.We check validity for interactions between parameters during
transformSchemaand raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled byParam.validate().Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.
- Specified by:
transformSchemain classPipelineStage- Parameters:
schema- (undocumented)- Returns:
- (undocumented)
-
copy
Description copied from interface:ParamsCreates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. SeedefaultCopy(). -
write
Description copied from interface:MLWritableReturns anMLWriterinstance for this ML instance.- Specified by:
writein interfaceMLWritable- Returns:
- (undocumented)
-
toString
- Specified by:
toStringin interfaceIdentifiable- Overrides:
toStringin classObject
-
recommendForAllUsers
Returns topnumItemsitems recommended for each user, for all users.- Parameters:
numItems- max number of recommendations for each user- Returns:
- a DataFrame of (userCol: Int, recommendations), where recommendations are stored as an array of (itemCol: Int, rating: Float) Rows.
-
recommendForUserSubset
Returns topnumItemsitems recommended for each user id in the input data set. Note that if there are duplicate ids in the input dataset, only one set of recommendations per unique id will be returned.- Parameters:
dataset- a Dataset containing a column of user ids. The column name must matchuserCol.numItems- max number of recommendations for each user.- Returns:
- a DataFrame of (userCol: Int, recommendations), where recommendations are stored as an array of (itemCol: Int, rating: Float) Rows.
-
recommendForAllItems
Returns topnumUsersusers recommended for each item, for all items.- Parameters:
numUsers- max number of recommendations for each item- Returns:
- a DataFrame of (itemCol: Int, recommendations), where recommendations are stored as an array of (userCol: Int, rating: Float) Rows.
-
recommendForItemSubset
Returns topnumUsersusers recommended for each item id in the input data set. Note that if there are duplicate ids in the input dataset, only one set of recommendations per unique id will be returned.- Parameters:
dataset- a Dataset containing a column of item ids. The column name must matchitemCol.numUsers- max number of recommendations for each item.- Returns:
- a DataFrame of (itemCol: Int, recommendations), where recommendations are stored as an array of (userCol: Int, rating: Float) Rows.
-
estimatedSize
public long estimatedSize()
-