Skip to content

Commit

Permalink
update pkgs and re-run codes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mhamdi committed Dec 7, 2024
1 parent 2985210 commit 8a2ba9a
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Codes/Julia/Part-2/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
MLJClusteringInterface = "d354fa79-ed1c-40d4-88ef-b8c7bd1568af"
MLJDecisionTreeInterface = "c6f25543-311c-4c74-83dc-3ea6d1015661"
MLJLIBSVMInterface = "61c7150f-6c77-4bb1-949c-13197eac2a52"
MLJLinearModels = "6ee0df7b-362f-4a72-a706-9e79364fb692"
NearestNeighborModels = "636a865e-7cf4-491e-846c-de09b730eb36"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
3 changes: 2 additions & 1 deletion Codes/Julia/Part-2/decision-tree-classification.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
##################################
#= DECISION TREE CLASSIFICATION =#
##################################
# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
using CSV, DataFrames
using CSV, DataFrames, Plots
using MLJ

md"Read dataset and assign it `df`"
Expand Down
1 change: 1 addition & 0 deletions Codes/Julia/Part-2/decision-tree-regression.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
##############################
#= DECISION TREE REGRESSION =#
##############################
# `versioninfo()` -> 1.11.1

using Markdown

Expand Down
7 changes: 4 additions & 3 deletions Codes/Julia/Part-2/gradient-descent.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###########################################
# IMPLEMENTING GRADIENT DESCENT ALGORITHM #
###########################################
# `versioninfo()` -> 1.11.1

