pub fn mean_absolute_error(expected: &[f64], estimated: &[f64]) -> f64Expand description
Get the mean absolute error between two vectors
Examples found in repository?
examples/xor.rs (line 115)
98fn get_bits_error_rate(
99 estimated_output: Vec<Vec<f64>>,
100 expected_output: Vec<Vec<f64>>,
101) -> (f64, f64) {
102 let mut y_tested_binary = vec![0.0; estimated_output.len()];
103
104 for (n, estimated) in estimated_output.iter().enumerate() {
105 if estimated[0] > 0.5 {
106 y_tested_binary[n] = 1.0;
107 } else {
108 y_tested_binary[n] = 0.0;
109 }
110 }
111
112 let expected_output = expected_output.into_iter().flatten().collect::<Vec<f64>>();
113
114 let mse = mean_squared_error(&expected_output, &y_tested_binary);
115 let mae = mean_absolute_error(&expected_output, &y_tested_binary);
116
117 (mse, mae)
118}
119
120fn get_error_rate(estimated_output: Vec<Vec<f64>>, expected_output: Vec<Vec<f64>>) -> (f64, f64) {
121 let estimated_output = estimated_output.iter().map(|x| x[0]).collect::<Vec<f64>>();
122 let expected_output = expected_output.into_iter().flatten().collect::<Vec<f64>>();
123
124 let mse = mean_squared_error(&expected_output, &estimated_output);
125 let mae = mean_absolute_error(&expected_output, &estimated_output);
126
127 (mse, mae)
128}