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

Attributes of a fitted `ALSModel`.

Every accessor here is one name on the server's allowlist for
`org.apache.spark.ml.recommendation.ALSModel` — 7 of them — so tab completion is that
allowlist. The server refuses anything else with `CONNECT_ML.ATTRIBUTE_NOT_ALLOWED`; these
refuse a model of the wrong class before it gets that far, and name the module that would
have taken it.

Allowed by the server but not here: `toString` is `Identifiable`'s, and tells you less than
the model's own uid. `Latu.ML.attribute/2` and `Latu.ML.attribute/3` will send any of these
names; it is what comes back that has nowhere to go.

The allowlist is inherited rather than per class: this one is the union of
`org.apache.spark.ml.recommendation.ALSModel`, `org.apache.spark.ml.util.Identifiable`.

# `class`

```elixir
@spec class() :: String.t()
```

The JVM class these accessors belong to.

# `item_factors`

```elixir
@spec item_factors(Latu.ML.Model.t()) :: Latu.DataFrame.t()
```

a DataFrame that stores item factors in two columns: `id` and `features`.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

# `rank`

```elixir
@spec rank(Latu.ML.Model.t()) :: {:ok, term()} | {:error, Latu.Error.t()}
```

rank of the matrix factorization model.

An action: it reaches the server. A `Vector` or `Matrix` comes back as an `Nx.Tensor`, or a
`Latu.ML.SparseVector` where densifying would be this package's decision rather than yours.

# `recommend_for_all_items`

```elixir
@spec recommend_for_all_items(Latu.ML.Model.t(), integer()) :: Latu.DataFrame.t()
```

Returns top `numUsers` users recommended for each item, for all items.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

## Arguments

  * `num_users` — an integer

# `recommend_for_all_users`

```elixir
@spec recommend_for_all_users(Latu.ML.Model.t(), integer()) :: Latu.DataFrame.t()
```

Returns top `numItems` items recommended for each user, for all users.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

## Arguments

  * `num_items` — an integer

# `recommend_for_item_subset`

```elixir
@spec recommend_for_item_subset(Latu.ML.Model.t(), Latu.DataFrame.t(), integer()) ::
  Latu.DataFrame.t()
```

Returns top `numUsers` users 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.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

## Arguments

  * `dataset` — a `Latu.DataFrame`, sent as a relation rather than a literal
  * `num_users` — an integer

# `recommend_for_user_subset`

```elixir
@spec recommend_for_user_subset(Latu.ML.Model.t(), Latu.DataFrame.t(), integer()) ::
  Latu.DataFrame.t()
```

Returns top `numItems` items 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.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

## Arguments

  * `dataset` — a `Latu.DataFrame`, sent as a relation rather than a literal
  * `num_items` — an integer

# `user_factors`

```elixir
@spec user_factors(Latu.ML.Model.t()) :: Latu.DataFrame.t()
```

a DataFrame that stores user factors in two columns: `id` and `features`.

A lazy builder: the `Fetch` rides a relation, so this hands back a `Latu.DataFrame` and
nothing has run until you collect it.

---

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