pub struct LinearRegression {
pub slope: f64,
pub mean_x: f64,
pub mean_y: f64,
}
Expand description
Simple linear regression from provided data.
use irox_stats::sampling::Sample;
use irox_time::epoch::UnixTimestamp;
use irox_stats::fitting::LinearRegression;
let data = &[
Sample::new(0., UnixTimestamp::from_seconds(0)),
Sample::new(0.5, UnixTimestamp::from_seconds_f64(0.5)),
Sample::new(1., UnixTimestamp::from_seconds(1)),
];
let reg = LinearRegression::from_data(
data.iter(),
|s| s.time.get_offset().as_seconds_f64(),
|s| s.value,
);
assert!(reg.is_some());
let Some(reg) = reg else {
return;
};
assert_eq!(1.0, reg.slope);
assert_eq!(0.5, reg.mean_x);
assert_eq!(0.5, reg.mean_y);
Fields§
§slope: f64
§mean_x: f64
§mean_y: f64
Implementations§
Trait Implementations§
Source§impl Clone for LinearRegression
impl Clone for LinearRegression
Source§fn clone(&self) -> LinearRegression
fn clone(&self) -> LinearRegression
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for LinearRegression
impl Debug for LinearRegression
Source§impl PartialEq for LinearRegression
impl PartialEq for LinearRegression
impl Copy for LinearRegression
impl StructuralPartialEq for LinearRegression
Auto Trait Implementations§
impl Freeze for LinearRegression
impl RefUnwindSafe for LinearRegression
impl Send for LinearRegression
impl Sync for LinearRegression
impl Unpin for LinearRegression
impl UnwindSafe for LinearRegression
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
Mutably borrows from an owned value. Read more