Skip to content

Commit

Permalink
Merge branch 'refactor/rename_base_model_module' into 'dev'
Browse files Browse the repository at this point in the history
Rename base model module

See merge request cdd/QSPRpred!181
  • Loading branch information
martin-sicho committed Mar 28, 2024
2 parents 06079a5 + bdc4bc2 commit f96049d
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ From v3.0.1 to v3.0.2

## Changes

- The module containing the sole model base class (`QSPRModel`) was renamed
from `models` to `model`.
- Restrictions on `numpy` versions were removed to allow for more flexibility in
package installations. However, the `BorutaFilter` feature selection method does not
function with `numpy` versions 1.24.0 and above. Therefore, this functionality now
Expand Down
2 changes: 1 addition & 1 deletion docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Overview of available features

.. dropdown:: Models

:class:`~qsprpred.models.models.QSPRModel`: Base class for models.
:class:`~qsprpred.models.model.QSPRModel`: Base class for models.

Models are used to predict properties of molecules.
A general example can be found in the `quick start tutorial <https://github.com/CDDLeiden/QSPRpred/blob/main/tutorials/quick_start.ipynb>`_.
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/benchmarks/replica.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..data.sources.data_source import DataSource
from ..logs import logger
from ..models.hyperparam_optimization import HyperparameterOptimization
from ..models.models import QSPRModel
from ..models.model import QSPRModel
from ..models.monitors import NullMonitor
from ..tasks import TargetProperty
from ..utils.serialization import JSONSerializable
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/benchmarks/settings/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ...data.descriptors.sets import DescriptorSet
from ...data.sources.data_source import DataSource
from ...models.hyperparam_optimization import HyperparameterOptimization
from ...models.models import QSPRModel
from ...models.model import QSPRModel
from ...tasks import TargetProperty
from ...utils.serialization import JSONSerializable

Expand Down
4 changes: 2 additions & 2 deletions qsprpred/data/descriptors/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def __init__(self, model: Type["QSPRModel"] | str):
"""
super().__init__()
if isinstance(model, str):
from ...models.models import QSPRModel
from ...models.model import QSPRModel

self.model = QSPRModel.fromFile(model)
else:
Expand All @@ -544,7 +544,7 @@ def __getstate__(self):

def __setstate__(self, state):
super().__setstate__(state)
from ...models.models import QSPRModel
from ...models.model import QSPRModel

self.model = QSPRModel.fromFile(self.model)

Expand Down
2 changes: 1 addition & 1 deletion qsprpred/extra/gpu/models/chemprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ....data.tables.qspr import QSPRDataset
from ....logs import logger
from ....models.early_stopping import EarlyStoppingMode, early_stopping
from ....models.models import QSPRModel
from ....models.model import QSPRModel
from ....models.monitors import BaseMonitor, FitMonitor


Expand Down
2 changes: 1 addition & 1 deletion qsprpred/extra/gpu/models/dnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ....data.tables.qspr import QSPRDataset
from ....extra.gpu.models.neural_network import STFullyConnected
from ....models.early_stopping import EarlyStoppingMode, early_stopping
from ....models.models import QSPRModel
from ....models.model import QSPRModel
from ....models.monitors import BaseMonitor, FitMonitor


Expand Down
2 changes: 1 addition & 1 deletion qsprpred/extra/gpu/models/pyboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ....data.sampling.splits import DataSplit
from ....data.tables.qspr import QSPRDataset
from ....models.early_stopping import EarlyStoppingMode, early_stopping
from ....models.models import QSPRModel
from ....models.model import QSPRModel
from ....models.monitors import BaseMonitor, FitMonitor
from ....tasks import ModelTasks

Expand Down
6 changes: 3 additions & 3 deletions qsprpred/extra/models/pcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from typing import Callable

import numpy as np
from rdkit import Chem
from rdkit.Chem import Mol

from qsprpred.extra.data.tables.pcm import PCMDataSet
from ..data.descriptors.sets import ProteinDescriptorSet
from ...data.tables.mol import MoleculeTable
from ...models.models import QSPRModel
from ...models.model import QSPRModel
from ...models.scikit_learn import SklearnModel
from rdkit import Chem
from rdkit.Chem import Mol


class PCMModel(QSPRModel, ABC):
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/extra/models/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from qsprpred.models.monitors import FitMonitor

from ...data.tables.qspr import QSPRDataset
from ...models.models import QSPRModel
from ...models.model import QSPRModel


class RandomDistributionAlgorithm(ABC):
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
HyperparameterOptimization,
)
from .metrics import SklearnMetrics
from .models import QSPRModel
from .model import QSPRModel

from .monitors import (
BaseMonitor,
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/models/assessment/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qsprpred.logs import logger
from qsprpred.models.early_stopping import EarlyStoppingMode
from qsprpred.models.metrics import SklearnMetrics
from qsprpred.models.models import QSPRModel
from qsprpred.models.model import QSPRModel
from qsprpred.models.monitors import AssessorMonitor, BaseMonitor


Expand Down
2 changes: 1 addition & 1 deletion qsprpred/models/hyperparam_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from qsprpred.models.assessment.methods import ModelAssessor
from ..data import QSPRDataset
from ..logs import logger
from ..models.models import QSPRModel
from ..models.model import QSPRModel
from ..models.monitors import BaseMonitor, HyperparameterOptimizationMonitor


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion qsprpred/models/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rdkit import Chem
from rdkit.Chem import Draw

from .models import QSPRModel
from .model import QSPRModel
from ..data.tables.qspr import QSPRDataset
from ..utils.serialization import JSONSerializable

Expand Down
2 changes: 1 addition & 1 deletion qsprpred/models/scikit_learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sklearn.exceptions import NotFittedError
from sklearn.utils.validation import check_is_fitted

from .models import QSPRModel
from .model import QSPRModel
from ..data.tables.qspr import QSPRDataset
from ..logs import logger
from ..tasks import ModelTasks
Expand Down
10 changes: 4 additions & 6 deletions qsprpred/plotting/base_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from abc import ABC, abstractmethod
from typing import Any

from ..models.models import QSPRModel
from ..models.model import QSPRModel


class ModelPlot(ABC):
Expand All @@ -21,6 +21,7 @@ class ModelPlot(ABC):
indPaths (dict[QSPRModel, str]):
dictionary of models mapped to their independent test set results paths
"""

