Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Moscow Julia Meetup #1 - Julia and ML

Moscow Julia Meetup #1 - Julia and ML

Quick review of Julia language tools for machine learning and data science. Presented by Gleb Ivashkevich at Moscow Julia Meetup #1.

Avatar for Gleb Ivashkevich

Gleb Ivashkevich

April 26, 2019
Tweet

More Decks by Gleb Ivashkevich

Other Decks in Programming

Transcript

  1. using DataFrames, DataFramesMeta, CSV, Statistics train_df = CSV.read("train.csv") # read

    CSV file first(train_df, 5) # head last(train_df, 5) # tail names(train_df) # col names describe(train_df) # describe dataframe train_df[train_df.Fare .> 20, :] # boolean indexing train_df[completecases(train_df, :Age), :] # filter missing values @where(train_df, .!ismissing.(:Age), :Age.> 35)
  2. function get_spouse_name(name::String) cleaned_name = strip(replace(name, r"\(.*\)"=>"")) replace(cleaned_name, "Mrs."=>"Mr.") end disallowmissing!(train_df,

    [:Name]) spouses = @from passenger in train_df begin @where occursin("Mrs.", passenger.Name) @select {passenger.Name, Spouse_Name=get_spouse_name(passenger.Name), passenger.Sex, passenger.Age} @collect DataFrame end
  3. using DecisionTree features, labels = load_data("iris") features = float.(features) labels

    = string.(labels) model = DecisionTreeClassifier(max_depth=2) fit!(model, features, labels) predict(model, [5.9,3.0,5.1,1.9]) predict_proba(model, [5.9,3.0,5.1,1.9]) using ScikitLearn.CrossValidation: cross_val_score accuracy = cross_val_score(model, features, labels, cv=3)
  4. using TensorFlow using Test sess = TensorFlow.Session() x = TensorFlow.constant(Float64[1,2])

    y = TensorFlow.Variable(Float64[3,4]) z = TensorFlow.placeholder(Float64) w = exp(x + z + -y) run(sess, TensorFlow.global_variables_initializer()) res = run(sess, w, Dict(z=>Float64[1,2]))
  5. using Flux model = Chain( Dense(768, 128, σ), LSTM(128, 256),

    LSTM(256, 128), Dense(128, 10), softmax) loss(x, y) = crossentropy(model(x), y) Flux.train!(loss, data, ADAM(...))
  6. function gpu_add(a, b, c) i = (blockIdx().x-1) * blockDim().x +

    threadIdx().x c[i] = a[i] + b[i] return nothing end