-
Notifications
You must be signed in to change notification settings - Fork 1
/
data-representation-abstraction.rkt
62 lines (45 loc) · 1.51 KB
/
data-representation-abstraction.rkt
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#lang racket
(require "utils.rkt")
(provide (all-defined-out))
(define (data-empty? data)
(empty? data))
(define (data-first data)
(car data))
(define (data-rest data)
(cdr data))
(define (data-range data start end)
(list-range data start end))
(define (data-length data)
(length data))
(define (data-point-length data-point)
(vector-length data-point))
(define (data-filter predicate data)
(filter predicate data))
(define (data-partition predicate data)
(partition predicate data))
(define (data-map procedure data)
(map procedure data))
(define (data-take data n)
(take data n))
(define (data-drop data n)
(drop data n))
(define (data-get-col data col-index)
(data-map (lambda (data-point)
(data-point-get-col data-point col-index))
data))
(define (data-point-get-col data-point col-index)
(vector-ref data-point col-index))
(define (data-point-take-features data-point n-features)
(vector-take data-point n-features))
(define (labels-elements-equal? subset)
(with-handlers ([exn:fail:contract:arity?
(lambda (exception)
(< (data-length subset) 2))])
(apply = subset)))
(define (data-majority-prediction data label-column-index)
(let-values ([(part1 part2)
(data-partition (lambda (data-point)
(= (data-point-get-col data-point label-column-index) 0))
data)])
(cond [(> (data-length part2) (data-length part1)) 1]
[else 0])))