Instance#
- class capymoa.instance.Instance[source]#
Bases:
object
An instance is a single data point in a stream. It contains a feature vector and a schema that describes the datastream it belongs to.
In supervised learning, your more likely to encounter
LabeledInstance
orRegressionInstance
which are subclasses ofInstance
with a class label or target value respectively.- __init__(
- schema: Schema,
- instance: InstanceExample | ndarray[Any, dtype[float64]],
Creates a new instance.
Its recommended that you prefer using
from_array()
orfrom_java_instance()
to create instances, as they provide a more user-friendly interface.- Parameters:
schema – A schema that describes the datastream the instance belongs to.
instance – A vector of features (float values) or a Java instance.
- Raises:
ValueError – If the given instance type is of an unsupported type.
- classmethod from_java_instance(
- schema: Schema,
- java_instance: InstanceExample,
- classmethod from_array(
- schema: Schema,
- instance: ndarray[Any, dtype[float64]],
A class constructor to create an instance from a schema and a vector of features.
This is useful in the rare cases you need to create custom unlabeled instances from scratch. In most cases, your datastream will automatically create instances for you.
>>> from capymoa.stream import Schema ... >>> from capymoa.instance import Instance >>> import numpy as np >>> schema = Schema.from_custom( ... ["f1", "f2"], ... dataset_name="CustomDataset", ... values_for_class_label=["yes", "no"] ... ) >>> x = np.array([0.1, 0.2]) >>> instance = Instance.from_array(schema, x) >>> instance Instance( Schema(CustomDataset), x=ndarray(..., 2) )
- Parameters:
schema – A schema that describes the datastream the instance belongs to.
instance – A vector (
numpy.ndarray
) of features (float values
- Returns:
A new
Instance
object
- property x: ndarray[Any, dtype[float64]]#
Returns a feature vector containing float values for the instance.
- property java_instance: InstanceExample#
Returns a representation of the instance in Java for use in MOA. This method is for advanced users who want to directly interact with MOA’s Java API.