1个不稳定版本
0.1.0 | 2024年5月12日 |
---|
#324 在 机器学习
8KB
82 行
Toy ML
欢迎使用 toy_ml
,这是一个旨在作为机器学习概念的“Hello World”介绍的Rust极简机器学习库。这个项目类似于你学习一门新编程语言时编写的第一个简单程序;它并不打算做很多事情,但它点燃了人们对机器学习领域的希望和好奇心。
概述
Rust的学习曲线陡峭,尤其是在探索机器学习领域时。 toy_ml
通过提供一个简单的梯度下降算法实现来改变这种观念。它并不旨在全面,而是为那些想要在Rust中探索机器学习的求知者指明方向。
安装
将 toy_ml
添加到您的 Cargo.toml 依赖项中
[dependencies]
toy_ml = "0.1.0"
使用
以下是使用 toy_ml
进行梯度下降的示例
use toy_ml::gradient_descent;
fn main() {
// Initialize the slope (m) and y-intercept (c) to 0.
let mut m = 0.0;
let mut b = 0.0;
// Define the learning rate and number of epochs.
let learning_rate = 0.0001;
let epochs = 1000000;
// Define your data points here.
let x_coords = vec![...]; // x-coordinates
let y_coords = vec![...]; // y-coordinates
// Run the gradient descent algorithm.
for _ in 0..epochs {
let (new_m, new_c) = gradient_descent(m, c, learning_rate, &x_coords, &y_coords);
m = new_m;
c = new_c;
}
println!("Calculated values - Slope: {:?}, Intercept: {:?}", m, c);
let new_x = vec![3.0, 6.0]; // New values of X to be predicted
let mut predictions:Vec<f64> = Vec::new();
for x in &new_x{
predictions.push(x * m + c);
}
println!("{:?}", predictions);
}
贡献
欢迎贡献!如果您有改进的想法或想要帮助完善这个包,请随意创建问题或提交拉取请求。
许可证
本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE文件。
致谢
toy_ml
是一个有远大抱负的谦逊项目。它不承诺星辰大海,但希望以Rust为载体,开启千千万万的机器学习之旅。如果它能够激发哪怕一个人的兴趣,它就已经实现了它的使命。
编码愉快!