# `io`

## Functions

| [`load_model`](#capymoa.core.io.load_model)       | Load a model from a jpype pickle file.   |
|-------------------------------------------------------------------|------------------------------------------|
| [`save_model`](#capymoa.core.io.save_model)       | Save a model to a jpype pickle file.     |
| [`save_stream_arff`](#capymoa.core.io.save_stream_arff) | Save a CapyMOA stream to an ARFF file.   |

### capymoa.core.io.load_model(file: [BinaryIO](https://docs.python.org/3/library/typing.html#typing.BinaryIO)) → [object](https://docs.python.org/3/builtins/functions.html#object)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/core/io.py#L34)

Load a model from a jpype pickle file.

See also: [`save_model()`](#capymoa.core.io.save_model).

* **Parameters:**
  **file** – The file-like object to load the model from.
* **Returns:**
  The loaded model.

### capymoa.core.io.save_model(model: [object](https://docs.python.org/3/builtins/functions.html#object), file: [BinaryIO](https://docs.python.org/3/library/typing.html#typing.BinaryIO)) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/core/io.py#L12)

Save a model to a jpype pickle file.

```pycon
>>> from capymoa.classifier import AdaptiveRandomForestClassifier
>>> from capymoa.datasets import ElectricityTiny
>>> from tempfile import TemporaryFile
>>> stream = ElectricityTiny()
>>> learner = AdaptiveRandomForestClassifier(schema=stream.get_schema())
>>> with TemporaryFile() as fd:
...     save_model(learner, fd)
```

See [https://jpype.readthedocs.io/en/latest/api.html#jpype-pickle-module](https://jpype.readthedocs.io/en/latest/api.html#jpype-pickle-module) for
more information.

* **Parameters:**
  * **model** – A python object optionally containing Java objects.
  * **file** – The file-like object to save the model to.

### capymoa.core.io.save_stream_arff(file: [TextIO](https://docs.python.org/3/library/typing.html#typing.TextIO) | [Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) | [str](https://docs.python.org/3/builtins/stdtypes.html#str), stream: [Stream](capymoa.stream.Stream.md#capymoa.stream.Stream)) → [None](https://docs.python.org/3/builtins/constants.html#None)[[source]](https://github.com/adaptive-machine-learning/CapyMOA/blob/3e255b1/src/capymoa/core/io.py#L56)

Save a CapyMOA stream to an ARFF file.

Usage for classification datastream:

```pycon
>>> from capymoa.stream import NumpyStream
>>> import numpy as np
>>> from io import StringIO
>>>
>>> stream = NumpyStream(
...     X=np.array([[0, 1], [1, 0], [0, 0]]),
...     y=np.array([0, 1, 0]),
...     dataset_name="SimpleDataset",
...     target_type="categorical"
... )
>>> fd = StringIO() # You can 'open' a real file instead
>>> save_stream_arff(fd, stream)
>>> print(fd.getvalue())
@relation SimpleDataset

@attribute 0 numeric
@attribute 1 numeric
@attribute target {0,1}

@data
0.0,1.0,0,
1.0,0.0,1,
0.0,0.0,0,
```

Usage for regression datastream:

```pycon
>>> stream = NumpyStream(
...     X=np.array([[0, 1], [1, 0], [0, 0]]),
...     y=np.array([0, 1, 0]),
...     dataset_name="SimpleDataset",
...     target_type="numeric"
... )
>>> fd = StringIO() # You can 'open' a real file instead
>>> save_stream_arff(fd, stream)
>>> print(fd.getvalue())
@relation SimpleDataset

@attribute 0 numeric
@attribute 1 numeric
@attribute target numeric

@data
0.0,1.0,0.0,
1.0,0.0,1.0,
0.0,0.0,0.0,
```

* **Parameters:**
  * **file** – A file-like object or path to write the ARFF to.
  * **stream** – The stream to save.
