MCPcopy
hub / github.com/scikit-learn/scikit-learn / plot_subfigure

Function plot_subfigure

examples/miscellaneous/plot_multilabel.py:54–110  ·  view source on GitHub ↗
(X, Y, subplot, title, transform)

Source from the content-addressed store, hash-verified

52
53
54def plot_subfigure(X, Y, subplot, title, transform):
55 if transform == "pca":
56 X = PCA(n_components=2).fit_transform(X)
57 elif transform == "cca":
58 X = CCA(n_components=2).fit(X, Y).transform(X)
59 else:
60 raise ValueError
61
62 min_x = np.min(X[:, 0])
63 max_x = np.max(X[:, 0])
64
65 min_y = np.min(X[:, 1])
66 max_y = np.max(X[:, 1])
67
68 classif = OneVsRestClassifier(SVC(kernel="linear"))
69 classif.fit(X, Y)
70
71 plt.subplot(2, 2, subplot)
72 plt.title(title)
73
74 zero_class = (Y[:, 0]).nonzero()
75 one_class = (Y[:, 1]).nonzero()
76 plt.scatter(X[:, 0], X[:, 1], s=40, c="gray", edgecolors=(0, 0, 0))
77 plt.scatter(
78 X[zero_class, 0],
79 X[zero_class, 1],
80 s=160,
81 edgecolors="b",
82 facecolors="none",
83 linewidths=2,
84 label="Class 1",
85 )
86 plt.scatter(
87 X[one_class, 0],
88 X[one_class, 1],
89 s=80,
90 edgecolors="orange",
91 facecolors="none",
92 linewidths=2,
93 label="Class 2",
94 )
95
96 plot_hyperplane(
97 classif.estimators_[0], min_x, max_x, "k--", "Boundary\nfor class 1"
98 )
99 plot_hyperplane(
100 classif.estimators_[1], min_x, max_x, "k-.", "Boundary\nfor class 2"
101 )
102 plt.xticks(())
103 plt.yticks(())
104
105 plt.xlim(min_x - 0.5 * max_x, max_x + 0.5 * max_x)
106 plt.ylim(min_y - 0.5 * max_y, max_y + 0.5 * max_y)
107 if subplot == 2:
108 plt.xlabel("First principal component")
109 plt.ylabel("Second principal component")
110 plt.legend(loc="upper left")
111

Callers 1

plot_multilabel.pyFile · 0.85

Calls 11

fitMethod · 0.95
PCAClass · 0.90
CCAClass · 0.90
OneVsRestClassifierClass · 0.90
SVCClass · 0.90
minMethod · 0.80
maxMethod · 0.80
plot_hyperplaneFunction · 0.70
fit_transformMethod · 0.45
transformMethod · 0.45
fitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…