-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjulia_example.jl
39 lines (27 loc) · 910 Bytes
/
julia_example.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
37
38
39
#hello.jl
# Below is the first time I was really working with Julia
# Built models with sklearn and plotted with ggplot
# using DataFrames
using RDatasets
iris = dataset("datasets", "iris")
# ScikitLearn.jl expects arrays, but DataFrames can also be used - see
# the corresponding section of the manual
X = convert(Array, iris[[:SepalLength, :SepalWidth, :PetalLength, :PetalWidth]])
y = convert(Array, iris[:Species])
using ScikitLearn
using ScikitLearn: fit!, predict
@sk_import line
ar_model: LogisticRegression
# Then fit the model
model = LogisticRegression(fit_intercept=true)
fit!(model, X, y)
accuracy = sum(predict(model, X) .== y) / length(y)
println("accuracy: $accuracy")
# Then, lets try to plot some stuff
using RCall
R"library(ggplot2);
ggplot($iris, aes(x=SepalLength, y=SepalWidth, color=Species)) + geom_point()"
a = 2
R"multiply <- function(x) x * $a"
@rget multiply
multiply(4)