Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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