Crates.io | linear-regression |
lib.rs | linear-regression |
version | 0.1.0 |
source | src |
created_at | 2023-03-03 12:32:57.055187 |
updated_at | 2023-03-03 12:32:57.055187 |
description | Library for linear regression |
homepage | |
repository | https://github.com/Fugazzii/Linear-Regression-ML |
max_upload_size | |
id | 799726 |
size | 5,585 |
Linear regression algorithm that predicts future values depending on existing data
use linear_regression::{linear_regression, predict}
fn main() {
/* Some data */
let data: Vec<(f32, f32)> = vec![
(17.9, 2013.0),
(17.63, 2014.0),
(14.95, 2015.0),
(15.14, 2016.0),
(16.24, 2017.0),
(17.6, 2018.0),
(17.47, 2019.0),
(15.84, 2020.0),
(18.7, 2021.0)
];
for price in &data {
println!("Year: {}, GDP = ${:.3}B", price.1, price.0);
}
// Linear regression prints the equation and returns k and b
let eq = linear_regression(&data);
// Test cases for different x values
predict(&eq, 2022.0);
}
Example: