pub struct LinearModel {
pub slope: f64,
pub intercept: f64,
}Fields§
§slope: f64§intercept: f64Implementations§
Source§impl LinearModel
impl LinearModel
Sourcepub fn predict(&self, x: f64) -> f64
pub fn predict(&self, x: f64) -> f64
Examples found in repository?
examples/basic_usage.rs (line 26)
3fn main() {
4 // 1. Create some messy data
5 let data = vec![
6 Point::new(1.0, 3.0), // 2x + 1
7 Point::new(2.0, 5.0), // 2x + 1
8 Point::new(3.0, 7.0), // 2x + 1
9 Point::new(4.0, 9.0), // 2x + 1
10 Point::new(2.5, 50.0), // OUTLIER!
11 Point::new(3.5, -10.0), // OUTLIER!
12 Point::new(5.0, 11.0), // 2x + 1
13 ];
14
15 // 2. Fit
16 let result = RansacSolver::new()
17 .with_seed(123)
18 .fit(&data);
19
20 // 3. Handle Result
21 match result {
22 Ok(model) => {
23 println!("Succcess!");
24 println!("y = {:.2}x + {:.2}", model.slope, model.intercept);
25 // Should predict close to y = 2*10 + 1 = 21
26 println!("Prediction for x=10: {}", model.predict(10.0));
27 },
28 Err(e) => println!("RANSAC failed: {}", e),
29 }
30}Trait Implementations§
Source§impl Clone for LinearModel
impl Clone for LinearModel
Source§fn clone(&self) -> LinearModel
fn clone(&self) -> LinearModel
Returns a duplicate 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 LinearModel
impl Debug for LinearModel
impl Copy for LinearModel
Auto Trait Implementations§
impl Freeze for LinearModel
impl RefUnwindSafe for LinearModel
impl Send for LinearModel
impl Sync for LinearModel
impl Unpin for LinearModel
impl UnwindSafe for LinearModel
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