BatchRegressor#
- class capymoa.base.BatchRegressor[source]#
Bases:
Regressor
Base class for batch trained regression algorithms.
>>> class MyBatchRegressor(BatchRegressor): ... ... def batch_train(self, x, y): ... with np.printoptions(precision=2): ... print(x) ... print(y) ... print() ... ... def predict(self, instance): ... return 0.0 ... >>> from capymoa.datasets import FriedTiny >>> print("downloading stream"); stream = FriedTiny() downloading stream... >>> learner = MyBatchRegressor(stream.schema, batch_size=2) >>> for _ in range(4): ... learner.train(stream.next_instance()) [[0.49 0.07 0. 0.83 0.76 0.6 0.13 0.89 0.07 0.34] [0.22 0.4 0.66 0.53 0.84 0.71 0.58 0.47 0.57 0.53]] [17.95 13.81] [[0.9 0.91 0.94 0.98 0.56 0.74 0.63 0.82 0.31 0.51] [0.79 0.86 0.36 0.84 0.16 0.95 0.11 0.29 0.41 0.99]] [20.77 18.3 ]
- __init__(
- schema: Schema,
- batch_size: int,
- random_seed: int = 1,
Initialize the batch classifier.
- Parameters:
schema – A schema used to allocate memory for the batch.
batch_size – The size of the batch.
random_seed – The random seed for reproducibility.
- train(instance: RegressionInstance) None [source]#
Collate instances into a batch and call
batch_train()
.
- abstract batch_train(
- x: ndarray[Any, dtype[number]],
- y: ndarray[Any, dtype[integer]],
Train the classifier with a batch of instances.
- Parameters:
x – A real valued matrix of shape
(batch_size, num_attributes)
containing a batch of feature vectors.y – A real valued vector of shape
(batch_size,)
containing a batch of target values.
- abstract predict(instance: RegressionInstance) float64 [source]#