-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.jl
36 lines (30 loc) · 1.15 KB
/
app.jl
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
using Clustering
import RDatasets: dataset
import DataFrames
using GenieFramework
@genietools
const data = DataFrames.insertcols!(dataset("datasets", "iris"), :Cluster => zeros(Int, 150))
features = [:SepalLength, :SepalWidth, :PetalLength, :PetalWidth]
function cluster(no_of_clusters=3, no_of_iterations=10)
feats = Matrix(data[:, [c for c in features]])' |> collect
result = kmeans(feats, no_of_clusters; maxiter=no_of_iterations)
data[!, :Cluster] = assignments(result)
end
@handlers begin
@out features
@in no_of_clusters = 3
@in no_of_iterations = 10
@in xfeature = :SepalLength
@in yfeature = :SepalWidth
@out datatable = DataTable()
@out datatablepagination = DataTablePagination(rows_per_page=50)
@out irisplot = PlotData[]
@out clusterplot = PlotData[]
@onchange isready, xfeature, yfeature, no_of_clusters, no_of_iterations begin
cluster(no_of_clusters, no_of_iterations)
datatable = DataTable(data)
irisplot = plotdata(data, xfeature, yfeature; groupfeature=:Species)
clusterplot = plotdata(data, xfeature, yfeature; groupfeature=:Cluster)
end
end
@page("/", "app.jl.html")