misc#
Functions#
- capymoa.misc.load_model(file: BinaryIO) object[source]#
Load a model from a jpype pickle file.
See also:
save_model().- Parameters:
file – The file-like object to load the model from.
- Returns:
The loaded model.
- capymoa.misc.save_model(model: object, file: BinaryIO) None[source]#
Save a model to a jpype pickle file.
>>> 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 for more information.
- Parameters:
model – A python object optionally containing Java objects.
file – The file-like object to save the model to.
- capymoa.misc.save_stream_arff(
- file: TextIO | Path | str,
- stream: Stream,
Save a CapyMOA stream to an ARFF file.
Usage for classification datastream:
>>> 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:
>>> 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.