Mathias,
In building the chapter 1 classifier, I added components as they were covered in the text. When I got to the page 24 addition of "Training and Evaluating a Classifier Function" I ran into a roadblock.
The train function has an error.
Here is the code up to that point
open System.IO //standard #Net library
type Observation = { Label:string; Pixels: int[]} // create a record (F# specific) essentially an immutable class. two properties Label and Pixels
type Distance = int[] * int[] -> int
type Classifier = int[] -> string
let toObservation(csvData:string)= // notice
let columns = csvData.Split(',')
let label = columns.[0]
let pixels = columns.[1..] |> Array.map int
{ Label = label; Pixels = pixels} //F# magic.... instantiaes an observation by recognizing that only Observation class has correct signature/properties
let reader path = // create the reader function. replaces the C# DataReader Class containing the ReadObservations method
let data = File.ReadAllLines path
data.[1..] // an indexer!. here we drop the first element [0] and keep the rest great array slicing
|> Array.map toObservation //uses the power of the Array module..complete replacement for the c# Enumerable class much like LINQ
let trainingPath = @"C://users/dennis/OneDrive/Class1/Class1/Data/trainingsample.csv";
let training = reader trainingPath
let manhattanDistance (pixels1,pixels2) =
Array.zip pixels1 pixels2
|> Array.map (fun (x,y) -> abs (x-y))
|> Array.sum
let train (trainingset:Observation[]) (dist:Distance) =
let classify (pixels:int[]) =
trainingset
|> Array.minBy (fun x -> manhattanDistance x.Pixels pixels)
|> fun x -> x.Label
classify
In Visual studio Community 2015 I get the error " Script.fsx(30,34): error FS0003: This value is not a function and cannot be applied" while, at the same time, a portion of line 33 is underlined in red "manhattanDistance x.Pixels ". Further in the chapter when the distance function is factored out, and I substitute the structures and functions from page 27. The problem disappears.
where lines 30:34 define the train function above. I've re-entered this section several times, to eliminate any possible invisible character problems, but cannot get it to pass the build step.
Not really a problem, but it may discourage some at an early stage of their coding.
Thank you,
Dennis L. Warner