using Markdown
md"**NORMAL EQUATION**"
Expand All @@ -25,7 +26,7 @@ for _ in 1:1_000 # RUN IT MULTIPLE TIMES TO CONVERGE
for k in shuffle(1:5)
cost = ( y[k] - X[k, :]' * θ )^2
push!(J, cost);
θ += α * (y[k] - X[k, :]' * θ) * X[k, :]
global θ += α * (y[k] - X[k, :]' * θ) * X[k, :]
println("θ is $(θ)")
end
end
Expand All @@ -39,10 +40,10 @@ for _ in 1:1_000
ϵ = (y-X*θ)[:, 1]
cost = (2*n)\ ϵ'*ϵ
push!(J, cost)
θ += n\α * sum((y - X * θ) .* X, dims=1)'
global θ += n\α * sum((y - X * θ) .* X, dims=1)'
println("θ is $(θ)")
end

plot(J)

md"TO DO: Add Regularization Term To Cost Function"
md"TO DO: Add Regularization Term To Cost Function"
3 changes: 2 additions & 1 deletion Codes/Julia/Part-2/kmeans.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
############
#= KMEANS =#
############
# `versioninfo()` -> 1.11.1

using Markdown

Expand Down Expand Up @@ -31,7 +32,7 @@ kmeans_ = KMeans(k=5)
md"You may want to see [Clustering.jl](https://github.com/JuliaStats/Clustering.jl) and the unwrapped model type [`Clustering.KMeans`](@ref)."

md"Train & regroup into clusters"
kmeans = machine(kmeans_, table(X)) |> fit!
kmeans = machine(kmeans_, X) |> fit!

md"Clusters & centroids"
centroids = fitted_params(kmeans).centers
Expand Down
9 changes: 8 additions & 1 deletion Codes/Julia/Part-2/knn.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#########################
#= k-NEAREST NEIGHBORS =#
#########################
# `versioninfo()` -> 1.11.1

using Markdown

Expand Down Expand Up @@ -49,5 +50,11 @@ ŷ = predict_mode(pipe, Xtest)
md"Confusion Matrix"
confusion_matrix(ŷ, ytest)

md"Evaluation Metrics"
accuracy(ŷ, ytest)
specificity(ŷ, ytest) # specificity, true negative rate: TN/(TN+FP)
sensitivity(ŷ, ytest) # sensitivity, true positive rate: TP/(TP+FN)
f1score(ŷ, ytest)

md"We can estimate the performance of `pipe` through the `evaluate!` command."
evaluate!(pipe, operation=predict_mode, measures=[accuracy, precision, recall, f1score])
evaluate!(pipe, operation=predict)
9 changes: 5 additions & 4 deletions Codes/Julia/Part-2/logistic-regression.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#########################
#= LOGISTIC REGRESSION =#
#########################
# `versioninfo()` -> 1.11.1

using Markdown

Expand All @@ -15,7 +16,7 @@ schema(df)
coerce!(df,
:Age => Continuous,
:EstimatedSalary => Continuous,
:Purchased => Multiclass)
:Purchased => OrderedFactor)
schema(df)

md"Unpack features & target"
Expand Down Expand Up @@ -55,9 +56,9 @@ confusion_matrix(ŷ, ytest)

md"Evaluation Metrics"
accuracy(ŷ, ytest)
precision(ŷ, ytest)
recall(ŷ, ytest)
specificity(ŷ, ytest) # specificity, true negative rate: TN/(TN+FP)
sensitivity(ŷ, ytest) # sensitivity, true positive rate: TP/(TP+FN)
f1score(ŷ, ytest)

md"We can estimate, more elegantly, the performance of `pipe` through the `evaluate!` command."
evaluate!(pipe, operation=predict_mode, measures=[accuracy, precision, recall, f1score])
evaluate!(pipe, operation=predict)
1 change: 1 addition & 0 deletions Codes/Julia/Part-2/ml-workflows.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###########################################
#= COMMON DATA PREPROCESSING `WORKFLOWS` =#
###########################################
# `versioninfo()` -> 1.11.1

using Markdown

Expand Down
1 change: 1 addition & 0 deletions Codes/Julia/Part-2/multivariable-regression.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#####################################
#= MULTIVARIABLE LINEAR REGRESSION =#
#####################################
# `versioninfo()` -> 1.11.1

using Markdown

Expand Down
2 changes: 2 additions & 0 deletions Codes/Julia/Part-2/polynomial-regression.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
##################################
#= POLYNOMIAL LINEAR REGRESSION =#
##################################
# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
Expand Down
5 changes: 3 additions & 2 deletions Codes/Julia/Part-2/random-forest-classification.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
##################################
#= RANDOM FOREST CLASSIFICATION =#
##################################
# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
using CSV, DataFrames
using CSV, DataFrames, Plots
using MLJ

md"Read dataset -> `df`"
Expand Down Expand Up @@ -33,4 +34,4 @@ rfc = machine(rfc_, x, y) |> fit!
md"You may want to see [DecisionTree.jl](https://github.com/bensadeghi/DecisionTree.jl) and the unwrapped model type [`MLJDecisionTreeInterface.DecisionTree.RandomForestClassifier`](@ref)."

md"Evaluate the model"
evaluate!(rfc)
evaluate!(rfc)
4 changes: 2 additions & 2 deletions Codes/Julia/Part-2/random-forest-regression.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
##############################
#= DECISION TREE REGRESSION =#
##############################
# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
using CSV, D
ataFrames
using CSV, DataFrames
using MLJ

md"Load data from CSV file"
Expand Down
2 changes: 2 additions & 0 deletions Codes/Julia/Part-2/simple-regression-1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
##############################
# SALARY vs. YEARSEXPERIENCE #

# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
Expand Down
4 changes: 3 additions & 1 deletion Codes/Julia/Part-2/simple-regression-2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#######################
# WEIGHT vs. HEIGHT #

# `versioninfo()` -> 1.11.1

using Markdown

md"Import librairies"
Expand Down Expand Up @@ -42,4 +44,4 @@ md"Metric"
println("Error is $(sum( (yhat .- ytest).^2 ) ./ length(ytest) )")

scatter(xtest, ytest, label=:none)
scatter!(xtest, yhat, label=:none)
scatter!(xtest, yhat, label=:none)
11 changes: 9 additions & 2 deletions Codes/Julia/Part-2/svc.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###############################################
#= SUPPORT VECTOR MACHINE FOR CLASSIFICATION =#
###############################################
# `versioninfo()` -> 1.11.1

using Markdown

Expand All @@ -17,7 +18,7 @@ schema(df)
coerce!(df,
:Age => Continuous,
:EstimatedSalary => Continuous,
:Purchased => Multiclass)
:Purchased => OrderedFactor)
schema(df)

md"Unpack features & target"
Expand Down Expand Up @@ -49,5 +50,11 @@ ŷ = predict(pipe, Xtest)
md"Confusion Matrix"
confusion_matrix(ŷ, ytest)

md"Evaluation Metrics"
accuracy(ŷ, ytest)
specificity(ŷ, ytest) # specificity, true negative rate: TN/(TN+FP)
sensitivity(ŷ, ytest) # sensitivity, true positive rate: TP/(TP+FN)
f1score(ŷ, ytest)

md"We can estimate the performance of `pipe` through the `evaluate!` command."
evaluate!(pipe, operation=predict, measures=[accuracy, precision, recall, f1score])
evaluate!(pipe, operation=predict)

0 comments on commit 8a2ba9a

Please sign in to comment.