Skip to content

Commit

Permalink
Merge pull request #19 from spirosmaggioros/algorithms_optimization
Browse files Browse the repository at this point in the history
Codecov 80+% check | Workflows upadte to build the whl file for spare_scores installation | More test cases and fixes
  • Loading branch information
spirosmaggioros authored Aug 8, 2024
2 parents 28c3e50 + 6bad18d commit 1f5d9ac
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 45 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/macos_test_cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ jobs:
- name: Install pip
run: conda run -n spare conda install pip
- name: Install spare scores
run: conda run -n spare pip install spare_scores
run: |
pip install setuptools twine wheel
python setup.py bdist_wheel
cd dist
WHEEL_FILE=$(ls spare_scores*)
pip install "$WHEEL_FILE"
- name: Download dependencies
run: pip install setuptools && pip install .
- name: Run unit tests
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/ubuntu_test_cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ jobs:
- name: Install pip
run: conda run -n spare conda install pip
- name: Install spare scores
run: conda run -n spare pip install spare_scores
run: |
pip install setuptools twine wheel
python setup.py bdist_wheel
cd dist
WHEEL_FILE=$(ls spare_scores*)
pip install "$WHEEL_FILE"
- name: Download dependencies
run: pip install setuptools && pip install .
- name: Run unit tests
run: |
cd tests/unit && python -m unittest discover -s . -p "*.py"
- name: Generate Coverage Report
run: |
pip install pytest-cov
cd tests/unit && pytest --cov=../../ --cov-report=xml
- name: Upload Coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CBICA/spare_score
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no

ignore:
- "merge_ROI_demo_and_test.py"
- "setup.py"
- "spare_scores/cli.py"
- "tests/conftest.py"
11 changes: 6 additions & 5 deletions spare_scores/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from typing import Any

import pandas as pd
from data_prep import logging_basic_config
from mlp import MLPModel
from mlp_torch import MLPTorchModel
from svm import SVMModel

from .data_prep import logging_basic_config
from .mlp import MLPModel
from .mlp_torch import MLPTorchModel
from .svm import SVMModel


class SpareModel:
Expand Down Expand Up @@ -77,7 +78,7 @@ def __init__(
predictors, target, key_var, verbose, **parameters, **kwargs
)
else:
logger.err(f"Model type {self.model_type} not supported.")
logger.error(f"Model type {self.model_type} not supported.")
raise NotImplementedError("Only SVM is supported currently.")

def set_parameters(self, **parameters: Any) -> None:
Expand Down
3 changes: 2 additions & 1 deletion spare_scores/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import argparse

import pkg_resources # type: ignore
from spare import spare_test, spare_train

from .spare import spare_test, spare_train

VERSION = pkg_resources.require("spare_scores")[0].version

Expand Down
3 changes: 2 additions & 1 deletion spare_scores/data_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import numpy as np
import pandas as pd
from scipy import stats
from util import convert_to_number_if_possible

from .util import convert_to_number_if_possible


def check_train(
Expand Down
3 changes: 2 additions & 1 deletion spare_scores/mlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
import pandas as pd
from data_prep import logging_basic_config
from sklearn import metrics
from sklearn.exceptions import ConvergenceWarning
from sklearn.model_selection import GridSearchCV, KFold
Expand All @@ -13,6 +12,8 @@
from sklearn.preprocessing import StandardScaler
from sklearn.utils._testing import ignore_warnings

from .data_prep import logging_basic_config


class MLPModel:
"""
Expand Down
3 changes: 2 additions & 1 deletion spare_scores/mlp_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import torch
import torch.nn as nn
import torch.optim as optim
from data_prep import logging_basic_config
from sklearn.exceptions import ConvergenceWarning
from sklearn.metrics import (
accuracy_score,
Expand All @@ -29,6 +28,8 @@
from sklearn.utils._testing import ignore_warnings
from torch.utils.data import DataLoader, Dataset

from .data_prep import logging_basic_config

os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0" # for MPS backend
device = (
"cuda"
Expand Down
18 changes: 11 additions & 7 deletions spare_scores/spare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@

import numpy as np
import pandas as pd
from classes import MetaData, SpareModel
from data_prep import (

from .classes import MetaData, SpareModel
from .data_prep import (
check_test,
check_train,
convert_cat_variables,
logging_basic_config,
)
from util import check_file_exists, is_unique_identifier, load_df, load_model, save_file
from .util import (
check_file_exists,
is_unique_identifier,
load_df,
load_model,
save_file,
)


def spare_train(
Expand Down Expand Up @@ -105,7 +112,7 @@ def spare_train(

# Check if it contains any errors.
try:
df, predictors, mdl_task = check_train(
df, predictors, mdl_task = check_train( # type: ignore
df, predictors, to_predict, verbose, pos_group
)
except Exception as e:
Expand Down Expand Up @@ -200,9 +207,6 @@ def spare_train(
if output != "" and output is not None:
save_file(result, output, "train", logger)

print("###### PRINTING ########")
print(result)
print("####### END ###########")
res["status"] = "OK"
res["data"] = result
res["status_code"] = 0
Expand Down
5 changes: 3 additions & 2 deletions spare_scores/svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

import numpy as np
import pandas as pd
from data_prep import logging_basic_config
from sklearn import metrics
from sklearn.model_selection import GridSearchCV, RepeatedKFold
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC, LinearSVC, LinearSVR
from util import expspace

from .data_prep import logging_basic_config
from .util import expspace


class SVMModel:
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/test_data_prep.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import logging
import os
import sys
import unittest

import pandas as pd

sys.path.append(
"../../spare_scores/"
) # check_test and check_train were imported from the build, but now they are updated
from data_prep import ( # If updates go through, it can be updated to spare_scores.data_prep
from spare_scores.data_prep import ( # If updates go through, it can be updated to spare_scores.data_prep
age_sex_match,
check_test,
check_train,
logging_basic_config,
smart_unique,
)
from util import load_df
from spare_scores.util import load_df


class CheckDataPrep(unittest.TestCase):
Expand Down
Loading

0 comments on commit 1f5d9ac

Please sign in to comment.