I am trying to write a machine learning library in Haskell, to work on my Haskell skills. I thought about a general design involving a class which is like so:
class Classifier classifier where
train :: X -> y -> trainingData
classify :: trainingData -> x -> y
For example, given a set of examples X, and their true labels y, train returns trainingData which is used in the classify function.
So, if I want to implement KNN, I would do it like so:
data KNN = KNN Int (Int -> Int -> Float)
Where the first int is the number of neighbors and the function its the metric that calculate the distance between the vectors
instance Classifier KNN where
---This is where I am stuck---
How can I implement the Classifier type class function so they would be generic to all of the classifier that I will create? I am feeling like I am treating Haskell too much like an imperative OOP like language and I'd like to do this the Haskell way.
classify
andtrain
functions for the various classifiers you plan on creating? Then it will probably be obvious if, why and how to abstract things – jberryman