Skip to content
Open
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r tests/requirements.txt
python -m nltk.downloader popular
python -m nltk.downloader popular punkt punkt_tab

- name: Run Unit Tests
run: |
make test
env:
MPLBACKEND: Agg

- name: Upload Coverage
uses: codecov/codecov-action@v1
Expand Down
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
## Dependencies
matplotlib>=2.0.2,!=3.0.0
scipy>=1.0.0
matplotlib>=3.6.0
scipy>=1.9.0
scikit-learn>=1.0.2
numpy>=1.16.0
cycler>=0.10.0
numpy>=1.21.0
cycler>=0.11.0

## Optional Dependencies (uncomment to use)
# nltk>=3.2
# pandas>=1.0.4
# umap-learn>=0.5
# nltk>=3.6.0
# pandas>=1.4.0
# umap-learn>=0.5.3

## Testing Requirements (pip install -r tests/requirements.txt)
# pytest>=6.1
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline_images/test_cluster/test_elbow/test_timings.png
Diff not rendered.
Binary file modified tests/baseline_images/test_features/test_pca/test_biplot_2d.png
Binary file modified tests/baseline_images/test_features/test_pca/test_biplot_3d.png
Binary file modified tests/baseline_images/test_features/test_pca/test_colorbar.png
Binary file modified tests/baseline_images/test_features/test_pca/test_continuous.png
Binary file modified tests/baseline_images/test_features/test_pca/test_discrete.png
Binary file modified tests/baseline_images/test_features/test_pca/test_heatmap.png
Binary file modified tests/baseline_images/test_features/test_pca/test_single.png
Binary file modified tests/baseline_images/test_features/test_pcoords/test_alpha.png
Binary file modified tests/baseline_images/test_features/test_radviz/test_radviz.png
Diff not rendered.
Binary file modified tests/baseline_images/test_text/test_tsne/test_no_target_tsne.png
Binary file modified tests/baseline_images/test_text/test_tsne/test_quick_method.png
26 changes: 13 additions & 13 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
# are probably using. We recommend monitoring Libraries.io to alert for changes.

# Library Dependencies
matplotlib==3.4.2
scipy==1.8.0
scikit-learn==1.0.2
numpy==1.22.0
cycler==0.10.0
matplotlib>=3.6.0
scipy>=1.9.0
scikit-learn>=1.1.0
numpy>=1.21.0
cycler>=0.11.0

# Testing Requirements
pytest==6.2.4
pytest-cov==2.12.1
pytest-flakes==4.0.3
pytest>=7.1.0
pytest-cov>=3.0.0
pytest-flakes>=4.0.5
pytest-spec>=2.0.0
coverage==5.5
coverage>=6.4.0

# Optional Testing Dependencies
nltk==3.6.7
nltk>=3.7.0
# spacy>=2.0.18
pandas==1.3.0
umap-learn==0.5.3
numba==0.55.2
pandas>=1.4.0
umap-learn>=0.5.3
numba>=0.56.0

# Third-Party Estimator Tests
# xgboost==1.2.0
Expand Down
155 changes: 88 additions & 67 deletions tests/test_classifier/test_prcurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_multiclass_probability_with_class_labels(self):
# Will not check for these as they appears okay in other test images.
for child in oz.ax.get_children():
if isinstance(child, matplotlib.text.Annotation):
oz.ax.texts.remove(child)
child.remove()

