LoginSignup
0
1

More than 3 years have passed since last update.

【Julia入門】JuliaでRDatasets.jlしてMLLabelUtils.jlを活用しつつXGBoost.jlする

Posted at

概要

irisをxgboostする意義はありません。

環境

julia version 1.5.3
"RDatasets" => v"0.7.3"
"MLLabelUtils" => v"0.5.5"
"XGBoost" => v"1.1.1"

>import Pkg.add.(["RDatasets", "MLLabelUtils", "XGBoost"])

(Plutoでやりました)

データセット準備

using RDatasets
iris = dataset("datasets", "iris")

train_Y = convertlabel(LabelEnc.Indices{Int},iris.Species) #Speciesをlabel encoding

train_X = select!(iris, Not(:Species)) #Speciesを抜く
train_X = convert(Matrix,train_X) #arrayに

XGBoost

bst = xgboost(train_X, num_round = 2, label = train_Y, eta = 1, max_depth = 2)
pred = predict(bst, train_X)

Julia基礎

変数型確認

> typeof(array)
Array{Float64,1}

arrayの長さ

> size(array)[1]
150

unique

> unique(array)
Int64[1,2,3]

count

> countmap(array)
Dict(2⇒50,3⇒50,1⇒50)

arrayの中から特定の値を数える

> length(array[array .> 2.5])
50

array各要素にround

> array1 = [round.(x) for x in array]

dataframeからcolumnをarrayで抜く

> df.column_name

train_test_split

> using MLDataUtils
> train, test = splitobs(X, at = 0.7)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1