Skip to content

Instantly share code, notes, and snippets.

@sudipto80
Created January 21, 2016 08:55
Show Gist options
  • Save sudipto80/d257f8da8ed32b16fec3 to your computer and use it in GitHub Desktop.
Save sudipto80/d257f8da8ed32b16fec3 to your computer and use it in GitHub Desktop.
base line predictor
//Non personalized baseline predictor
let baseline (ratings:(float list)list) =
let mu = ratings |> List.map ( fun ra -> [for i in 0 .. ra.Length - 1 -> ra.[i]]
|> List.filter (fun t -> t <> 0.0)
|> List.average)
|> List.average
let mutable bu = ratings |> List.sumBy (fun rating -> [for i in 0 .. rating.Length - 1 -> rating.[i]]
|> List.filter (fun ri -> ri <> 0.0)
|> List.sumBy (fun ri -> ri - mu))
bu <- bu / float ratings.[0].Length
let mutable bi = ratings |> List.sumBy (fun ra -> [for i in 0 .. ra.Length - 1 -> ra.[i]]
|> List.filter (fun t -> t <> 0.0)
|> List.sumBy (fun z -> z - bu - mu))
bi <- bi / float ratings.Length
mu + bu + bi
@Habush
Copy link

Habush commented Apr 17, 2016

I got here from the link in your "F# Machine Learning Essentials" book. However, you don't explain this formula neither in the book nor in this code. It would be very nice if you could explain the calculations. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment