-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_regression.py
88 lines (72 loc) · 2.02 KB
/
test_regression.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pytest
import numpy as np
import pandas as pd
from sklearn.datasets import make_regression
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
from sklearn_evaluation import plot
y_true = np.array([105, 120, 120, 160, 120, 145, 175, 160, 185, 210, 150])
y_pred = np.array(
[
108.19,
115.16,
122.13,
136.06,
136.06,
156.97,
163.94,
170.91,
184.84,
205.75,
151.23,
]
)
X, y = make_regression(
n_samples=100,
n_features=14,
n_informative=6,
bias=1.2,
noise=49.8,
tail_strength=0.6,
random_state=637,
)
@image_comparison(baseline_images=["residual"], extensions=["png"], remove_text=True)
def test_residuals():
plot.residuals(y_true, y_pred)
@pytest.mark.parametrize(
"y_true, y_pred",
[(y_true, y_pred), (pd.Series(y_true), pd.Series(y_pred))],
ids=["numpy", "pandas"],
)
@image_comparison(
baseline_images=["prediction_error"], extensions=["png"], remove_text=True
)
def test_prediction_error(y_true, y_pred):
plot.prediction_error(y_true, y_pred)
@image_comparison(
baseline_images=["prediction_error_lines_one"],
extensions=["png"],
remove_text=True,
tol=0.1,
)
def test_prediction_error_lines_one(regression_data):
y_true, y_pred = regression_data
plot.prediction_error(y_true, y_pred)
@image_comparison(
baseline_images=["prediction_error_lines_two"], extensions=["png"], remove_text=True
)
def test_prediction_error_lines_two():
y_true = np.array([150, 500, 750, 35, 1200])
y_pred = np.array([155, 495, 703, 41, 950])
plot.prediction_error(y_true, y_pred)
@image_comparison(
baseline_images=["cooks_distance"], extensions=["png"], remove_text=True
)
def test_cooks_distance():
plot.cooks_distance(X, y)
def test_cooks_distance_ax():
out_ax = plot.cooks_distance(X, y)
fig, ax = plt.subplots(1, 1)
assert out_ax is not ax
out_ax = plot.cooks_distance(X, y, ax=ax)
assert ax is out_ax