Created
May 15, 2013 21:45
-
-
Save mathias-brandewinder/5587668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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