Skip to content

Instantly share code, notes, and snippets.

@mathias-brandewinder
Created May 15, 2013 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathias-brandewinder/5587668 to your computer and use it in GitHub Desktop.
Save mathias-brandewinder/5587668 to your computer and use it in GitHub Desktop.
open System
open System.IO
let path = @"C:\Users\Mathias\Desktop\Dojo\DigitsSample.csv"
let data = File.ReadAllLines(path)
let parsed = data |> Array.map (fun line -> line.Split(','))
let parsed2 = parsed.[1..] |> Array.map (fun line -> line |> Array.map (fun x -> Convert.ToInt32(x)))
type Example = { Number:int; Pixels:int[] }
let sample = parsed2 |> Array.map (fun x -> { Number = x.[0]; Pixels = x.[1..] })
let distance (x:int[]) (y:int[]) =
Array.map2 (fun x y -> (x-y)*(x-y)) x y
|> Array.sum
let classify item n =
let best =
sample
//|> Array.sortBy(fun x -> distance x.Pixels item)
|> Array.minBy(fun x -> distance x.Pixels item)
best.Number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment