An alias for getOrDefault()
.
An alias for getOrDefault()
.
Param for the alpha parameter in the implicit preference formulation (nonnegative).
Param for the alpha parameter in the implicit preference formulation (nonnegative). Default: 1.0
Attempts to safely cast a user/item id to an Int.
Attempts to safely cast a user/item id to an Int. Throws an exception if the value is out of integer range or contains a fractional part.
Param for set checkpoint interval (>= 1) or disable checkpoint (-1).
Param for set checkpoint interval (>= 1) or disable checkpoint (-1). E.g. 10 means that the cache will get checkpointed every 10 iterations. Note: this setting will be ignored if the checkpoint directory is not set in the SparkContext.
Clears the user-supplied value for the input param.
Clears the user-supplied value for the input param.
Param for strategy for dealing with unknown or new users/items at prediction time.
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".
Creates a copy of this instance with the same UID and some extra 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.
See defaultCopy()
.
Copies param values from this instance to another instance for params shared by them.
Copies param values from this instance to another instance for params shared by them.
This handles default Params and explicitly set Params separately.
Default Params are copied from and to defaultParamMap
, and explicitly set Params are
copied from and to paramMap
.
Warning: This implicitly assumes that this Params instance and the target instance
share the same set of default Params.
the target instance, which should work with the same set of default Params as this source instance
extra params to be copied to the target's paramMap
the target instance with param values copied
Default implementation of copy with extra params.
Default implementation of copy with extra params. It tries to create a new instance with the same UID. Then it copies the embedded and extra parameters over and returns the new instance.
Explains a param.
Explains a param.
input param, must belong to this instance.
a string that contains the input param name, doc, and optionally its default value and the user-supplied value
Explains all params of this instance.
Explains all params of this instance. See explainParam()
.
extractParamMap
with no extra values.
extractParamMap
with no extra values.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values less than user-supplied values less than extra.
Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values less than user-supplied values less than extra.
Param for StorageLevel for ALS model factors.
Param for StorageLevel for ALS model factors. Pass in a string representation of
StorageLevel
.
Default: "MEMORY_AND_DISK".
Fits a model to the input data.
Fits multiple models to the input data with multiple sets of parameters.
Fits multiple models to the input data with multiple sets of parameters. The default implementation uses a for loop on each parameter map. Subclasses could override this to optimize multi-model training.
input dataset
An array of parameter maps. These values override any specified in this Estimator's embedded ParamMap.
fitted models, matching the input parameter maps
Fits a single model to the input data with provided parameter map.
Fits a single model to the input data with provided parameter map.
input dataset
Parameter map. These values override any specified in this Estimator's embedded ParamMap.
fitted model
Fits a single model to the input data with optional parameters.
Fits a single model to the input data with optional parameters.
input dataset
the first param pair, overrides embedded params
other param pairs. These values override any specified in this Estimator's embedded ParamMap.
fitted model
Optionally returns the user-supplied value of a param.
Optionally returns the user-supplied value of a param.
Gets the default value of a parameter.
Gets the default value of a parameter.
Gets the value of a param in the embedded param map or its default value.
Gets the value of a param in the embedded param map or its default value. Throws an exception if neither is set.
Gets a param by its name.
Gets a param by its name.
Tests whether the input param has a default value set.
Tests whether the input param has a default value set.
Tests whether this instance contains a param with a given name.
Tests whether this instance contains a param with a given name.
Param to decide whether to use implicit preference.
Param to decide whether to use implicit preference. Default: false
Param for StorageLevel for intermediate datasets.
Param for StorageLevel for intermediate datasets. Pass in a string representation of
StorageLevel
. Cannot be "NONE".
Default: "MEMORY_AND_DISK".
Checks whether a param is explicitly set or has a default value.
Checks whether a param is explicitly set or has a default value.
Checks whether a param is explicitly set.
Checks whether a param is explicitly set.
Param for the column name for item ids.
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"
Param for maximum number of iterations (>= 0).
Param for maximum number of iterations (>= 0).
Param for whether to apply nonnegativity constraints.
Param for whether to apply nonnegativity constraints. Default: false
Param for number of item blocks (positive).
Param for number of item blocks (positive). Default: 10
Param for number of user blocks (positive).
Param for number of user blocks (positive). Default: 10
Returns all params sorted by their names.
Returns all params sorted by their names. The default implementation uses Java reflection to list all public methods that have no arguments and return Param.
Developer should not use this method in constructor because we cannot guarantee that this variable gets initialized before other params.
Param for prediction column name.
Param for prediction column name.
Param for rank of the matrix factorization (positive).
Param for rank of the matrix factorization (positive). Default: 10
Param for the column name for ratings.
Param for the column name for ratings. Default: "rating"
Param for regularization parameter (>= 0).
Param for regularization parameter (>= 0).
Saves this ML instance to the input path, a shortcut of write.save(path)
.
Saves this ML instance to the input path, a shortcut of write.save(path)
.
Param for random seed.
Param for random seed.
Sets a parameter in the embedded param map.
Sets a parameter in the embedded param map.
Sets a parameter (by name) in the embedded param map.
Sets a parameter (by name) in the embedded param map.
Sets a parameter in the embedded param map.
Sets a parameter in the embedded param map.
Sets default values for a list of params.
Sets default values for a list of params.
Note: Java developers should use the single-parameter setDefault
.
Annotating this with varargs can cause compilation failures due to a Scala compiler bug.
See SPARK-9268.
a list of param pairs that specify params and their default values to set respectively. Make sure that the params are initialized before this method gets called.
Sets a default value for a param.
Sets a default value for a param.
param to set the default value. Make sure that this param is initialized before this method gets called.
the default value
Sets both numUserBlocks and numItemBlocks to the specific value.
Sets both numUserBlocks and numItemBlocks to the specific value.
:: DeveloperApi ::
:: DeveloperApi ::
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 by Param.validate()
.
Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.
:: DeveloperApi ::
:: DeveloperApi ::
Derives the output schema from the input schema and parameters, optionally with logging.
This should be optimistic. If it is unclear whether the schema will be valid, then it should be assumed valid until proven otherwise.
An immutable unique ID for the object and its derivatives.
An immutable unique ID for the object and its derivatives.
Param for the column name for user ids.
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"
Validates and transforms the input schema.
Validates and transforms the input schema.
input schema
output schema
Returns an MLWriter
instance for this ML instance.
Returns an MLWriter
instance for this ML instance.
A list of (hyper-)parameter keys this algorithm can take. Users can set and get the parameter values through setters and getters, respectively.
A list of advanced, expert-only (hyper-)parameter keys this algorithm can take. Users can set and get the parameter values through setters and getters, respectively.
Alternating Least Squares (ALS) matrix factorization.
ALS attempts to estimate the ratings matrix
R
as the product of two lower-rank matrices,X
andY
, i.e.X * Yt = R
. Typically these approximations are called 'factor' matrices. The general approach is iterative. During each iteration, one of the factor matrices is held constant, while the other is solved for using least squares. The newly-solved factor matrix is then held constant while solving for the other factor matrix.This is a blocked implementation of the ALS factorization algorithm that groups the two sets of factors (referred to as "users" and "products") into blocks and reduces communication by only sending one copy of each user vector to each product block on each iteration, and only for the product blocks that need that user's feature vector. This is achieved by pre-computing some information about the ratings matrix to determine the "out-links" of each user (which blocks of products it will contribute to) and "in-link" information for each product (which of the feature vectors it receives from each user block it will depend on). This allows us to send only an array of feature vectors between each user block and product block, and have the product block find the users' ratings and update the products based on these messages.
For implicit preference data, the algorithm used is based on "Collaborative Filtering for Implicit Feedback Datasets", available at http://dx.doi.org/10.1109/ICDM.2008.22, adapted for the blocked approach used here.
Essentially instead of finding the low-rank approximations to the rating matrix
R
, this finds the approximations for a preference matrixP
where the elements ofP
are 1 if r is greater than 0 and 0 if r is less than or equal to 0. The ratings then act as 'confidence' values related to strength of indicated user preferences rather than explicit ratings given to items.