()
| 7 | use rustml::opt::{plot_learning_curve, opt_hypothesis, empty_opts}; |
| 8 | |
| 9 | fn 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 |
nothing calls this directly
no test coverage detected