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

Better lint #132

Merged
merged 7 commits into from
Sep 8, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ _doc/examples/plot_*.onnx
_doc/examples/plot_*.xlsx
_doc/_static/require.js
_doc/_static/viz.js
_doc/sg_execution_times.rst
_unittests/ut__main/*.png
_unittests/test_constants.h
mlinsights/_config.py
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOGS.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@

===========
Change Logs
===========

0.5.1
=====

* :pr:`132` builds against scikit-learn==1.5.0, python 3.12

0.5.0
=====

Expand Down
8 changes: 4 additions & 4 deletions _doc/examples/plot_constraint_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

colors = "brgy"
fig, ax = plt.subplots(1, 1, figsize=(4, 4))
for i in range(0, max(cl) + 1):
for i in range(max(cl) + 1):
ax.plot(X[cl == i, 0], X[cl == i, 1], colors[i] + ".", label="cl%d" % i)
x = [km.cluster_centers_[i, 0], km.cluster_centers_[i, 0]]
y = [km.cluster_centers_[i, 1], km.cluster_centers_[i, 1]]
Expand Down Expand Up @@ -97,7 +97,7 @@
#

fig, ax = plt.subplots(1, 2, figsize=(10, 4))
for i in range(0, max(cl1) + 1):
for i in range(max(cl1) + 1):
ax[0].plot(X[cl1 == i, 0], X[cl1 == i, 1], colors[i] + ".", label="cl%d" % i)
ax[1].plot(X[cl2 == i, 0], X[cl2 == i, 1], colors[i] + ".", label="cl%d" % i)
x = [km1.cluster_centers_[i, 0], km1.cluster_centers_[i, 0]]
Expand Down Expand Up @@ -135,7 +135,7 @@ def plot_delaunay(ax, edges, points):


fig, ax = plt.subplots(1, 2, figsize=(10, 4))
for i in range(0, max(cl) + 1):
for i in range(max(cl) + 1):
ax[0].plot(X[cl == i, 0], X[cl == i, 1], colors[i] + ".", label="cl%d" % i)
x = [km.cluster_centers_[i, 0], km.cluster_centers_[i, 0]]
y = [km.cluster_centers_[i, 1], km.cluster_centers_[i, 1]]
Expand All @@ -145,7 +145,7 @@ def plot_delaunay(ax, edges, points):

cls = km.cluster_centers_iter_
ax[1].plot(X[:, 0], X[:, 1], ".", label="X", color="#AAAAAA", ms=3)
for i in range(0, max(cl) + 1):
for i in range(max(cl) + 1):
ms = numpy.arange(cls.shape[-1]).astype(numpy.float64) / cls.shape[-1] * 50 + 1
ax[1].scatter(cls[i, 0, :], cls[i, 1, :], color=colors[i], s=ms, label="cl%d" % i)
plot_delaunay(ax[1], edges, km.cluster_centers_)
Expand Down
6 changes: 3 additions & 3 deletions _doc/examples/plot_logistic_regression_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
Xs = []
Ys = []
n = 20
for i in range(0, 5):
for j in range(0, 4):
for i in range(5):
for j in range(4):
x1 = numpy.random.rand(n) + i * 1.1
x2 = numpy.random.rand(n) + j * 1.1
Xs.append(numpy.vstack([x1, x2]).T)
Expand All @@ -41,7 +41,7 @@
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
for i in set(Y):
ax.plot(
X[Y == i, 0], X[Y == i, 1], "o", label="cl%d" % i, color=plt.cm.tab20.colors[i]
X[i == Y, 0], X[i == Y, 1], "o", label="cl%d" % i, color=plt.cm.tab20.colors[i]
)
ax.legend()
ax.set_title("Classification not convex")
Expand Down
4 changes: 2 additions & 2 deletions _doc/examples/plot_piecewise_linear_regression_criterion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Custom DecisionTreeRegressor adapted to a linear regression
===========================================================

A :class:`sklearn.tree.DecisionTreeRegressor`
can be trained with a couple of possible criterions but it is possible
can be trained with a couple of possible criterions but it is possible
to implement a custom one (see `hellinger_distance_criterion
<https://github.com/EvgeniDubov/hellinger-distance-criterion/blob/master/hellinger_distance_criterion.pyx>`_).
See also tutorial
Expand Down
6 changes: 3 additions & 3 deletions _doc/examples/plot_search_images_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
imgs = datasets.ImageFolder("simages", trans)
dataloader = DataLoader(imgs, batch_size=1, shuffle=True, num_workers=1)
img_seq = iter(dataloader)
imgs = list(img[0] for i, img in zip(range(2), img_seq))
imgs = [img[0] for i, img in zip(range(2), img_seq)]
#######################################
#

Expand Down Expand Up @@ -182,7 +182,7 @@
ConcatDataset([imgs1, imgs2]), batch_size=1, shuffle=True, num_workers=1
)
img_seq = iter(dataloader)
imgs = list(img[0] for i, img in zip(range(10), img_seq))
imgs = [img[0] for i, img in zip(range(10), img_seq)]
#######################################
#

Expand Down Expand Up @@ -259,7 +259,7 @@
imgs = datasets.ImageFolder("simages", trans)
dataloader = DataLoader(imgs, batch_size=1, shuffle=False, num_workers=1)
img_seq = iter(dataloader)
imgs = list(img[0] for img in img_seq)
imgs = [img[0] for img in img_seq]

all_outputs = [model.forward(img).detach().numpy().ravel() for img in imgs]

Expand Down
6 changes: 3 additions & 3 deletions _doc/examples/plot_sklearn_transformed_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def evaluation():
rnd = []
perf_reg = []
perf_clr = []
for rs in range(0, 200):
for rs in range(200):
rnd.append(rs)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=rs)
reg = LinearRegression()
Expand Down Expand Up @@ -247,7 +247,7 @@ def evaluation2():
perf_clr = []
acc_reg = []
acc_clr = []
for rs in range(0, 50):
for rs in range(50):
rnd.append(rs)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=rs)
reg = LinearRegression()
Expand Down Expand Up @@ -368,7 +368,7 @@ def permute(y):


rows = []
for i in range(0, 10):
for _i in range(10):
regpt = TransformedTargetRegressor2(LinearRegression(), transformer="permute")
regpt.fit(X_train, y_train)
logpt = TransformedTargetClassifier2(
Expand Down
4 changes: 2 additions & 2 deletions _doc/examples/plot_visualize_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,6 @@
# Every piece behaves the same way.


for coor, model, vars in enumerate_pipeline_models(model):
for coor, m, _vars in enumerate_pipeline_models(model):
print(coor)
print(model._debug)
print(m._debug)
1 change: 0 additions & 1 deletion _unittests/ut_helpers/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy.random
from sklearn.linear_model import LinearRegression, LogisticRegression
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_helpers/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
from mlinsights.ext_test_case import ExtTestCase
from mlinsights.helpers.parameters import format_value
Expand Down
19 changes: 9 additions & 10 deletions _unittests/ut_metrics/test_non_linear_correlations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import pandas
from sklearn import datasets
Expand All @@ -18,7 +17,7 @@ def test_non_linear_correlations_df(self):
self.assertEqual(cor.shape, (4, 4))
self.assertEqual(list(cor.columns), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(cor.index), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(cor.iloc[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(cor.iloc[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertGreater(cor.values.min(), 0)

def test_non_linear_correlations_array(self):
Expand All @@ -27,7 +26,7 @@ def test_non_linear_correlations_array(self):
df = pandas.DataFrame(X).values
cor = non_linear_correlations(df, LinearRegression(fit_intercept=False))
self.assertEqual(cor.shape, (4, 4))
self.assertEqual(list(cor[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(cor[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertGreater(cor.min(), 0)

def test_non_linear_correlations_df_tree(self):
Expand All @@ -39,7 +38,7 @@ def test_non_linear_correlations_df_tree(self):
self.assertEqual(cor.shape, (4, 4))
self.assertEqual(list(cor.columns), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(cor.index), ["X1", "X2", "X3", "X4"])
self.assertGreater(max(cor.iloc[i, i] for i in range(0, 4)), 0.98)
self.assertGreater(max(cor.iloc[i, i] for i in range(4)), 0.98)
self.assertGreater(cor.values.min(), 0)

def test_non_linear_correlations_df_minmax(self):
Expand All @@ -53,9 +52,9 @@ def test_non_linear_correlations_df_minmax(self):
self.assertEqual(cor.shape, (4, 4))
self.assertEqual(list(cor.columns), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(cor.index), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(cor.iloc[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(mini.iloc[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(maxi.iloc[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(cor.iloc[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertEqual(list(mini.iloc[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertEqual(list(maxi.iloc[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertGreater(cor.values.min(), 0)
self.assertEqual(list(mini.columns), ["X1", "X2", "X3", "X4"])
self.assertEqual(list(mini.index), ["X1", "X2", "X3", "X4"])
Expand All @@ -74,9 +73,9 @@ def test_non_linear_correlations_array_minmax(self):
df, LinearRegression(fit_intercept=False), minmax=True
)
self.assertEqual(cor.shape, (4, 4))
self.assertEqual(list(cor[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(mini[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(maxi[i, i] for i in range(0, 4)), [1, 1, 1, 1])
self.assertEqual(list(cor[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertEqual(list(mini[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertEqual(list(maxi[i, i] for i in range(4)), [1, 1, 1, 1])
self.assertGreater(cor.min(), 0)
self.assertEqual(mini.shape, (4, 4))
self.assertLesser(mini.min(), cor.min())
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_metrics/test_scoring_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import pandas
import numpy
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlbatch/test_pipeline_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA, TruncatedSVD as SVD
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_anmf_predictor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from scipy.sparse import csr_matrix
Expand Down
5 changes: 2 additions & 3 deletions _unittests/ut_mlmodel/test_classification_kmeans.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import RandomState
Expand Down Expand Up @@ -75,8 +74,8 @@ def test_classification_kmeans_relevance(self):
Xs = []
Ys = []
n = 20
for i in range(0, 5):
for j in range(0, 4):
for i in range(5):
for j in range(4):
x1 = state.rand(n) + i * 1.1
x2 = state.rand(n) + j * 1.1
Xs.append(numpy.vstack([x1, x2]).T)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import random
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_direct_blas_lapack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from scipy.linalg.lapack import dgelss as scipy_dgelss
Expand Down
5 changes: 2 additions & 3 deletions _unittests/ut_mlmodel/test_extended_features.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from scipy import sparse
Expand Down Expand Up @@ -304,7 +303,7 @@ def test_polynomial_features_bigger(self):
ext = ExtendedFeatures(poly_degree=deg)
X_ext = ext.fit_transform(X)

inames = ["x%d" % i for i in range(0, X.shape[1])]
inames = ["x%d" % i for i in range(X.shape[1])]
names_ext = ext.get_feature_names_out(inames)

self.assertEqual(len(names_sk), len(names_ext))
Expand All @@ -329,7 +328,7 @@ def test_polynomial_features_bigger_ionly(self):
)
X_ext = ext.fit_transform(X)

inames = ["x%d" % i for i in range(0, X.shape[1])]
inames = ["x%d" % i for i in range(X.shape[1])]
names_ext = ext.get_feature_names_out(inames)

self.assertEqual(len(names_sk), len(names_ext))
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_interval_regressor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn.linear_model import LinearRegression
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_kmeans_sklearn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy as np
from scipy import sparse as sp
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_piecewise_classifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import random
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import warnings
import packaging.version as pv
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import warnings
import numpy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import warnings
import numpy
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_piecewise_regressor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import random
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_quantile_mlpregression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import random
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_quantile_regression.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import random
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_sklearn_text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_sklearn_transform_inv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from mlinsights.ext_test_case import ExtTestCase
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_target_predictors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn.datasets import load_iris
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mlmodel/test_transfer_transformer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn.linear_model import LinearRegression, LogisticRegression
Expand Down
5 changes: 2 additions & 3 deletions _unittests/ut_mlmodel/test_tsne_predictable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from numpy.random import RandomState
Expand Down Expand Up @@ -63,8 +62,8 @@ def test_predictable_tsne_relevance(self):
Xs = []
Ys = []
n = 20
for i in range(0, 5):
for j in range(0, 4):
for i in range(5):
for j in range(4):
x1 = state.rand(n) + i * 1.1
x2 = state.rand(n) + j * 1.1
Xs.append(numpy.vstack([x1, x2]).T)
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mltree/test_tree_digitize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn.tree import DecisionTreeRegressor
Expand Down
1 change: 0 additions & 1 deletion _unittests/ut_mltree/test_tree_structure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
import numpy
from sklearn import datasets
Expand Down
3 changes: 1 addition & 2 deletions _unittests/ut_plotting/test_dot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest
from io import StringIO
from textwrap import dedent
Expand Down Expand Up @@ -168,7 +167,7 @@ def test_onehotencoder_dot(self):
),
LinearRegression(),
)
train_cols = cols + ["weekday"]
train_cols = [*cols, "weekday"]
model.fit(df, df[train_cols])
dot = pipeline2dot(model, df)
self.assertIn('label="Identity"', dot)
Expand Down
Loading
Loading