def __init__(self, models: list[QSPRModel]):
"""Initialize the base class for all model plots.
Expand Down Expand Up @@ -55,13 +56,10 @@ def checkModel(self, model: QSPRModel) -> tuple[str, str]:
ind_path = f"{self.modelOuts[model]}.ind.tsv"
if model.task not in self.getSupportedTasks():
raise ValueError("Unsupported model type: %s" % model.task)
if not os.path.exists(
model.metaFile
):
if not os.path.exists(model.metaFile):
raise ValueError(
"Model output file does not exist: %s. "
"Have you evaluated and saved the model, yet?" %
model.metaFile
"Have you evaluated and saved the model, yet?" % model.metaFile
)
if not os.path.exists(cv_path):
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion qsprpred/plotting/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)

from ..models.metrics import calibration_error
from ..models.models import QSPRModel
from ..models.model import QSPRModel
from ..plotting.base_plot import ModelPlot
from ..tasks import ModelTasks

Expand Down
19 changes: 12 additions & 7 deletions qsprpred/predict_CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pandas as pd

from .logs.utils import backup_files, enable_file_logger
from .models.models import QSPRModel
from .models.model import QSPRModel


def QSPRArgParser(txt=None):
Expand Down Expand Up @@ -120,23 +120,28 @@ def QSPR_predict(args):
for i in range(predictions[idx].shape[1]):
results.update(
{
f"preds_{predictor.name}_{target.name}_class_{i}":
predictions[idx][:, i].flatten()
f"preds_{predictor.name}_{target.name}_class_{i}": predictions[
idx
][
:, i
].flatten()
}
)
else:
for i in range(predictions.shape[1]):
results.update(
{
f"preds_{predictor.name}_{target.name}_class_{i}":
predictions[:, i].flatten()
f"preds_{predictor.name}_{target.name}_class_{i}": predictions[
:, i
].flatten()
}
)
else:
results.update(
{
f"preds_{predictor.name}_{target.name}":
predictions[:, idx].flatten()
f"preds_{predictor.name}_{target.name}": predictions[
:, idx
].flatten()
}
)

Expand Down
2 changes: 1 addition & 1 deletion tutorials/advanced/modelling/custom_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"This significantly speeds up the algorithm, so let's continue with the second implementation. \n",
"\n",
"Now for the implementation of the `QSPRModel` Gzip KNN, we find the base class for models `QSPRModels` in the `interfaces.py` file of the `models` module.\n",
"In the `models.py` file of the `models` module you can also find an example of a model that inherits from the base class `QSPRSklearn`, which uses estimators from the `scikit-learn` package.\n",
"In the `model.py` file of the `models` module you can also find an example of a model that inherits from the base class `QSPRSklearn`, which uses estimators from the `scikit-learn` package.\n",
"\n",
"There are six abstract methods that need to be implemented from `QSPRModel` class in our new class `GzipKNNModel`:\n",
"- `fit`, which trains the model\n",
Expand Down

0 comments on commit f96049d

Please sign in to comment.