Skip to content

Commit 66b8f5b

Browse files
committed
modAL.models.ActiveLearner _fit_on_new method added
1 parent 7b997cd commit 66b8f5b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

modAL/models.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,35 @@ def _fit_to_known(self, bootstrap=False, **fit_kwargs):
170170
self.estimator.fit(self.X_training[bootstrap_idx], self.y_training[bootstrap_idx], **fit_kwargs)
171171
return self
172172

173+
def _fit_on_new(self, X, y, bootstrap=False, **fit_kwargs):
174+
"""
175+
Fits self.estimator to the given data and labels.
176+
177+
Parameters
178+
----------
179+
X: numpy.ndarray of shape (n_samples, n_features)
180+
The new samples for which the labels are supplied
181+
by the expert.
182+
183+
y: numpy.ndarray of shape (n_samples, )
184+
Labels corresponding to the new instances in X.
185+
186+
bootstrap: boolean
187+
If True, the method trains the model on a set bootstrapped from X.
188+
189+
fit_kwargs: keyword arguments
190+
Keyword arguments to be passed to the fit method of the predictor.
191+
"""
192+
assert len(X) == len(y), 'the length of X and y must match'
193+
194+
if not bootstrap:
195+
self.estimator.fit(X, y, **fit_kwargs)
196+
return self
197+
else:
198+
bootstrap_idx = np.random.choice(range(len(X)), len(X), replace=True)
199+
self.estimator.fit(X[bootstrap_idx], y[bootstrap_idx])
200+
return self
201+
173202
def fit(self, X, y, bootstrap=False, **fit_kwargs):
174203
"""
175204
Interface for the fit method of the predictor. Fits the predictor

0 commit comments

Comments
 (0)