Julia始めました vol.2
Juliaでデータ分析する
データ分析で有名なirisデータを読み込む
PythonのScikitLearnからirisを読み込むときと同様にJuliaでもScikitLearnから読み込むことができる
RDatasetsから読み込むことでdf形式で読み込むこむことができる
using RDatasets using RCall using Gadfly
RDatasetsの中身を確認する
RDatasets.packages()
irisデータを読み込む
iris = dataset("datasets", "iris")
データの要約を確認
describe(iris)
データの中身を確認するためにhead(df)が用いられるが、Juliaではhead(df)からfirst(df, 6)に置き換わったらしい
julia> first(iris, 6) 6×5 DataFrame │ Row │ SepalLength │ SepalWidth │ PetalLength │ PetalWidth │ Species │ │ │ Float64 │ Float64 │ Float64 │ Float64 │ Categorical… │ ├─────┼─────────────┼────────────┼─────────────┼────────────┼──────────────┤ │ 1 │ 5.1 │ 3.5 │ 1.4 │ 0.2 │ setosa │ │ 2 │ 4.9 │ 3.0 │ 1.4 │ 0.2 │ setosa │ │ 3 │ 4.7 │ 3.2 │ 1.3 │ 0.2 │ setosa │ │ 4 │ 4.6 │ 3.1 │ 1.5 │ 0.2 │ setosa │ │ 5 │ 5.0 │ 3.6 │ 1.4 │ 0.2 │ setosa │ │ 6 │ 5.4 │ 3.9 │ 1.7 │ 0.4 │ setosa │
次にプロットする
plot(iris, x = "SepalWidth", y = "SepalLength", color="Species")
重回帰分析をする
using GLM lm1 = lm(@formula(PetalWidth ~ PetalLength) , iris) pre = predict(lm1)