# `Latu.ML.Recommendation`
[🔗](https://github.com/zero-one-group/latu_ml/blob/v0.4.2/lib/latu/ml/recommendation.ex#L1)

Collaborative filtering.

One operator: alternating least squares over a user/item/rating frame. Its model holds the
learned factors, and recommends in bulk rather than one row at a time — which is why most of
`Latu.ML.Recommendation.ALSModel` answers with frames.

Every constructor here is generated from PySpark 4.2.0's own param table, and every
accessor module from the server's own attribute allowlist. Nothing in this file is
hand-written but the words you are reading — see `Latu.ML.operators/1` for the table it all
comes from.

# `als`

```elixir
@spec als(keyword()) :: Latu.ML.Estimator.t()
```

Alternating Least Squares (ALS) matrix factorization.

`Latu.ML.fit/2` fits it, and hands back a `Latu.ML.Model` — a reference into the session's
ML cache, not a value. `Latu.ML.with_model/3` releases it for you; `Latu.ML.delete/1` is the
explicit form. Its attributes are on `Latu.ML.Recommendation.ALSModel`.

*Status `:probed`* — `dev/probe_ml.exs` fitted it against a live Spark 4.2.0 server, and
every allowlisted attribute it could ask answered.

## Params

  * `:alpha` — alpha for implicit preference. Default `1.0`.
  * `:block_size` — 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. Default `4096`.
  * `:checkpoint_interval` — 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. Default `10`.
  * `:cold_start_strategy` — 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', 'drop'. Default `"nan"`.
  * `:final_storage_level` — StorageLevel for ALS model factors. Default `"MEMORY_AND_DISK"`.
  * `:implicit_prefs` — whether to use implicit preference. Default `false`.
  * `:intermediate_storage_level` — StorageLevel for intermediate datasets. Cannot be 'NONE'. Default `"MEMORY_AND_DISK"`.
  * `:item_col` — column name for item ids. Ids must be within the integer value range. Default `"item"`.
  * `:max_iter` — max number of iterations (>= 0). Default `10`.
  * `:nonnegative` — whether to use nonnegative constraint for least squares. Default `false`.
  * `:num_item_blocks` — number of item blocks. Default `10`.
  * `:num_user_blocks` — number of user blocks. Default `10`.
  * `:prediction_col` — prediction column name. Default `"prediction"`.
  * `:rank` — rank of the factorization. Default `10`.
  * `:rating_col` — column name for ratings. Default `"rating"`.
  * `:reg_param` — regularization parameter (>= 0). Default `0.1`.
  * `:seed` — random seed.
  * `:user_col` — column name for user ids. Ids must be within the integer value range. Default `"user"`.

Defaults are documented, never sent: a param the caller did not set and a param sent with
its default value are different requests, and only the first is right. A value's **kind** is
refused here; its **range** is Spark's own `ParamValidators` to refuse, with a better
message than this package could write.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