# Compare the images
tol = (
Expand Down Expand Up @@ -438,9 +438,11 @@ def test_quick_method_with_test_set(self):

viz = precision_recall_curve(
RandomForestClassifier(random_state=72),
X_train, y_train,
X_test, y_test,
show=False
X_train,
y_train,
X_test,
y_test,
show=False,
)
self.assert_images_similar(viz)

Expand Down Expand Up @@ -487,24 +489,31 @@ def test_within_pipeline(self):
classes = ["unoccupied", "occupied"]

X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([
('minmax', MinMaxScaler()),
('prc', PrecisionRecallCurve(SVC(random_state=42),
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=classes))
])
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline(
[
("minmax", MinMaxScaler()),
(
"prc",
PrecisionRecallCurve(
SVC(random_state=42),
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=classes,
),
),
]
)

model.fit(X_train, y_train)
model.score(X_test, y_test)
model['prc'].finalize()
self.assert_images_similar(model['prc'], tol=5.5)
model["prc"].finalize()
self.assert_images_similar(model["prc"], tol=5.5)

def test_within_pipeline_quickmethod(self):
"""
Expand All @@ -514,22 +523,32 @@ def test_within_pipeline_quickmethod(self):
X, y = load_occupancy(return_dataset=True).to_pandas()

X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([
('minmax', MinMaxScaler()),
('prc', precision_recall_curve(SVC(random_state=42),
X_train, y_train, X_test, y_test,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=["unoccupied", "occupied"],
show=False))
])
self.assert_images_similar(model['prc'], tol=5.5)
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline(
[
("minmax", MinMaxScaler()),
(
"prc",
precision_recall_curve(
SVC(random_state=42),
X_train,
y_train,
X_test,
y_test,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=["unoccupied", "occupied"],
show=False,
),
),
]
)
self.assert_images_similar(model["prc"], tol=5.5)

def test_pipeline_as_model_input(self):
"""
Expand All @@ -539,21 +558,20 @@ def test_pipeline_as_model_input(self):
classes = ["unoccupied", "occupied"]

X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([
('minmax', MinMaxScaler()),
('svc', SVC(random_state=42))
])

oz = PrecisionRecallCurve(model,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=classes)
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([("minmax", MinMaxScaler()), ("svc", SVC(random_state=42))])

oz = PrecisionRecallCurve(
model,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=classes,
)
oz.fit(X_train, y_train)
oz.score(X_test, y_test)
oz.finalize()
Expand All @@ -567,20 +585,23 @@ def test_pipeline_as_model_input_quickmethod(self):
X, y = load_occupancy(return_dataset=True).to_pandas()

X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([
('minmax', MinMaxScaler()),
('svc', SVC(random_state=42))
])

oz = precision_recall_curve(model, X_train, y_train, X_test, y_test,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=["unoccupied", "occupied"],
show=False)
self.assert_images_similar(oz, tol=5.5)
X, y, test_size=0.2, shuffle=True, random_state=42
)

model = Pipeline([("minmax", MinMaxScaler()), ("svc", SVC(random_state=42))])

oz = precision_recall_curve(
model,
X_train,
y_train,
X_test,
y_test,
per_class=True,
micro=False,
fill_area=False,
iso_f1_curves=True,
ap_score=False,
classes=["unoccupied", "occupied"],
show=False,
)
self.assert_images_similar(oz, tol=5.5)
35 changes: 20 additions & 15 deletions tests/test_cluster/test_elbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def test_distortion_score_empty_clusters(self):
"""
Ensure no ValueError is thrown when there are empty clusters #1185
"""
X = np.array([[1,2],[3,4],[5,6]])
valuea = distortion_score(X, np.array([1,3,3]))
valueb = distortion_score(X, np.array([0,1,1]))
X = np.array([[1, 2], [3, 4], [5, 6]])
valuea = distortion_score(X, np.array([1, 3, 3]))
valueb = distortion_score(X, np.array([0, 1, 1]))
assert valuea == valueb


Expand Down Expand Up @@ -238,7 +238,9 @@ def test_valid_k(self):
visualizer = KElbowVisualizer(KMeans(), k=np.arange(10, 100, 10)).fit(X)
assert visualizer.k_values_ == list(np.arange(10, 100, 10))

visualizer = KElbowVisualizer(KMeans(), k=[10, 20, 30, 40, 50, 60, 70, 80, 90]).fit(X)
visualizer = KElbowVisualizer(
KMeans(), k=[10, 20, 30, 40, 50, 60, 70, 80, 90]
).fit(X)
assert visualizer.k_values_ == list(np.arange(10, 100, 10))

