packages feed

hinduce-classifier (empty) → 0.0.0.0

raw patch · 4 files changed

+93/−0 lines, 4 filesdep +basedep +haskell98dep +hinduce-missinghsetup-changed

Dependencies added: base, haskell98, hinduce-missingh, layout

Files

+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hinduce-classifier.cabal view
@@ -0,0 +1,22 @@+Name:           hinduce-classifier+Version:        0.0.0.0+License:        BSD3+Author:         Robert Hensing+Maintainer:     hackage@roberthensing.nl+Synopsis:       Interface and utilities for classifiers+Description:    Provides an interface for classifiers and functions to use and analyze them. Take one or more hinduce-classifier-* packages for actual classifier implementations.+Stability:      stable+Maintainer:     Robert Hensing+Build-Type:     Simple+Cabal-Version:  >= 1.2+Category:       Data Mining++Library+    Build-Depends:      haskell98+                        , base >= 4 && < 5+                        , layout >= 0.0.0.1+                        , hinduce-missingh >= 0.0.0.0+    Exposed-Modules:    Data.HInduce.Classifier+                        Data.HInduce.Classifier.Class+    Hs-Source-Dirs:     src+    Extensions:	        MultiParamTypeClasses, FunctionalDependencies
+ src/Data/HInduce/Classifier.hs view
@@ -0,0 +1,63 @@+-- | In machine learning and pattern recognition, classification+-- refers to an algorithmic procedure for assigning a given piece of+-- input data into one of a given number of categories. An example+-- would be assigning a given email into “spam” or “non-spam” classes+-- or assigning a diagnosis to a given patient as described by+-- observed characteristics of the patient (gender, blood pressure,+-- presence or absence of certain symptoms, etc.). An algorithm that+-- implements classification, especially in a concrete implementation,+-- is known as a classifier. The term “classifier” sometimes also+-- refers to the mathematical function, implemented by a+-- classification algorithm, that maps input data to a category.+-- (<https://en.wikipedia.org/wiki/Classification_in_machine_learning>,+-- Nov 28 2011)++module Data.HInduce.Classifier+       ( module Data.HInduce.Classifier.Class+       , confusion, confusion'+       , absConfusion, absConfusion'+       ) where+import Control.Arrow+import Data.HInduce.Classifier.Class+import Data.List.HIUtils+import Text.Layout+import Ratio++-- | A confusion matrix, represented sparsely as an association list.+--+-- Keys are (realLabel, classificationLabel) :: (label, label)+newtype Confusion label = Confusion { fromConfusion :: [((label, label), Int)] }+        deriving (Eq, Ord, Read, Show)++-- | Calculate the confusion matrix of a classifier. Prefer @confusion'@ in ghci.+confusion  :: (Classifier classifier attributes label,+               Ord label,+               Fractional f) =>+              classifier -> [(attributes, label)] -> [((label, label), f)]+confusion cl db = map (second (fromRational . (% s) . fromIntegral)) absconf+  where absconf = absConfusion cl db+        s = fromIntegral . sum . map snd $ absconf++-- | Calculate the confusion matrix of a classifier, showing numbers of occurance instead of relative frequencies. Prefer @absConfusion'@ in ghci.+absConfusion :: ( Classifier classifier attributes label+                , Ord label+                ) =>+        classifier -> [(attributes, label)] -> [((label, label), Int)]+absConfusion cl = count . aggregate . toLabelpairs+  where toLabelpairs = map (snd &&& classify cl . fst)+        count = map (head &&& length)++-- | Like @confusion@, but puts it in a nice table.+confusion' :: ( Classifier classifier attributes label+                , Ord label, Show label+                ) =>+                classifier -> [(attributes, label)] -> Table label label Double+confusion' cl db = Table "Confusion Matrix" ("Actual", "Predicted") $ confusion cl db+++-- | Like @absConfusion@, but puts it in a nice table.+absConfusion' :: ( Classifier classifier attributes label+                , Ord label, Show label+                ) =>+                classifier -> [(attributes, label)] -> Table label label Int+absConfusion' cl db = Table "Absolute Confusion Matrix" ("Actual","Predicted") $ absConfusion cl db
+ src/Data/HInduce/Classifier/Class.hs view
@@ -0,0 +1,6 @@+module Data.HInduce.Classifier.Class+       where++class Classifier classifier attributes label +                       | classifier -> attributes label where+  classify :: classifier -> attributes -> label