MCPcopy Create free account
hub / github.com/daniel-e/rustml / main

Function main

examples/linear_regression.rs:9–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7use rustml::opt::{plot_learning_curve, opt_hypothesis, empty_opts};
8
9fn main() {
10
11 let dm = from_csv_file("datasets/testing/points.txt", " ")
12 .unwrap().design_matrix();
13
14 let y = dm.column(2).unwrap();
15 let x = dm.rm_column(2).unwrap();
16
17 let result = opt_hypothesis(
18 &Hypothesis::from_params(&[0.7, 0.5]),
19 &x, &y,
20 empty_opts().alpha(0.05).iter(400)
21 );
22
23 let w = Window::new();
24
25 plot_learning_curve(&result, &w).unwrap();
26 w.wait_key();
27
28 // plot the hypothesis with the data points
29 builder()
30 .add("x = [0, 1]")
31 .add_values("y = $1 + $2 * x", &result.params)
32 .add("plot(x, y, 'linewidth', 2, 'color', 'red')")
33 .add("hold on")
34 .add_vector("x = $$", &x.column(1).unwrap())
35 .add_vector("y = $$", &y)
36 .add("plot(x, y, 'o')")
37 .add("grid on")
38 .add("axis('nolabel')")
39 .add("print -r50 -dpng '/tmp/linreg_plot.png'")
40 .run("/tmp/plot_script.m")
41 .unwrap();
42
43 w.show_image(&RgbImage::from_file("/tmp/linreg_plot.png").unwrap());
44 w.wait_key();
45}
46

Callers

nothing calls this directly

Calls 15

from_csv_fileFunction · 0.85
opt_hypothesisFunction · 0.85
empty_optsFunction · 0.85
plot_learning_curveFunction · 0.85
from_fileFunction · 0.85
design_matrixMethod · 0.80
columnMethod · 0.80
rm_columnMethod · 0.80
alphaMethod · 0.80
wait_keyMethod · 0.80
runMethod · 0.80
add_vectorMethod · 0.80

Tested by

no test coverage detected