MCPcopy
hub / github.com/ddbourgin/numpy-ml / plot_gp

Function plot_gp

numpy_ml/plots/nonparametric_plots.py:166–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

164
165
166def plot_gp():
167 np.random.seed(12345)
168 sns.set_context("paper", font_scale=0.65)
169
170 X_test = np.linspace(-10, 10, 100)
171 X_train = np.array([-3, 0, 7, 1, -9])
172 y_train = np.sin(X_train)
173
174 fig, axes = plt.subplots(2, 2)
175 alphas = [0, 1e-10, 1e-5, 1]
176 for ix, (ax, alpha) in enumerate(zip(axes.flatten(), alphas)):
177 G = GPRegression(kernel="RBFKernel", alpha=alpha)
178 G.fit(X_train, y_train)
179 y_pred, conf = G.predict(X_test)
180
181 ax.plot(X_train, y_train, "rx", label="observed")
182 ax.plot(X_test, np.sin(X_test), label="true fn")
183 ax.plot(X_test, y_pred, "--", label="MAP (alpha={})".format(alpha))
184 ax.fill_between(X_test, y_pred + conf, y_pred - conf, alpha=0.1)
185 ax.set_xticks([])
186 ax.set_yticks([])
187 sns.despine()
188
189 ax.legend()
190
191 plt.tight_layout()
192 plt.savefig("img/gp_alpha.png", dpi=300)
193 plt.close("all")
194
195
196def plot_gp_dist():

Callers

nothing calls this directly

Calls 3

fitMethod · 0.95
predictMethod · 0.95
GPRegressionClass · 0.90

Tested by

no test coverage detected