pub struct StreamingFitter<M> { /* private fields */ }Expand description
Feeds batches from an iterator to a PartialFit model.
This adapter collects batches from an iterator and feeds them to a model
that implements PartialFit. Multiple epochs can be specified, causing
the batches to be replayed multiple times for convergence.
§Type Parameters
M: The model type, which must implementPartialFit<X, Y>.
Implementations§
Source§impl<M> StreamingFitter<M>
impl<M> StreamingFitter<M>
Sourcepub fn new(model: M) -> Self
pub fn new(model: M) -> Self
Create a new StreamingFitter wrapping the given model.
The default number of epochs is 1 (a single pass over the data).
Sourcepub fn n_epochs(self, n_epochs: usize) -> Self
pub fn n_epochs(self, n_epochs: usize) -> Self
Set the number of epochs (passes over the data).
Each epoch replays all batches in order. More epochs can improve convergence for online learning algorithms.
§Panics
This method does not panic, but fit_batches
will return early with the initial model state if n_epochs is 0.
Sourcepub fn fit_batches<X, Y, I>(self, batches: I) -> Result<M::FitResult, M::Error>where
M: PartialFit<X, Y>,
M::FitResult: PartialFit<X, Y, FitResult = M::FitResult, Error = M::Error>,
I: IntoIterator<Item = (X, Y)>,
pub fn fit_batches<X, Y, I>(self, batches: I) -> Result<M::FitResult, M::Error>where
M: PartialFit<X, Y>,
M::FitResult: PartialFit<X, Y, FitResult = M::FitResult, Error = M::Error>,
I: IntoIterator<Item = (X, Y)>,
Feed all batches to the model, returning the fitted result.
The batches are collected into a Vec so they can be replayed
across multiple epochs. For a single epoch with a non-cloneable
iterator, use fit_batches_single_epoch.
§Errors
Returns the first error encountered during any partial_fit call.
Sourcepub fn fit_batches_single_epoch<X, Y, I>(
self,
batches: I,
) -> Result<M::FitResult, M::Error>where
M: PartialFit<X, Y>,
M::FitResult: PartialFit<X, Y, FitResult = M::FitResult, Error = M::Error>,
I: IntoIterator<Item = (X, Y)>,
pub fn fit_batches_single_epoch<X, Y, I>(
self,
batches: I,
) -> Result<M::FitResult, M::Error>where
M: PartialFit<X, Y>,
M::FitResult: PartialFit<X, Y, FitResult = M::FitResult, Error = M::Error>,
I: IntoIterator<Item = (X, Y)>,
Feed batches from a single-pass iterator to the model.
Unlike fit_batches, this method
does not collect the batches, so it only supports a single epoch.
The n_epochs setting is ignored.
§Errors
Returns the first error encountered during any partial_fit call.
Auto Trait Implementations§
impl<M> Freeze for StreamingFitter<M>where
M: Freeze,
impl<M> RefUnwindSafe for StreamingFitter<M>where
M: RefUnwindSafe,
impl<M> Send for StreamingFitter<M>where
M: Send,
impl<M> Sync for StreamingFitter<M>where
M: Sync,
impl<M> Unpin for StreamingFitter<M>where
M: Unpin,
impl<M> UnsafeUnpin for StreamingFitter<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for StreamingFitter<M>where
M: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more