Class/Object

org.apache.flink.ml.recommendation

ALS

Related Docs: object ALS | package recommendation

Permalink

class ALS extends Predictor[ALS]

Alternating least squares algorithm to calculate a matrix factorization.

Given a matrix R, ALS calculates two matrices U and V such that R ~~ U^TV. The unknown row dimension is given by the number of latent factors. Since matrix factorization is often used in the context of recommendation, we'll call the first matrix the user and the second matrix the item matrix. The ith column of the user matrix is u_i and the ith column of the item matrix is v_i. The matrix R is called the ratings matrix and (R)_{i,j} = r_{i,j}.

In order to find the user and item matrix, the following problem is solved:

argmin_{U,V} sum_(i,j\ with\ r_{i,j} != 0) (r_{i,j} - u_{i}Tv_{j})2 + lambda (sum_(i) n_{u_i} ||u_i||2 + sum_(j) n_{v_j} ||v_j||2)

with \lambda being the regularization factor, n_{u_i} being the number of items the user i has rated and n_{v_j} being the number of times the item j has been rated. This regularization scheme to avoid overfitting is called weighted-lambda-regularization. Details can be found in the work of Zhou et al..

By fixing one of the matrices U or V one obtains a quadratic form which can be solved. The solution of the modified problem is guaranteed to decrease the overall cost function. By applying this step alternately to the matrices U and V, we can iteratively improve the matrix factorization.

The matrix R is given in its sparse representation as a tuple of (i, j, r) where i is the row index, j is the column index and r is the matrix value at position (i,j).

Example:
  1. val inputDS: DataSet[(Int, Int, Double)] = env.readCsvFile[(Int, Int, Double)](
      pathToTrainingFile)
    val als = ALS()
      .setIterations(10)
      .setNumFactors(10)
    als.fit(inputDS)
    val data2Predict: DataSet[(Int, Int)] = env.readCsvFile[(Int, Int)](pathToData)
    als.predict(data2Predict)

    Parameters

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ALS
  2. Predictor
  3. Estimator
  4. WithParameters
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ALS()

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def empiricalRisk(labeledData: DataSet[(Long, Long, Double)], riskParameters: ParameterMap = ParameterMap.Empty): DataSet[Double]

    Permalink

    Empirical risk of the trained model (matrix factorization).

    Empirical risk of the trained model (matrix factorization).

    labeledData

    Reference data

    riskParameters

    Additional parameters for the empirical risk calculation

  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def evaluate[Testing, PredictionValue](testing: DataSet[Testing], evaluateParameters: ParameterMap = ParameterMap.Empty)(implicit evaluator: EvaluateDataSetOperation[ALS, Testing, PredictionValue]): DataSet[(PredictionValue, PredictionValue)]

    Permalink

    Evaluates the testing data by computing the prediction value and returning a pair of true label value and prediction value.

    Evaluates the testing data by computing the prediction value and returning a pair of true label value and prediction value. It is important that the implementation chooses a Testing type from which it can extract the true label value.

    Definition Classes
    Predictor
  10. var factorsOption: Option[(DataSet[Factors], DataSet[Factors])]

    Permalink
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def fit[Training](training: DataSet[Training], fitParameters: ParameterMap = ParameterMap.Empty)(implicit fitOperation: FitOperation[ALS, Training]): Unit

    Permalink

    Fits the estimator to the given input data.

    Fits the estimator to the given input data. The fitting logic is contained in the FitOperation. The computed state will be stored in the implementing class.

    Training

    Type of the training data

    training

    Training data

    fitParameters

    Additional parameters for the FitOperation

    fitOperation

    FitOperation which encapsulates the algorithm logic

    Definition Classes
    Estimator
  13. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  14. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  19. val parameters: ParameterMap

    Permalink
    Definition Classes
    WithParameters
  20. def predict[Testing, Prediction](testing: DataSet[Testing], predictParameters: ParameterMap = ParameterMap.Empty)(implicit predictor: PredictDataSetOperation[ALS, Testing, Prediction]): DataSet[Prediction]

    Permalink

    Predict testing data according the learned model.

    Predict testing data according the learned model. The implementing class has to provide a corresponding implementation of PredictDataSetOperation which contains the prediction logic.

    Testing

    Type of the testing data

    Prediction

    Type of the prediction data

    testing

    Testing data which shall be predicted

    predictParameters

    Additional parameters for the prediction

    predictor

    PredictDataSetOperation which encapsulates the prediction logic

    Definition Classes
    Predictor
  21. def setBlocks(blocks: Int): ALS

    Permalink

    Sets the number of blocks into which the user and item matrix shall be partitioned

  22. def setIterations(iterations: Int): ALS

    Permalink

    Sets the number of iterations of the ALS algorithm

  23. def setLambda(lambda: Double): ALS

    Permalink

    Sets the regularization coefficient lambda

  24. def setNumFactors(numFactors: Int): ALS

    Permalink

    Sets the number of latent factors/row dimension of the latent model

  25. def setSeed(seed: Long): ALS

    Permalink

    Sets the random seed for the initial item matrix initialization

  26. def setTemporaryPath(temporaryPath: String): ALS

    Permalink

    Sets the temporary path into which intermediate results are written in order to increase performance.

  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  28. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Predictor[ALS]

Inherited from Estimator[ALS]

Inherited from WithParameters

Inherited from AnyRef

Inherited from Any

Ungrouped