@pytest.mark.xfail(sys.platform == "win32", reason="images not close on windows")
Expand All @@ -255,7 +257,7 @@ def test_distortion_metric(self):
)
visualizer.fit(self.clusters.X)

expected = np.array([69.100065, 54.081571, 43.146921, 34.978487])
expected = np.array([69.100065, 54.891057, 44.319888, 35.857462])
assert len(visualizer.k_scores_) == 4

visualizer.finalize()
Expand All @@ -276,7 +278,7 @@ def test_silhouette_metric(self):
)
visualizer.fit(self.clusters.X)

expected = np.array([0.691636, 0.456646, 0.255174, 0.239842])
expected = np.array([0.691636, 0.453478, 0.242102, 0.235422])
assert len(visualizer.k_scores_) == 4

visualizer.finalize()
Expand All @@ -299,7 +301,7 @@ def test_calinski_harabasz_metric(self):
assert len(visualizer.k_scores_) == 4
assert visualizer.elbow_value_ is None

expected = np.array([81.662726, 50.992378, 40.952179, 35.939494])
expected = np.array([81.662726, 50.129783, 39.744834, 34.978841])

visualizer.finalize()
self.assert_images_similar(visualizer)
Expand All @@ -308,21 +310,22 @@ def test_calinski_harabasz_metric(self):
@pytest.mark.xfail(sys.platform == "win32", reason="images not close on windows")
def test_distance_metric(self):
"""
Test the manhattan distance metric of the distortion metric of the k-elbow visualizer
Test the manhattan distance metric of the distortion metric of the k-elbow
visualizer
"""
visualizer = KElbowVisualizer(
KMeans(random_state=0),
k=5,
metric="distortion",
distance_metric='manhattan',
distance_metric="manhattan",
timings=False,
locate_elbow=False,
)
visualizer.fit(self.clusters.X)
assert len(visualizer.k_scores_) == 4
assert visualizer.elbow_value_ is None

expected = np.array([189.060129, 154.096223, 124.271208, 107.087566])
expected = np.array([189.06013, 152.276395, 132.668674, 110.741248])

visualizer.finalize()
self.assert_images_similar(visualizer)
Expand Down Expand Up @@ -350,7 +353,7 @@ def test_locate_elbow(self):
visualizer.fit(X)
assert len(visualizer.k_scores_) == 5
assert visualizer.elbow_value_ == 3
expected = np.array([4286.5, 12463.4, 8766.8, 6950.1, 5863.6])
expected = np.array([4286.5, 12463.4, 8766.8, 6950.1, 5863.6])

visualizer.finalize()
self.assert_images_similar(visualizer, tol=0.5, windows_tol=2.2)
Expand Down Expand Up @@ -483,7 +486,8 @@ def test_set_colors_manually(self):
Test the silhouette metric of the k-elbow visualizer
"""
oz = KElbowVisualizer(
KMeans(random_state=0), k=5,
KMeans(random_state=0),
k=5,
)

oz.metric_color = "r"
Expand All @@ -493,7 +497,7 @@ def test_set_colors_manually(self):
# Create artificial "fit" data for testing purposes
oz.k_values_ = [1, 2, 3, 4, 5, 6, 7, 8]
oz.k_timers_ = [6.2, 8.3, 10.1, 15.8, 21.2, 27.9, 38.2, 44.9]
oz.k_scores_ = [.8, .7, .55, .48, .40, .38, .35, .30]
oz.k_scores_ = [0.8, 0.7, 0.55, 0.48, 0.40, 0.38, 0.35, 0.30]
oz.elbow_value_ = 5
oz.elbow_score_ = 0.40

Expand All @@ -507,7 +511,8 @@ def test_get_params(self):
Ensure the get params works for sklearn-compatibility
"""
oz = KElbowVisualizer(
KMeans(random_state=0), k=5,
KMeans(random_state=0),
k=5,
)
params = oz.get_params()
assert len(params) > 0
assert len(params) > 0
Loading
Loading