gleam_synapses/stats

Measure the difference between the values predicted by a neural network and the observed values.

Functions

pub fn rmse(output_pairs: Iterator(#(List(Float), List(Float)))) -> Float

The standard deviation of the prediction errors (root mean square error). output_pairs should be an iterator o tuples that contain the expected and predicted values.

[#([0.0, 0.0, 1.0], [0.0, 0.0, 1.0]),
 #([0.0, 0.0, 1.0], [0.0, 1.0, 1.0])]
|> iterator.from_list
|> stats.rmse
0.7071067811865476
pub fn score(output_pairs: Iterator(#(List(Float), List(Float)))) -> Float

The ratio of correct predictions to the total number of provided observations. For a prediction to be considered as correct, the index of its maximum expected value needs to be the same with the index of its maximum predicted value. output_pairs should be an iterator o tuples that contain the expected and predicted values.

[
  #([0.0, 0.0, 1.0], [0.0, 0.1, 0.9]),
  #([0.0, 1.0, 0.0], [0.8, 0.2, 0.0]),
  #([1.0, 0.0, 0.0], [0.7, 0.1, 0.2]),
  #([1.0, 0.0, 0.0], [0.3, 0.3, 0.4]),
  #([0.0, 0.0, 1.0], [0.2, 0.2, 0.6]),
]
|> iterator.from_list
|> stats.score
0.6