Skip to content

Commit

Permalink
🐛 Fix CDDetector including tests and upgrade PyOD (#6)
Browse files Browse the repository at this point in the history
* upgrade to pyod version 2

* fix cd detector

* fix tests to include all models

* upgrade package version

* fix python version to 3.12

* upgrade ci actions

* fix python version to 3.11

* fix ci actions to run only on master push and pr

* change to explicit sklearn python module import

* remove fixed python version again
  • Loading branch information
davnn authored Jan 5, 2025
1 parent cc12a94 commit f0e2984
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 61 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: CI
on:
- push
- pull_request
push:
branches: [ master ]
# pull_request event is required only for autolabeler
pull_request:
types: [ opened, reopened, synchronize ]
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -19,12 +22,12 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
Expand Down
2 changes: 1 addition & 1 deletion CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
channels = ["conda-forge"]

[deps]
pyod = "=1"
pyod = "=2"

[deps.llvmlite]
channel = "numba"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OutlierDetectionPython"
uuid = "2449c660-d36c-460e-a68b-92ab3c865b3e"
authors = ["David Muhr <[email protected]> and contributors"]
version = "0.2.2"
version = "0.2.3"

[deps]
OutlierDetectionInterface = "1722ece6-f894-4ffc-b6be-6ca1174e2011"
Expand Down
2 changes: 2 additions & 0 deletions src/OutlierDetectionPython.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module OutlierDetectionPython
const OD = OutlierDetectionInterface
using PythonCall
const numpy = PythonCall.pynew()
const sklearn_linear = PythonCall.pynew()

function __init__()
PythonCall.pycopy!(numpy, pyimport("numpy"))
PythonCall.pycopy!(sklearn_linear, pyimport("sklearn.linear_model"))
end

include("utils.jl")
Expand Down
5 changes: 2 additions & 3 deletions src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ end
$(make_docs_link("cd"))
"""
@pymodel mutable struct CDDetector <: UnsupervisedDetector
whitening::Bool = true
rule_of_thumb::Bool = false
model::Py = sklearn_linear.LinearRegression()
end

""" COPODDetector(n_jobs = 1)
Expand Down Expand Up @@ -77,7 +76,7 @@ $(make_docs_link("gmm"))
reg_covar::Real = 1e-06::(_ >= 0)
max_iter::Integer = 100::(_ > 0)
n_init::Integer = 1::(_ > 0)
init_params::String = "kmeans"::(_ in ("kemans", "random"))
init_params::String = "kmeans"::(_ in ("kmeans", "random"))
random_state::Union{Nothing,Integer} = nothing
warm_start::Bool = false
end
Expand Down
56 changes: 5 additions & 51 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
using OutlierDetectionPython
using OutlierDetectionTest

models = eval.(OutlierDetectionPython.MODELS)

# Test the metadata of all exported detectors
test_meta.(eval.(OutlierDetectionPython.MODELS))
test_meta.(models)

data = TestData()
run_test(detector) = test_detector(detector, data)

# ABOD
run_test(ABODDetector())

# CBLOF
run_test(CBLOFDetector(random_state=0))

# COF
run_test(COFDetector())

# COPOD
run_test(COPODDetector())

# HBOS
run_test(HBOSDetector())

# IForest
run_test(IForestDetector(random_state=0))

# KNN
run_test(KNNDetector())

# LMDD
run_test(LMDDDetector(random_state=0))

# LOD
run_test(LODADetector())

# LOF
run_test(LOFDetector())

# LOCI
run_test(LOCIDetector())

# MCD
run_test(MCDDetector(random_state=0))

# SVM
run_test(OCSVMDetector())

# PCA
run_test(PCADetector(random_state=0))

# ROD
run_test(RODDetector())

# SOD
run_test(SODDetector())

# SOS
run_test(SOSDetector())
# Test all models with default parameters
run_test.([model() for model in models])

0 comments on commit f0e2984

Please sign in to comment.