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 SummaryNested classes/interfaces inherited from interface org.apache.spark.internal.Loggingorg.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter
- 
Method SummaryModifier 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.itemCol()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.Transformertransform, transform, transformMethods inherited from class org.apache.spark.ml.PipelineStageparamsMethods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.spark.ml.recommendation.ALSModelParamscheckIntegers, getColdStartStrategy, getItemCol, getUserColMethods inherited from interface org.apache.spark.ml.param.shared.HasBlockSizegetBlockSizeMethods inherited from interface org.apache.spark.ml.param.shared.HasPredictionColgetPredictionColMethods inherited from interface org.apache.spark.internal.LogginginitializeForcefully, 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, withLogContextMethods inherited from interface org.apache.spark.ml.util.MLWritablesaveMethods inherited from interface org.apache.spark.ml.param.Paramsclear, 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
- 
userColDescription 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 interface- ALSModelParams
- Returns:
- (undocumented)
 
- 
itemColDescription 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 interface- ALSModelParams
- Returns:
- (undocumented)
 
- 
coldStartStrategyDescription 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 interface- ALSModelParams
- Returns:
- (undocumented)
 
- 
blockSizeDescription 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 interface- HasBlockSize
- Returns:
- (undocumented)
 
- 
predictionColDescription copied from interface:HasPredictionColParam for prediction column name.- Specified by:
- predictionColin interface- HasPredictionCol
- Returns:
- (undocumented)
 
- 
uidDescription copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
- uidin interface- Identifiable
- Returns:
- (undocumented)
 
- 
rankpublic int rank()
- 
userFactors
- 
itemFactors
- 
setUserCol
- 
setItemCol
- 
setPredictionCol
- 
setColdStartStrategy
- 
setBlockSizeSet block size for stacking input data in matrices. Default is 4096.- Parameters:
- value- (undocumented)
- Returns:
- (undocumented)
 
- 
transformDescription copied from class:TransformerTransforms the input dataset.- Specified by:
- transformin class- Transformer
- Parameters:
- dataset- (undocumented)
- Returns:
- (undocumented)
 
- 
transformSchemaDescription 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 class- PipelineStage
- Parameters:
- schema- (undocumented)
- Returns:
- (undocumented)
 
- 
copyDescription 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().
- 
writeDescription copied from interface:MLWritableReturns anMLWriterinstance for this ML instance.- Specified by:
- writein interface- MLWritable
- Returns:
- (undocumented)
 
- 
toString- Specified by:
- toStringin interface- Identifiable
- Overrides:
- toStringin class- Object
 
- 
recommendForAllUsersReturns 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.
 
- 
recommendForUserSubsetReturns 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 match- userCol.
- 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.
 
- 
recommendForAllItemsReturns 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.
 
- 
recommendForItemSubsetReturns 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 match- itemCol.
- 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.
 
 
-