Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP isolate convergence warning in LogReg #225

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ coverage/*
.coverage

.DS_Store
MANIFEST
MANIFEST
29 changes: 29 additions & 0 deletions celer/tests/inspect_conv_warn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Check whether ``C`` is the only reason behind the warning.
Badr-MOUFAD marked this conversation as resolved.
Show resolved Hide resolved

If yes, no matter how the dummy data is generated,
for ``C >= 1e4 / alpha_max``, the warning is raised.

It's not the case.
"""

import numpy as np
from numpy.linalg import norm
from celer.dropin_sklearn import LogisticRegression


# params
C_fac = 1e4
tol = 1e-4

n_samples, n_features = np.random.randint(low=1, high=100, size=2)
min_bound, max_bound = 0, 2

np.random.seed(0)
X = np.random.random(size=(n_samples, n_features))
y = np.random.randint(low=min_bound, high=max_bound, size=n_samples)

alpha_max = norm(X.T.dot(y), ord=np.inf) / 2
C = C_fac / alpha_max

clf = LogisticRegression(C=C, tol=tol, verbose=0)
clf.fit(X, y)
30 changes: 30 additions & 0 deletions celer/tests/isolate_conv_warn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""ConvergenceWarning in celer/tests/test_logreg.py.

ConvergenceWarning is due to ``sklearn.utils.estimator_checks.check_estimator``.
The followings functions in ``check_estimator`` sources code:
https://github.com/scikit-learn/scikit-learn/blob/582fa30a3/sklearn/utils/estimator_checks.py#L514
raises the warning:
- ``check_fit_idempotent``
- ``check_fit_check_is_fitted``
- ``check_n_features_in``

Code inspired by the latter functions implementation.
"""

import numpy as np
from celer.dropin_sklearn import LogisticRegression


# params
n_samples, n_features = 100, 2
mu, std = 100, 1
min_bound, max_bound = 0, 2
tol = 1e-4
C = 1.

np.random.seed(0)
X = np.random.normal(loc=mu, scale=std, size=(n_samples, n_features))
y = np.random.randint(low=min_bound, high=max_bound, size=n_samples)

clf = LogisticRegression(C=C, tol=tol, verbose=0)
clf.fit(X, y)