Skip to content

Commit 1e15fef

Browse files
committed
work on first milestone complete
1 parent 96896b1 commit 1e15fef

File tree

3 files changed

+72
-41
lines changed

3 files changed

+72
-41
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,36 @@
33

44
(provide total count average standard-deviation min max filiter)
55

6+
(provide same-class)
7+
(provide remove-last)
8+
(provide filter-last-csv)
9+
(provide str-to-num-lst strlst-to-numlsts)
10+
611
;;data helper functions
712
(define (same-class class1 class2)
813
(string=? class1 class2))
914

15+
; function to remve last element from list, needed to remove class from iris csv to form a array
16+
; and to remove the last element
17+
(define (remove-last lst)
18+
(reverse (cdr (reverse lst))))
19+
20+
; function that takes a list of lists, will remove the last list in the first level and final element
21+
; of all other lists
22+
(define (filter-last-csv lst-of-lsts)
23+
(define remove-last-lst (remove-last lst-of-lsts))
24+
(map (lambda (x) (remove-last x)) remove-last-lst))
25+
26+
; converts a list of strings to numbers recursivly
27+
(define (str-to-num-lst items)
28+
(if (null? items)
29+
'()
30+
(cons (string->number (car items))
31+
(str-to-num-lst (cdr items)))))
32+
33+
; converts a list of lists of strings to numbers using a mapping of the str-to-num-lst function
34+
(define (strlst-to-numlsts lst-of-str)
35+
(map (lambda (x) (str-to-num-lst x)) lst-of-str))
1036

1137
;;Data manipluation functions
1238

@@ -70,7 +96,9 @@
7096
;;> (standard-deviation(remove-last iris-raw) petal-width "Iris-virginica")
7197
(define standard-deviation
7298
(lambda (data parm [class-t "none"])
73-
(sqrt (/ (foldr (lambda (x y) (+ (expt (- (string->number (parm x)) (average data parm class-t)) 2) y)) 0 data)
99+
(sqrt (/ (foldr
100+
(lambda (x y)
101+
(+ (expt (- (string->number (parm x)) (average data parm class-t)) 2) y)) 0 data)
74102
(total data parm class-t)))))
75103

76104
(define min

graphs.rkt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@
1919
list-of-points
2020
(begin
2121
(set! count (+ count 1))
22-
(points-ceator (cdr list-of-datasets) col1 col2 (cons (points(foldr (lambda(x y) (cons (vector (string->number (col1 x)) (string->number (col2 x))) y)) '() (car list-of-datasets)) #:color count) list-of-points)))))
23-
(plot (points-ceator list-of-datasets col1 col2 '()))))
22+
(points-ceator (cdr list-of-datasets) col1 col2
23+
(cons (points
24+
(foldr (lambda(x y)
25+
(cons
26+
(vector
27+
(string->number (col1 x))
28+
(string->number (col2 x))) y))
29+
'() (car list-of-datasets))
30+
#:color count) list-of-points)))))
31+
(plot (points-ceator list-of-datasets col1 col2 '()))))

pca.rkt

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,48 @@
33
(require net/url)
44
(require csv-reading)
55
(require math/array)
6+
(require math/matrix)
67
(require plot)
8+
9+
; require custom functions
710
(require "graphs.rkt")
8-
(require "data-filitering.rkt")
11+
(require "data-filtering.rkt")
912

1013
;; define list of iris data directly from url
1114
(define iris-url "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data")
1215
(define iris-raw ((compose csv->list get-pure-port string->url) iris-url))
1316

14-
; function to remve last element from list, needed to remove class from iris csv to form a array
15-
; and to remove the last element
16-
(define (remove-last lst)
17-
(reverse (cdr (reverse lst))))
17+
; converts iris csv to a list with just numbers (stored as string), drops the last cololmn in a list
18+
; of lists
19+
(define iris-raw-num-str (filter-last-csv iris-raw))
1820

19-
; function that takes a list of lists, will remove the last list in the first level and final element
20-
; of all other lists
21-
(define (filter-last-csv lst-of-lsts)
22-
(define remove-last-lst (remove-last lst-of-lsts))
23-
(map (lambda (x) (remove-last x)) remove-last-lst))
21+
; create a mutable NxM array of the iris dataset
22+
(define iris-array (list*->array (strlst-to-numlsts iris-raw-num-str) number?))
2423

25-
; converts iris csv to a list with just numbers (stored as string)
26-
(define iris-raw-num-str (filter-last-csv iris-raw))
24+
; calculate mean and standard diviation
25+
(define iris-mean 0)
2726

28-
; converts a list of strings to numbers recursivly
29-
(define (str-to-num-lst items)
30-
(if (null? items)
31-
'()
32-
(cons (string->number (car items))
33-
(str-to-num-lst (cdr items)))))
27+
(define iris-std 0)
3428

35-
; converts a list of lists of strings to numbers using a mapping of the str-to-num-lst function
36-
(define (strlst-to-numlsts lst-of-str)
37-
(map (lambda (x) (str-to-num-lst x)) lst-of-str))
29+
; function that takes a NXM array and standardizes the values (z = (x - mean) / std)
30+
(define (standardize-matrix n) 0)
31+
32+
; calculate mean vector (mean of z)
33+
(define mean-vector 0)
34+
35+
; create N X N matrix of containing covariance of all properties
36+
(define co-variance-matrix 0)
37+
38+
; calculate eigenvectors and eigenvalues
39+
(define eigenvalues 0)
40+
(define eigenvectors 0)
41+
42+
; use eigenvectors with the 2 or 3 highest eigenvalues to create projection matrix
43+
44+
; take dot product of z and projection matrix
45+
46+
; plot with result of dot product
3847

39-
; finally create a mutable NxM array of the iris dataset
40-
(define iris-array (list*->array (strlst-to-numlsts iris-raw-num-str) number?))
4148

4249
; quick test of 3d plot
4350
;(plot3d (points3d (array->list* iris-array))
@@ -71,7 +78,6 @@
7178
(lambda (x)
7279
x))
7380

74-
7581
;;TODO
7682
;;Plot a 3d graph plot graph
7783
;;Make a linear regression
@@ -86,17 +92,6 @@
8692

8793

8894
;;Some test data set for ploting
89-
(define Iris-virginica (filiter (remove-last iris-raw) petal-width identity "Iris-virginica"))
90-
(define Iris-versicolor (filiter (remove-last iris-raw) petal-width identity "Iris-versicolor"))
91-
(define Iris-setosa (filiter (remove-last iris-raw) petal-width identity "Iris-setosa"))
92-
93-
94-
95-
96-
97-
98-
99-
100-
101-
102-
95+
;(define Iris-virginica (filiter (remove-last iris-raw) petal-width identity "Iris-virginica"))
96+
;(define Iris-versicolor (filiter (remove-last iris-raw) petal-width identity "Iris-versicolor"))
97+
;(define Iris-setosa (filiter (remove-last iris-raw) petal-width identity "Iris-setosa"))

0 commit comments

Comments
 (0)