-
Notifications
You must be signed in to change notification settings - Fork 3
/
toydata.clj
110 lines (95 loc) · 3.87 KB
/
toydata.clj
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(ns scicloj.metamorph.ml.toydata
(:require
[camel-snake-kebab.core :as csk]
[clojure.java.io :as io]
[tablecloth.api :as tc]
[tech.v3.dataset :as ds]
[tech.v3.dataset.modelling :as ds-mod]))
(defn sonar-ds []
(-> (ds/->dataset
(io/input-stream (io/resource "data/sonar.csv"))
{:header-row? false :file-type :csv})
(tc/rename-columns
(zipmap
(map #(str "column-" %) (range 61))
(concat
(map #(keyword (str "x" %)) (range 60))
[:material])))
(ds-mod/set-inference-target :material)))
(defn diabetes-ds []
(let [data
(-> (io/resource "data/diabetes_data.csv")
(io/input-stream)
(ds/->dataset
{:file-type :csv :separator " " :header-row? false})
(ds/rename-columns
(zipmap
( map #(str "column-" %) (range 10))
[:age :sex :bmi :bp
:s1 :s2 :s3 :s4 :s5 :s6])))
targets
(-> (io/resource "data/diabetes_target.csv")
(io/input-stream)
(ds/->dataset
{:file-type :csv :separator " " :header-row? false})
(ds/rename-columns {"column-0" :disease-progression})
(ds/update-column :disease-progression (fn [col] (map #(Integer/valueOf (Math/round %)) col))))]
(->
(ds/add-column data (:disease-progression targets))
(ds-mod/set-inference-target :disease-progression))))
(defn iris-ds []
(-> (io/resource "data/iris.csv")
(io/input-stream)
(ds/->dataset
{:file-type :csv :header-row? false :n-initial-skip-rows 1})
(ds/rename-columns
(zipmap
( map #(str "column-" %) (range 5))
[:sepal_length :sepal_width
:petal_length :petal_width
:species]))
(ds-mod/set-inference-target :species)
(ds/categorical->number [:species] {} :int16)))
(defn breast-cancer-ds []
(let [col-names (mapv csk/->kebab-case-keyword
["mean radius" "mean texture"
"mean perimeter" "mean area"
"mean smoothness" "mean compactness"
"mean concavity" "mean concave points"
"mean symmetry" "mean fractal dimension"
"radius error" "texture error"
"perimeter error" "area error"
"smoothness error" "compactness error"
"concavity error" "concave points error"
"symmetry error" "fractal dimension error"
"worst radius" "worst texture"
"worst perimeter" "worst area"
"worst smoothness" "worst compactness"
"worst concavity" "worst concave points"
"worst symmetry" "worst fractal dimension"])]
(-> (io/resource "data/breast_cancer.csv")
(io/input-stream)
(ds/->dataset
{:file-type :csv :header-row? false
:n-initial-skip-rows 1})
(ds/rename-columns
(zipmap
( map #(str "column-" %) (range 31))
(conj col-names :class)))
(ds/update-column :class (fn [col] (map #(case %
0 :malignant
1 :benign)
col)))
(ds/categorical->number [:class] {} :int16)
(ds-mod/set-inference-target :class))))
(defn titanic-ds-split []
{:train
(->
(io/resource "data/titanic-train.nippy")
(io/input-stream)
(ds/->dataset {:file-type :nippy}))
:test
(->
(io/resource "data/titanic-test.nippy")
(io/input-stream)
(ds/->dataset {:file-type :nippy}))})