Skip to content

Commit

Permalink
remove z-score (not needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Oct 12, 2023
1 parent a4aa313 commit 9e11476
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions code/nbc.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
function naivebayes(y::Vector{Bool}, X::Matrix{T}; presence=0.5) where {T <: Number}
μ = mapslices(mean, X, dims=1)
σ = mapslices(std, X, dims=1)
Xpos = (X[findall(y),:] .- μ) ./ σ
Xneg = (X[findall(.!y),:] .- μ) ./ σ
Xpos = X[findall(y),:]
Xneg = X[findall(.!y),:]
pred_pos = mapslices(x -> Normal(mean(x), std(x)), Xpos, dims=1)
pred_neg = mapslices(x -> Normal(mean(x), std(x)), Xneg, dims=1)
function inner_predictor(v::Vector{TN}) where { TN <: Number }
nv = (v' .- μ) ./ σ
is_pos = prod(pdf.(pred_pos, nv))
is_neg = prod(pdf.(pred_neg, nv))
is_pos = prod(pdf.(pred_pos, v))
is_neg = prod(pdf.(pred_neg, v))
evid = presence * is_pos + (1 - presence) * is_neg
return (presence * is_pos)/evid
end
Expand Down

0 comments on commit 9e11476

Please sign in to comment.