forked from solresol/padiclinear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scoring.lhs
31 lines (29 loc) · 1.15 KB
/
Scoring.lhs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
> module Scoring where
> import Data.List
> import Data.Maybe
> import WordNeighbourhood
> import MachineLearning
>
> onefoldCrossValidateResults :: Eq b => UntrainedPredictor a b -> [(a,b)] -> [(a,b,b,Bool)]
>
> ([(a,b)] -> a -> b) -> [(a,b)] -> [(a,b,b,Bool)]
> onefoldCrossValidateResults f pairs = map eval1 (onefold pairs)
> where
> eval1 ((testX, testY),train)
> | y_hat == testY = (testX, testY, y_hat, True)
> | otherwise = (testX, testY, y_hat, False)
> where y_hat = f train testX
>
> onefoldCrossValidateSummary :: Eq b => ([(a,b)] -> a -> b) -> [(a,b)] -> Int
> onefoldCrossValidateSummary f pairs = sum (map eval2 results)
> where
> results = onefoldCrossValidateResults f pairs
> eval2 (_,_,_,False) = 0
> eval2 (_,_,_,True) = 1
>
> type LanguageAlgorithm = [(String, String)] -> String -> String
> scoreLocalRegionThenAlgo :: NeighbourhoodFinder -> LanguageAlgorithm -> [(String,String)] -> [(String, String, String, Bool)]
> scoreLocalRegionThenAlgo nf algo dataset = onefoldCrossValidateResults algo' dataset
> where algo' trainingset testword
> localneighbourhood = nf trainingset testword
>