Repository navigation
Expand file tree
/
Copy pathvisualize_features.py
More file actions
97 lines (78 loc) · 2.15 KB
/
Copy pathvisualize_features.py
File metadata and controls
97 lines (78 loc) · 2.15 KB
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
89
90
91
92
93
94
95
96
97
import numpy as np
import matplotlib.pyplot as plt
FEATURE_NAMES = [
"height",
"root_density",
"area",
"shape_index",
"linearity",
"sphericity",
"slenderness",
"length_height_ratio",
"circularity",
"footprint_density",
]
CLASS_LABELS = ["building", "car", "fence", "pole", "tree"]
CLASS_COLORS = ["firebrick", "grey", "darkorange", "dodgerblue", "olivedrab"]
def scatter_two_features(X, y, feat_x, feat_y, log_y=False, log_x=False):
fig, ax = plt.subplots(figsize=(9, 6))
xvals = X[:, feat_x].copy()
yvals = X[:, feat_y].copy()
if log_x:
xvals = np.log1p(np.maximum(xvals, 0))
if log_y:
yvals = np.log1p(np.maximum(yvals, 0))
for cls in range(5):
mask = y == cls
ax.scatter(
xvals[mask],
yvals[mask],
s=70,
c=CLASS_COLORS[cls],
edgecolor="k",
label=CLASS_LABELS[cls],
alpha=0.8,
)
xlabel = FEATURE_NAMES[feat_x]
ylabel = FEATURE_NAMES[feat_y]
if log_x:
xlabel = f"log(1 + {xlabel})"
if log_y:
ylabel = f"log(1 + {ylabel})"
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_title(f"{xlabel} vs {ylabel}")
ax.legend()
plt.tight_layout()
plt.show()
def scatter_two_features(X, y, feat_x, feat_y, log_y=False, log_x=False):
fig, ax = plt.subplots(figsize=(9, 6))
xvals = X[:, feat_x].copy()
yvals = X[:, feat_y].copy()
if log_x:
xvals = np.log1p(np.maximum(xvals, 0))
if log_y:
yvals = np.log1p(np.maximum(yvals, 0))
for cls in range(5):
mask = y == cls
ax.scatter(
xvals[mask],
yvals[mask],
s=70,
c=CLASS_COLORS[cls],
edgecolor="k",
label=CLASS_LABELS[cls],
alpha=0.8
)
xlabel = FEATURE_NAMES[feat_x]
ylabel = FEATURE_NAMES[feat_y]
if log_x:
xlabel = f"log(1 + {xlabel})"
if log_y:
ylabel = f"log(1 + {ylabel})"
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_title(f"{xlabel} vs {ylabel}")
ax.legend()
plt.tight_layout()
plt.show()