LinRegressor

Struct LinRegressor 

Source
pub struct LinRegressor { /* private fields */ }
Expand description

Linear Regression Model.

Contains option for optimized parameter.

Implementations§

Source§

impl LinRegressor

Source

pub fn parameters(&self) -> Option<&Vector<f64>>

Get the parameters from the model.

Returns an option that is None if the model has not been trained.

Source§

impl LinRegressor

Source

pub fn train_with_optimization( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, )

Train the linear regressor using Gradient Descent.

§Examples
use rusty_machine::learning::lin_reg::LinRegressor;
use rusty_machine::learning::SupModel;
use rusty_machine::linalg::Matrix;
use rusty_machine::linalg::Vector;

let inputs = Matrix::new(4,1,vec![1.0,3.0,5.0,7.0]);
let targets = Vector::new(vec![1.,5.,9.,13.]);

let mut lin_mod = LinRegressor::default();

// Train the model
lin_mod.train_with_optimization(&inputs, &targets);

// Now we'll predict a new point
let new_point = Matrix::new(1,1,vec![10.]);
let _ = lin_mod.predict(&new_point).unwrap();

Trait Implementations§

Source§

impl Debug for LinRegressor

Source§

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

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

impl Default for LinRegressor

Source§

fn default() -> LinRegressor

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

impl Optimizable for LinRegressor

Source§

type Inputs = Matrix<f64>

The input data type to the model.
Source§

type Targets = Vector<f64>

The target data type to the model.
Source§

fn compute_grad( &self, params: &[f64], inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> (f64, Vec<f64>)

Compute the gradient for the model.
Source§

impl SupModel<Matrix<f64>, Vector<f64>> for LinRegressor

Source§

fn train( &mut self, inputs: &Matrix<f64>, targets: &Vector<f64>, ) -> LearningResult<()>

Train the linear regression model.

Takes training data and output values as input.

§Examples
use rusty_machine::learning::lin_reg::LinRegressor;
use rusty_machine::linalg::Matrix;
use rusty_machine::linalg::Vector;
use rusty_machine::learning::SupModel;

let mut lin_mod = LinRegressor::default();
let inputs = Matrix::new(3,1, vec![2.0, 3.0, 4.0]);
let targets = Vector::new(vec![5.0, 6.0, 7.0]);

lin_mod.train(&inputs, &targets).unwrap();
Source§

fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<f64>>

Predict output value from input data.

Model must be trained before prediction can be made.

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> 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, 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.