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 IntParam
Param 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.itemCol()
Param for the column name for item ids.static ALSModel
Param for prediction column name.int
rank()
read()
recommendForAllItems
(int numUsers) Returns topnumUsers
users recommended for each item, for all items.recommendForAllUsers
(int numItems) Returns topnumItems
items recommended for each user, for all users.recommendForItemSubset
(Dataset<?> dataset, int numUsers) Returns topnumUsers
users recommended for each item id in the input data set.recommendForUserSubset
(Dataset<?> dataset, int numItems) Returns topnumItems
items 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 anMLWriter
instance for this ML instance.Methods inherited from class org.apache.spark.ml.Transformer
transform, transform, transform
Methods inherited from class org.apache.spark.ml.PipelineStage
params
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.spark.ml.recommendation.ALSModelParams
checkIntegers, getColdStartStrategy, getItemCol, getUserCol
Methods inherited from interface org.apache.spark.ml.param.shared.HasBlockSize
getBlockSize
Methods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionCol
Methods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, 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, withLogContext
Methods inherited from interface org.apache.spark.ml.util.MLWritable
save
Methods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, 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:ALSModelParams
Param 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:
userCol
in interfaceALSModelParams
- Returns:
- (undocumented)
-
itemCol
Description copied from interface:ALSModelParams
Param 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:
itemCol
in interfaceALSModelParams
- Returns:
- (undocumented)
-
coldStartStrategy
Description copied from interface:ALSModelParams
Param 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:
coldStartStrategy
in interfaceALSModelParams
- Returns:
- (undocumented)
-
blockSize
Description copied from interface:HasBlockSize
Param 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:
blockSize
in interfaceHasBlockSize
- Returns:
- (undocumented)
-
predictionCol
Description copied from interface:HasPredictionCol
Param for prediction column name.- Specified by:
predictionCol
in interfaceHasPredictionCol
- Returns:
- (undocumented)
-
uid
Description copied from interface:Identifiable
An immutable unique ID for the object and its derivatives.- Specified by:
uid
in 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:Transformer
Transforms the input dataset.- Specified by:
transform
in classTransformer
- Parameters:
dataset
- (undocumented)- Returns:
- (undocumented)
-
transformSchema
Description copied from class:PipelineStage
Check transform validity and derive the output schema from the input schema.We check validity for interactions between parameters during
transformSchema
and 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:
transformSchema
in classPipelineStage
- Parameters:
schema
- (undocumented)- Returns:
- (undocumented)
-
copy
Description copied from interface:Params
Creates 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:MLWritable
Returns anMLWriter
instance for this ML instance.- Specified by:
write
in interfaceMLWritable
- Returns:
- (undocumented)
-
toString
- Specified by:
toString
in interfaceIdentifiable
- Overrides:
toString
in classObject
-
recommendForAllUsers
Returns topnumItems
items 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 topnumItems
items 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 topnumUsers
users 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 topnumUsers
users 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.
-