namespace integerImage
open System.IO
module integerML =
type Example = {
Label : int
Pixels : int []
}
let readExamples path =
path
|> File.ReadAllLines
|> Array.map (fun line -> line.Split ',')
|> Array.map (fun line -> line |> Array.map int)
|> Array.map (fun line -> {Label = line.[0]; Pixels = line.[1..]} )
let distance (img1 : int[]) (img2 : int[]) =
Array.map2 (fun pix1 pix2 -> abs(pix1 - pix2)) img1 img2
|> Array.sum
let classify (img : int[]) =
let bestMatch =
readExamples (__SOURCE_DIRECTORY__ + "/train.csv")
|> Array.minBy (fun x -> distance x.Pixels img)
bestMat
// Some codepublic class IntImg
{
private IntImg() { }
public static int intFrmImg(int[] tst)
{
return integerImage.integerML.classify(tst);
}
}