概要
https://qiita.com/chezou/items/d090f26dcb31818d6964
にも同様の記事がありますが、Julia-1.0でirisデータのプロットや線形回帰など初歩的な処理をやってみます。
環境
Julia Version 1.0.0
Commit 5d4eaca0c9 (2018-08-08 20:58 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: AMD E2-3000M APU with Radeon(tm) HD Graphics
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, generic)
使用パッケージは以下。
using RDatasets # irisデータ読み込み用
using Plots, StatPlots
using GLM # 線形回帰
データ取得
これだけ。
iris = dataset("datasets","iris");
DataFrame形式で読み込まれます。
プロット
プロットバックエンドはpyplotを使います。他のGRとかplotlyとかは、軸ラベルが表示されなかったりとか、まだちょっと使えない印象。
pyplot()
Plots.PyPlotBackend()
エラーが出たときは、パッケージが足りてないので足します。PyCallとかLaTeXStringsとか。
PyCallはbuildしなおさないとだめみたい。
@df iris scatter(:PetalLength, :PetalWidth, group=:Species, legend=:bottomright, markerstrokecolor=:auto)
title!("iris petal plot")
xaxis!("PetalLength")
yaxis!("PetalWidth")
markerstrokecolor=:autoをつけることで、マーカーの縁が黒でなくfillカラーと同じになって見やすい。
線形回帰
GLMを使ってRみたいにモデル式を記入します。
lm1 = lm(@formula(PetalWidth ~ PetalLength), iris)
StatsModels.DataFrameRegressionModel{LinearModel{LmResp{Array{Float64,1}},DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}},Array{Float64,2}}
Formula: PetalWidth ~ 1 + PetalLength
Coefficients:
Estimate Std.Error t value Pr(>|t|)
(Intercept) -0.363076 0.039762 -9.13122 <1e-15
PetalLength 0.415755 0.00958244 43.3872 <1e-85
predictで回帰線プロット用のデータを作ります。
pre = predict(lm1)
plot!(iris[:PetalLength],pre,label="predict")
残念ながら予想範囲計算の:predintはまだ実装されてないようです。
ソースコードに
interval_type == :confint || error("only :confint is currently implemented") #:predint will be implemented
と書いてあります。
Gist
jupyter notebookをgistにあげておきます。
https://gist.github.com/Yoshinobu-Ishizaki/01bf9ce2ca11322a458d761f0ca824c5

