File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -52,14 +52,23 @@ testSet.[..4]
52
52
( digit.Pixels |> classifyByNearest 3 ))
53
53
54
54
(******* 8. EVALUATING THE MODEL AGAINST VALIDATION DATA *******)
55
- let calculateAccuracyWithNearest k =
56
- testSet
55
+ let calculateAccuracyWithNearest k dataSet =
56
+ dataSet
57
57
|> Array.averageBy ( fun digit ->
58
58
if digit.Pixels |> classifyByNearest k = digit.Label then 1.0
59
59
else 0.0 )
60
60
61
+ (******* 9. GET AN IDEA ABOUT A GOOD RANGE OF K *******)
61
62
let predictionAccuracy =
62
63
[ 1 ; 3 ; 9 ; 27 ]
63
- |> List.map ( fun k -> ( k, calculateAccuracyWithNearest k))
64
+ |> List.map ( fun k -> ( k, crossValidationSet |> calculateAccuracyWithNearest k))
64
65
65
66
Chart.Line predictionAccuracy
67
+
68
+ (******* 10. FIND THE BEST K *******)
69
+ let bestK =
70
+ [ 1 .. 20 ]
71
+ |> List.maxBy ( fun k -> crossValidationSet |> calculateAccuracyWithNearest k)
72
+
73
+ (******* 11. THE FINAL RESULT! *******)
74
+ testSet |> calculateAccuracyWithNearest bestK
You can’t perform that action at this time.
0 commit comments