Skip to main content

MLPClassifier

Struct MLPClassifier 

Source
#[non_exhaustive]
pub struct MLPClassifier { pub loss_curve: Vec<f64>, /* private fields */ }
Expand description

Multi-layer perceptron classifier.

Trains a feedforward neural network for classification using backpropagation with configurable optimizers and activations.

Defaults match sklearn: hidden_layers=[100], Adam, lr=0.001, max_iter=200, batch_size=200, alpha=0.0001.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§loss_curve: Vec<f64>

Training loss curve (one entry per epoch).

Implementations§

Source§

impl MLPClassifier

Source

pub fn new() -> Self

Create a new MLP classifier with sklearn defaults.

Source

pub fn hidden_layers(self, sizes: &[usize]) -> Self

Set hidden layer sizes. Default: &[100].

Source

pub fn activation(self, activation: Activation) -> Self

Set activation function for hidden layers. Default: ReLU.

Source

pub fn optimizer(self, kind: OptimizerKind) -> Self

Set optimizer algorithm. Default: Adam.

Source

pub fn learning_rate(self, lr: f64) -> Self

Set learning rate. Default: 0.001.

Source

pub fn max_iter(self, n: usize) -> Self

Set maximum training iterations (epochs). Default: 200.

Source

pub fn batch_size(self, n: usize) -> Self

Set mini-batch size. Default: 200.

Source

pub fn alpha(self, a: f64) -> Self

Set L2 regularization strength. Default: 0.0001.

Source

pub fn tolerance(self, tol: f64) -> Self

Set convergence tolerance. Default: 1e-4.

Source

pub fn tol(self, t: f64) -> Self

Alias for tolerance (sklearn convention).

Source

pub fn early_stopping(self, enable: bool) -> Self

Enable early stopping with validation split. Default: false.

Source

pub fn validation_fraction(self, frac: f64) -> Self

Set validation fraction for early stopping. Default: 0.1.

Source

pub fn n_iter_no_change(self, n: usize) -> Self

Set patience for early stopping. Default: 10.

Source

pub fn seed(self, s: u64) -> Self

Set random seed. Default: 42.

Source

pub fn learning_rate_schedule(self, schedule: LearningRateSchedule) -> Self

Set learning rate schedule. Default: LearningRateSchedule::Constant.

Use LearningRateSchedule::adaptive() for reduce-on-plateau behavior.

Source

pub fn dropout(self, p: f64) -> Self

Set dropout probability applied between hidden layers.

p is the fraction of activations to zero out (e.g. 0.5 for 50%). Applied only during training; inference is unaffected. Default: 0.0 (no dropout).

Source

pub fn callback(self, cb: Box<dyn TrainingCallback>) -> Self

Add a training callback (invoked after each epoch).

Source

pub fn fit(&mut self, data: &Dataset) -> Result<()>

Train the classifier on a dataset.

Source

pub fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>

Predict class labels for input samples.

features is &[Vec<f64>] where each inner vec is one sample (row-major).

Source

pub fn predict_proba(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>

Predict class probabilities (softmax output).

Returns a flat [batch * n_classes] row-major probability matrix.

Source

pub fn n_classes(&self) -> usize

Number of classes discovered during fit.

Source

pub fn n_features(&self) -> usize

Number of features the model was trained on.

Source

pub fn loss_curve(&self) -> &[f64]

Training loss per epoch.

Source

pub fn history(&self) -> Option<&TrainingHistory>

Structured training history with per-epoch metrics.

Returns None if the model has not been fitted yet.

Source

pub fn weights(&self) -> &[(Vec<f64>, Vec<f64>)]

Saved network weights (for visualization).

Source

pub fn layer_dims(&self) -> &[(usize, usize)]

Layer dimensions (for visualization).

Source

pub fn activation_fn(&self) -> Activation

Hidden-layer activation function.

Trait Implementations§

Source§

impl Clone for MLPClassifier

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MLPClassifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MLPClassifier

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialFit for MLPClassifier

Source§

fn partial_fit(&mut self, data: &Dataset) -> Result<()>

Run one epoch of mini-batch SGD on the given data.

On the first call, initializes the network architecture from the data dimensions. Subsequent calls preserve network weights and continue training.

Source§

fn is_initialized(&self) -> bool

Whether the model has been initialized (at least one partial_fit call).
Source§

impl PipelineModel for MLPClassifier

Source§

fn fit(&mut self, data: &Dataset) -> Result<()>

Train the model on a dataset.
Source§

fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>

Predict on row-major feature matrix.
Source§

impl Tunable for MLPClassifier

Source§

fn set_param(&mut self, name: &str, _value: ParamValue) -> Result<()>

Apply a named hyperparameter. Read more
Source§

fn clone_box(&self) -> Box<dyn Tunable>

Clone this model into a boxed trait object.
Source§

fn fit(&mut self, data: &Dataset) -> Result<()>

Train on a dataset.
Source§

fn predict(&self, features: &[Vec<f64>]) -> Result<Vec<f64>>

Predict on row-major features.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.