Skip to content

Commit

Permalink
updates tests because scikit-learn has changed kmeans and linearscv m…
Browse files Browse the repository at this point in the history
…odels (#1068)
  • Loading branch information
rebeccabilbro committed Jun 10, 2020
1 parent 1879734 commit 994cc20
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 27 additions & 15 deletions tests/test_classifier/test_class_prediction_error.py
Expand Up @@ -26,7 +26,7 @@
from yellowbrick.datasets import load_occupancy
from yellowbrick.classifier.class_prediction_error import *

from sklearn.svm import LinearSVC
from sklearn.svm import LinearSVC, SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_multilabel_classification
from sklearn.model_selection import train_test_split as tts
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_numpy_integration(self):

classes = ["unoccupied", "occupied"]

model = LinearSVC(random_state=42)
model = SVC(random_state=42)
model.fit(X, y)
visualizer = ClassPredictionError(model, classes=classes)
visualizer.score(X, y)
Expand All @@ -79,7 +79,7 @@ def test_pandas_integration(self):
X, y = load_occupancy(return_dataset=True).to_pandas()
classes = ["unoccupied", "occupied"]

model = LinearSVC(random_state=42)
model = SVC(random_state=42)
model.fit(X, y)
visualizer = ClassPredictionError(model, classes=classes)
visualizer.score(X, y)
Expand All @@ -98,7 +98,7 @@ def test_class_prediction_error_quickmethod(self):
fig = plt.figure()
ax = fig.add_subplot()

clf = LinearSVC(random_state=42)
clf = SVC(random_state=42)
viz = class_prediction_error(clf, X, y, ax=ax, show=False)

# Not sure why the tolerance must be so high for this
Expand All @@ -112,32 +112,44 @@ def test_class_prediction_error_quickmethod_X_test_only(self):
Test the ClassPredictionError quickmethod
"""
X, y = load_occupancy(return_dataset=True).to_numpy()
X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2, shuffle=True,
random_state=42)
X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

fig = plt.figure()
ax = fig.add_subplot()

clf = LinearSVC(random_state=42)
with pytest.raises(YellowbrickValueError,
match="must specify both X_test and y_test or neither"):
class_prediction_error(clf, X_train=X_train, y_train=y_train,
X_test=X_test, ax=ax, show=False)
with pytest.raises(
YellowbrickValueError,
match="must specify both X_test and y_test or neither",
):
class_prediction_error(
clf, X_train=X_train, y_train=y_train, X_test=X_test, ax=ax, show=False
)

def test_class_prediction_error_quickmethod_X_test_and_y_test(self):
"""
Test the ClassPredictionError quickmethod
"""
X, y = load_occupancy(return_dataset=True).to_numpy()
X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2, shuffle=True,
random_state=42)
X_train, X_test, y_train, y_test = tts(
X, y, test_size=0.2, shuffle=True, random_state=42
)

fig = plt.figure()
ax = fig.add_subplot()

clf = LinearSVC(random_state=42)
viz = class_prediction_error(clf, X_train=X_train, y_train=y_train,
X_test=X_test, y_test=y_test, ax=ax, show=False)
clf = SVC(random_state=42)
viz = class_prediction_error(
clf,
X_train=X_train,
y_train=y_train,
X_test=X_test,
y_test=y_test,
ax=ax,
show=False,
)

# Not sure why the tolerance must be so high for this
# Failing on travis with RMS 9.544
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cluster/test_elbow.py
Expand Up @@ -328,7 +328,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, 8763.8, 6939.3, 5858.8])
expected = np.array([4286.5, 12463.4, 8763.3, 6938.2, 5858.4])

visualizer.finalize()
self.assert_images_similar(visualizer, tol=0.5, windows_tol=2.2)
Expand Down

0 comments on commit 994cc20

Please sign in to comment.