Skip to content

Commit

Permalink
docs: Modified docstring
Browse files Browse the repository at this point in the history
- Fixed imports in class references
- Fixed examples outputs
  • Loading branch information
georgedouzas committed Nov 5, 2024
1 parent 4de18cc commit bcd88cf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/imblearn_extra/clover/distribution/_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ class DensityDistributor(BaseDistributor):
An array of unique cluster labels.
Examples:
>>> from clover.distribution import DensityDistributor
>>> import numpy as np
>>> from imblearn_extra.clover.distribution import DensityDistributor
>>> from sklearn.datasets import load_iris
>>> from sklearn.cluster import KMeans
>>> from imblearn.datasets import make_imbalance
>>> np.set_printoptions(legacy='1.25')
>>> X, y = make_imbalance(
... *load_iris(return_X_y=True),
... sampling_strategy={0:50, 1:40, 2:30},
Expand All @@ -132,7 +134,7 @@ class DensityDistributor(BaseDistributor):
>>> density_distributor.filtered_clusters_
[(6, 1), (0, 1), (3, 1), (7, 1), (5, 2), (2, 2), (3, 2), (6, 2), (0, 2)]
>>> density_distributor.intra_distribution_
{(6, 1): 0.50604609281056... (0, 1): 0.143311766542165...}
{(6, 1): 0.50604609281055... (0, 1): 0.143311766542168...}
>>> density_distributor.inter_distribution_
{}
"""
Expand Down
10 changes: 6 additions & 4 deletions src/imblearn_extra/clover/over_sampling/_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class ClusterOverSampler(BaseOverSampler):
A fitted clone of the `clusterer` parameter or `None` when a
clusterer is not given.
distributor_ (clover.distribution.base.BaseDistributor):
distributor_ (imblearn_extra.clover.distribution.base.BaseDistributor):
A fitted clone of the `distributor` parameter or a fitted instance of
the `DensityDistributor` when a distributor is not given.
Expand All @@ -338,20 +338,22 @@ class ClusterOverSampler(BaseOverSampler):
Actual sampling strategy.
Examples:
>>> import numpy as np
>>> from collections import Counter
>>> from clover.over_sampling import ClusterOverSampler
>>> from imblearn_extra.clover.over_sampling import ClusterOverSampler
>>> from sklearn.datasets import make_classification
>>> from sklearn.cluster import KMeans
>>> from imblearn.over_sampling import SMOTE
>>> np.set_printoptions(legacy='1.25')
>>> X, y = make_classification(random_state=0, n_classes=2, weights=[0.9, 0.1])
>>> print('Original dataset shape %s' % Counter(y))
Original dataset shape Counter({{0: 90, 1: 10}})
Original dataset shape Counter({0: 90, 1: 10})
>>> cluster_oversampler = ClusterOverSampler(
... oversampler=SMOTE(random_state=5),
... clusterer=KMeans(random_state=10, n_init='auto'))
>>> X_res, y_res = cluster_oversampler.fit_resample(X, y)
>>> print('Resampled dataset shape %s' % Counter(y_res))
Resampled dataset shape Counter({{0: 90, 1: 90}})
Resampled dataset shape Counter({0: 90, 1: 90})
"""

def __init__(
Expand Down
10 changes: 5 additions & 5 deletions src/imblearn_extra/clover/over_sampling/_gsomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ class GeometricSOMO(ClusterOverSampler):
som_estimator:
Defines the SOM clusterer applied to the input space.
- If `None`, a `clover.clusterer.SOM` instance with default parameters is used.
- If `None`, a `imblearn_extra.clover.clusterer.SOM` instance with default parameters is used.
- If `clover.clusterer.SOM` object then is used with the given parameters.
- If `imblearn_extra.clover.clusterer.SOM` object then is used with the given parameters.
- If `int`, the number of clusters to be used.
Expand Down Expand Up @@ -150,8 +150,8 @@ class GeometricSOMO(ClusterOverSampler):
clusterer_ (SOM):
A fitted `clovar.clusterer.SOM` instance.
distributor_ (clover.distribution.DensityDistributor):
A fitted `clover.distribution.DensityDistributor` instance.
distributor_ (imblearn_extra.clover.distribution.DensityDistributor):
A fitted `imblearn_extra.clover.distribution.DensityDistributor` instance.
labels_ (Labels):
Labels of each sample.
Expand All @@ -168,7 +168,7 @@ class GeometricSOMO(ClusterOverSampler):
Examples:
>>> import numpy as np
>>> from clover.over_sampling import GeometricSOMO # doctest: +SKIP
>>> from imblearn_extra.clover.over_sampling import GeometricSOMO # doctest: +SKIP
>>> from sklearn.datasets import make_blobs
>>> blobs = [100, 800, 100]
>>> X, y = make_blobs(blobs, centers=[(-10, 0), (0,0), (10, 0)])
Expand Down
6 changes: 3 additions & 3 deletions src/imblearn_extra/clover/over_sampling/_kmeans_smote.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class KMeansSMOTE(ClusterOverSampler):
clusterer_ (sklearn.cluster.KMeans | sklearn.cluster.MiniBatchKMeans):
A fitted `sklearn.cluster.KMeans` or `sklearn.cluster.MiniBatchKMeans` instance.
distributor_ (clover.distribution.DensityDistributor):
A fitted `clover.distribution.DensityDistributor` instance.
distributor_ (imblearn_extra.clover.distribution.DensityDistributor):
A fitted `imblearn_extra.clover.distribution.DensityDistributor` instance.
labels_ (Labels):
Cluster labels of each sample.
Expand All @@ -149,7 +149,7 @@ class KMeansSMOTE(ClusterOverSampler):
Examples:
>>> import numpy as np
>>> from clover.over_sampling import KMeansSMOTE
>>> from imblearn_extra.clover.over_sampling import KMeansSMOTE
>>> from sklearn.datasets import make_blobs
>>> blobs = [100, 800, 100]
>>> X, y = make_blobs(blobs, centers=[(-10, 0), (0,0), (10, 0)])
Expand Down
12 changes: 6 additions & 6 deletions src/imblearn_extra/clover/over_sampling/_somo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SOMO(ClusterOverSampler):
- If `None`, `SOM` is used which
tends to be better with large number of samples.
- If SOM object, then it is a `clover.clusterer.SOM` instance.
- If SOM object, then it is a `imblearn_extra.clover.clusterer.SOM` instance.
- If `int`, the number of clusters to be used.
Expand Down Expand Up @@ -111,11 +111,11 @@ class SOMO(ClusterOverSampler):
oversampler_ (imblearn.over_sampling.SMOTE):
A fitted `imblearn.over_sampling.SMOTE` instance.
clusterer_ (clover.clusterer.SOM):
A fitted `clover.clusterer.SOM` instance.
clusterer_ (imblearn_extra.clover.clusterer.SOM):
A fitted `imblearn_extra.clover.clusterer.SOM` instance.
distributor_ (clover.distribution.DensityDistributor):
A fitted `clover.distribution.DensityDistributor` instance.
distributor_ (imblearn_extra.clover.distribution.DensityDistributor):
A fitted `imblearn_extra.clover.distribution.DensityDistributor` instance.
labels_ (Labels):
Cluster labels of each sample.
Expand All @@ -132,7 +132,7 @@ class SOMO(ClusterOverSampler):
Examples:
>>> import numpy as np
>>> from clover.over_sampling import SOMO # doctest: +SKIP
>>> from imblearn_extra.clover.over_sampling import SOMO # doctest: +SKIP
>>> from sklearn.datasets import make_blobs
>>> blobs = [100, 800, 100]
>>> X, y = make_blobs(blobs, centers=[(-10, 0), (0,0), (10, 0)])
Expand Down
4 changes: 3 additions & 1 deletion src/imblearn_extra/gsmote/geometric_smote.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ class GeometricSMOTE(BaseOverSampler):
Actual sampling strategy.
Examples:
>>> import numpy as np
>>> from collections import Counter
>>> from sklearn.datasets import make_classification
>>> from gsmote import GeometricSMOTE # doctest: +NORMALIZE_WHITESPACE
>>> from imblearn_extra.gsmote import GeometricSMOTE # doctest: +NORMALIZE_WHITESPACE
>>> np.set_printoptions(legacy='1.25')
>>> X, y = make_classification(n_classes=2, class_sep=2,
... weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,
... n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10)
Expand Down

0 comments on commit bcd88cf

Please sign in to comment.