<!-- Source: https://docs.squirro.com/en/latest/api/squirro.lib.nlp.steps.projectors.SklearnProjector.html -->
# SklearnProjector

**`class SklearnProjector(config)`**

Bases: [`Projector`](squirro.lib.nlp.steps.projectors.Projector.md#squirro.lib.nlp.steps.projectors.Projector)

The generic scikit-learn [`Projector`](squirro.lib.nlp.steps.projectors.Projector.md#squirro.lib.nlp.steps.projectors.Projector) step projects from one vector space to another. For more info see [Decomposition](https://scikit-learn.org/stable/modules/classes.html#module-sklearn.decomposition).

**Note** - So far only svd is supported -> [TruncatedSVD](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.TruncatedSVD.html#sklearn.decomposition.TruncatedSVD)

**Input** - all input fields need to be of type [`list`](https://docs.python.org/3.11/library/stdtypes.html#list) [ [`float`](https://docs.python.org/3.11/library/functions.html#float) or [`int`](https://docs.python.org/3.11/library/functions.html#int) ] or `numpy.ndarray`

**Output** - all output fields are filled with data of type `numpy.ndarray` with shape (‘n_components’,)

Parameters

- `type` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)) – sklearn
- `model_type` ([`str`](https://docs.python.org/3.11/library/stdtypes.html#str)`, ``'svd'`) – Type of scikit-learn projection
- `model_kwargs` ([`dict`](https://docs.python.org/3.11/library/stdtypes.html#dict)`, ``{}`) – Keyword arguments for the scikit-learn model
- `n_components` ([`int`](https://docs.python.org/3.11/library/functions.html#int)) – Number of vector components after projection
- `normalize_output` ([`bool`](https://docs.python.org/3.11/library/functions.html#bool)`, ``True`) – Whether or not to normalize the output

**Example**

```json
{
    "step": "projector",
    "type": "sklearn",
    "model_type": "svd",
    "n_components": 100,
    "input_field": "embedded_text",
    "output_field": "embedded_text"
}
```

Methods SummaryMethods Documentation

**`load()`**

Load a step

**`process_batch(batch)`**

Process a batch of documents. If not defined will default to using
self.process_doc for each document in the batch.

Parameters

`batch` ([`list`](https://docs.python.org/3.11/library/stdtypes.html#list)`(`[`Document`](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)`)`) – List of documents

Returns

List of processed documents

Return type

[list](https://docs.python.org/3.11/library/stdtypes.html#list)([Document](../technical/libnlp/base.md#squirro.lib.nlp.document.Document))

**`save()`**

Save a step

**`train(docs)`**

Train on a step of a set of documents

Parameters

`docs` (`generator``(`[`Document`](../technical/libnlp/base.md#squirro.lib.nlp.document.Document)`)`) – Generator of documents

Returns

Generator of processed documents

Return type

generator([Document](../technical/libnlp/base.md#squirro.lib.nlp.document.Document))
