Example usage

Open
#87 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
julia
Domain
documentation

Research direction

Start by reviewing the Julia example in the issue body, including the elastic_net_logistic_regression, train, and generate_predictions functions. Clarify where this example should be documented and what changes are wanted; done means the agreed usage example is added or revised in that location.

Written by the indexing model from the issue text.

Description

`
using DelimitedFiles
using MLJLinearModels

#############################################
'''
wrapper for the logistic regression function with elastic
net penalty provided by MLJLinearModels
'''
#############################################
function elastic_net_logistic_regression(Z::Matrix{Float64},
y::Vector{Float64},
λ::Float64 = 1.0,
α::Float64 = 0.0)
model = LogisticRegression(λ, α, penalty=:en)
return MLJLinearModels.fit(model, Z, y)
end

#############################################
'''
as MLJLinearModels require the labels to be +1, -1 instead
of 0, +1, the following code will read the data and the
labels (0, +1). Then it shall convert the labels to +1, -1
'''
#############################################
M = readdlm("train_data.txt", Float64)
n, m = size(M)
X = Matrix(M[1:n,1:m-1])
y = M[1:end,m:end][:]
z = copy(y) # z shall be the vector of labels
for i = 1:n
if y[i] == 0.0
z[i] = -1.0
end
end

#############################################
'''
compute the parameter vector on the training data
'''
#############################################
function train(X, y)
m, n = size(X)
β_bar = elastic_net_logistic_regression(X, y, 0.0, 0.0)[1:n] # ignore the intercept
return β_bar
end

#############################################
'''
make predictions after training
'''
#############################################
function generate_predictions(X, β)
n, m = size(X)
pred_y = zeros(n)
for i = 1:n
p = sigmoid(X[i,:], β)
if isinf(p)
println("error. sigmoid returned Inf")
end
if p >= 0.5
pred_y[i] = 1.0
else
pred_y[i] = -1.0
end
end
return pred_y
end

`

Dominant language
Julia
Stars
86
Forks
16
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaAI/MLJLinearModels.jl

All issues in JuliaAI/MLJLinearModels.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.