Skip to content

Instantly share code, notes, and snippets.

@FisherKK
Created July 10, 2018 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FisherKK/ca707f8af758917dd38bc978aab37169 to your computer and use it in GitHub Desktop.
Save FisherKK/ca707f8af758917dd38bc978aab37169 to your computer and use it in GitHub Desktop.
X = np.array([[0.], [1.], [2.], [3.]])
y = np.array([0., 2., 4., 6.])
w_space = np.arange(-3., 7.5, 1.0)
parameters_list = list()
for w_value in w_space:
parameters = {'w': np.array([w_value]), 'b': 0.}
parameters_list.append(parameters)
mae_list = list()
mse_list = list()
for parameter_set in parameters_list:
mae_error = mae([predict(x, parameter_set) for x in X], y)
mae_list.append(mae_error)
mse_error = mse([predict(x, parameter_set) for x in X], y)
mse_list.append(mse_error)
f, axarr = plt.subplots(1, 2, figsize=(16, 5))
axarr[0].scatter(w_space, mae_list, edgecolor='black', linewidth='1', s=35, zorder=2)
axarr[0].plot(w_space, mae_list, zorder=1)
axarr[0].set_title("MAE")
axarr[0].set_xlabel("w")
axarr[0].set_ylabel("error")
axarr[0].set_xticks(np.arange(-3., 7.5, 1.0))
axarr[0].grid(color='blue', linestyle='--', linewidth=1, alpha=0.1)
axarr[0].spines["top"].set_visible(False)
axarr[0].spines["right"].set_visible(False)
axarr[0].spines["bottom"].set_visible(False)
axarr[0].spines["left"].set_visible(False)
axarr[1].scatter(w_space, mse_list, edgecolor='black', linewidth='1', s=35, zorder=2, c="orange")
axarr[1].plot(w_space, mse_list, zorder=1, c="orange")
axarr[1].set_title("MSE")
axarr[1].set_xlabel("w")
axarr[1].set_ylabel("error")
axarr[1].set_xticks(np.arange(-3., 7.5, 1.0))
axarr[1].grid(color='blue', linestyle='--', linewidth=1, alpha=0.1)
axarr[1].spines["top"].set_visible(False)
axarr[1].spines["right"].set_visible(False)
axarr[1].spines["bottom"].set_visible(False)
axarr[1].spines["left"].set_visible(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment