Skip to content

Commit

Permalink
update deprecated binom_test (#426)
Browse files Browse the repository at this point in the history
* updated deprecated function name

* fix roc print output

* fix roc print output

* fix path check test on windows

* Remove sphinx napoleon as it's included with sphinx now

* Fix random seeds for reproducible testing

---------

Co-authored-by: ejolly <[email protected]>
  • Loading branch information
ljchang and ejolly authored Mar 27, 2024
1 parent 93632d2 commit 5445c01
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx.ext.mathjax",
"sphinxcontrib.napoleon",
"sphinx_gallery.gen_gallery",
]

Expand Down
10 changes: 6 additions & 4 deletions nltools/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import pandas as pd
import numpy as np
from nltools.plotting import roc_plot
from scipy.stats import norm, binom_test
from scipy.stats import norm, binomtest
from sklearn.metrics import auc
from copy import deepcopy


class Roc(object):

"""Roc Class
The Roc class is based on Tor Wager's Matlab roc_plot.m function and
Expand Down Expand Up @@ -233,7 +232,7 @@ def calculate(

# Calculate p-Value using binomial test (can add hierarchical version of binomial test)
self.n = len(self.misclass)
self.accuracy_p = binom_test(int(np.sum(~self.misclass)), self.n, p=0.5)
self.accuracy_p = binomtest(int(np.sum(~self.misclass)), self.n, p=0.5)
self.accuracy_se = np.sqrt(
np.mean(~self.misclass) * (np.mean(~self.misclass)) / self.n
)
Expand Down Expand Up @@ -318,7 +317,10 @@ def summary(self):
print("------------------------")
print("{:20s}".format("Accuracy:") + "{:.2f}".format(self.accuracy))
print("{:20s}".format("Accuracy SE:") + "{:.2f}".format(self.accuracy_se))
print("{:20s}".format("Accuracy p-value:") + "{:.2f}".format(self.accuracy_p))
print(
"{:20s}".format("Accuracy p-value:")
+ "{:.2f}".format(self.accuracy_p.pvalue)
)
print("{:20s}".format("Sensitivity:") + "{:.2f}".format(self.sensitivity))
print("{:20s}".format("Specificity:") + "{:.2f}".format(self.specificity))
print("{:20s}".format("AUC:") + "{:.2f}".format(self.auc))
Expand Down
4 changes: 4 additions & 0 deletions nltools/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@pytest.fixture(scope="module", params=["2mm"])
def sim_brain_data():
np.random.seed(0)
# MNI_Template["resolution"] = request.params
sim = Simulator()
r = 10
Expand All @@ -25,6 +26,7 @@ def sim_brain_data():

@pytest.fixture(scope="module")
def sim_design_matrix():
np.random.seed(0)
# Design matrices are specified in terms of sampling frequency
TR = 2.0
sampling_freq = 1.0 / TR
Expand All @@ -37,6 +39,7 @@ def sim_design_matrix():

@pytest.fixture(scope="module")
def sim_adjacency_single():
np.random.seed(0)
sim = np.random.multivariate_normal(
[0, 0, 0, 0],
[
Expand All @@ -54,6 +57,7 @@ def sim_adjacency_single():

@pytest.fixture(scope="module")
def sim_adjacency_multiple():
np.random.seed(0)
n = 10
sim = np.random.multivariate_normal(
[0, 0, 0, 0],
Expand Down
4 changes: 3 additions & 1 deletion nltools/tests/test_brain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def test_load(tmpdir):
bb = Brain_Data(
os.path.join(tmpdir.join("test_write.h5")), mask=MNI_Template["mask"]
)
assert bb.mask.get_filename() == MNI_Template["mask"]
assert os.path.abspath(bb.mask.get_filename()) == os.path.abspath(
MNI_Template["mask"]
)


def test_shape(sim_brain_data):
Expand Down
2 changes: 0 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ coveralls
sphinx
sphinx_gallery
sphinx_bootstrap_theme
sphinxcontrib-napoleon

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pandas>=1.1.0
numpy<1.24
seaborn>=0.7.0
matplotlib>=2.2.0
scipy
scipy>=1.7.0
pynv
joblib>=0.15
h5py

0 comments on commit 5445c01

Please sign in to comment.