关注 spark技术分享,
撸spark源码 玩spark最佳实践

ALSModel — Model for Predictions

ALSModel — Model for Predictions

ALSModel is a model fitted by ALS algorithm.

Note
A Model in Spark MLlib is a Transformer that comes with a custom transform method.

When making prediction (i.e. executed), ALSModel…​FIXME

ALSModel is created when:

  • ALS fits a ALSModel

  • ALSModel copies a ALSModel

  • ALSModelReader loads a ALSModel from a persistent storage

ALSModel is a MLWritable.

Making Predictions — transform Method

Note
transform is part of Transformer Contract.

Internally, transform validates the schema of the dataset.

transform left-joins the dataset with userFactors dataset (using userCol column of dataset and id column of userFactors).

Note

Left join takes two datasets and gives all the rows from the left side (of the join) combined with the corresponding row from the right side if available or null.

transform left-joins the dataset with itemFactors dataset (using itemCol column of dataset and id column of itemFactors).

transform makes predictions using the features columns of userFactors and itemFactors datasets (per every row in the left-joined dataset).

transform takes (selects) all the columns from the dataset and predictionCol with predictions.

Ultimately, transform drops rows containing null or NaN values for predictions if coldStartStrategy is drop.

Note
The default value of coldStartStrategy is nan that does not drop missing values from predictions column.

transformSchema Method

Note
transformSchema is part of Transformer Contract.

Internally, transform validates the schema of the dataset.

Creating ALSModel Instance

ALSModel takes the following when created:

  • Unique ID

  • Rank

  • DataFrame of user factors

  • DataFrame of item factors

ALSModel initializes the internal registries and counters.

Requesting sdot from BLAS — predict Internal Property

predict is a user-defined function (UDF) that takes two collections of float numbers and requests BLAS for sdot.

Caution
FIXME Read about com.github.fommil.netlib.BLAS.getInstance.sdot.
Note
predict is a mere wrapper of com.github.fommil.netlib.BLAS.
Note
predict is used exclusively when ALSModel is requested to transform.

Creating ALSModel with Extra Parameters — copy Method

Note
copy is part of Model Contract.

copy creates a new ALSModel.

copy then copies extra parameters to the new ALSModel and sets the parent.

赞(0) 打赏
未经允许不得转载:spark技术分享 » ALSModel — Model for Predictions
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