Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/source/notes/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ Full CLI options (check out with ``geneplexus --help``)
123})
-lk , --logreg_kwargs
Set the logistic regression keyword arguments in fit(). (default:
{'max_iter': 10000, 'solver': 'lbfgs', 'penalty': 'l2', 'C': 1.0})
{'max_iter': 10000, 'solver': 'lbfgs', 'C': 1.0, 'l1_ratio': 0.0} on
scikit-learn>=1.8, otherwise {'max_iter': 10000, 'solver': 'lbfgs',
'penalty': 'l2', 'C': 1.0})
-s, --scale When added, will set scale to True in fit(). See docs for more info of
when this is good to do. (default: False)
-mnp , --min_num_pos
Expand Down
15 changes: 14 additions & 1 deletion geneplexus/_config/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Global variables used by the GenePlexus library."""
import os.path as osp
import pathlib
import re
from typing import Any
from typing import Dict
from typing import List
Expand All @@ -10,6 +11,7 @@
from typing import Union

import numpy as np
import sklearn

MAX_RETRY = 10 # maximum number of retries for downloading

Expand Down Expand Up @@ -118,9 +120,20 @@
DEFAULT_LOGREG_KWARGS: Dict[str, Any] = {
"max_iter": 10000,
"solver": "lbfgs",
"penalty": "l2",
"C": 1.0,
}
# In scikit-learn>=1.8, ``penalty`` is deprecated in favor of ``l1_ratio``/``C``
# (l1_ratio=0 is equivalent to the old penalty="l2" default), and passing
# ``penalty`` explicitly now raises a FutureWarning even when set to "l2".
# Older versions don't accept l1_ratio unless penalty="elasticnet", so pick
# whichever explicit form matches the installed version instead of relying on
# either version's default.
_SKLEARN_VERSION_MATCH = re.match(r"(\d+)\.(\d+)", sklearn.__version__)
_SKLEARN_VERSION = tuple(map(int, _SKLEARN_VERSION_MATCH.groups())) if _SKLEARN_VERSION_MATCH else (0, 0)
if _SKLEARN_VERSION >= (1, 8):
DEFAULT_LOGREG_KWARGS["l1_ratio"] = 0.0
else:
DEFAULT_LOGREG_KWARGS["penalty"] = "l2"

__all__ = [
"URL_DICT",
Expand Down
5 changes: 4 additions & 1 deletion geneplexus/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ def parse_args() -> argparse.Namespace:
default=config.DEFAULT_LOGREG_KWARGS,
metavar="",
type=json.loads,
help="Set the logistic regression keyword arguments in fit().",
help=(
"Set the logistic regression keyword arguments in fit(). The default shown "
"depends on the installed scikit-learn version (penalty vs l1_ratio)."
),
)

parser.add_argument(
Expand Down
5 changes: 4 additions & 1 deletion geneplexus/geneplexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,10 @@ def fit(

Args:
logreg_kwargs: Scikit-learn logistic regression settings (see
:class:`~sklearn.linear_model.LogisticRegression`).
:class:`~sklearn.linear_model.LogisticRegression`). The default
uses ``l1_ratio=0.0`` on scikit-learn>=1.8 and ``penalty="l2"``
on older versions (equivalent settings), since ``penalty`` is
deprecated in scikit-learn>=1.8.
scale: Whether to scale the data when doing model training and prediction. It is
not recommended to set to ``True`` unless using custom data.
min_num_pos: Minimum number of positives required for the model
Expand Down
Loading