Skip to content

Instantly share code, notes, and snippets.

@FisherKK
Created July 10, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FisherKK/15eb3f36444fb3dd4ed64c21ab300bfc to your computer and use it in GitHub Desktop.
Save FisherKK/15eb3f36444fb3dd4ed64c21ab300bfc to your computer and use it in GitHub Desktop.
X = np.array([[0.0], [1.0], [2.0], [3.0]])
y = np.array([0.0, 2.0, 4.0, 6.0])
model_parameters = {'b': 0.0, 'w': np.array([0.5])}
y_predicted = [predict(x, model_parameters) for x in X]
plt.figure(figsize=(8, 5))
plt.yticks(np.arange(0, 7, 0.5))
plt.xticks(np.arange(0, 4, 1))
plt.ylabel("y")
plt.xlabel("x")
plt.ylim(-1, 7)
plt.grid("on", linestyle='--', linewidth=1, alpha=0.3)
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)
plt.gca().spines["bottom"].set_visible(False)
plt.gca().spines["left"].set_visible(False)
plt.title("y = wx, [w=0.5]")
plt.scatter(X, y, edgecolor='black', linewidth=1,
label="expected", s=80, zorder=2)
plt.scatter(X, y_predicted, edgecolor='black', linewidth=1,
label="predicted", s=80, zorder=2)
plt.plot(X, y_predicted, zorder=1, c="orange")
plt.plot([1.0, 1.0], [2.0, 0.5], linewidth=1, linestyle="--", color="red",
label="distance", alpha=0.8, zorder=1)
plt.plot([2.0, 2.0], [4.0, 1.0], linewidth=1, linestyle="--", color="red",
label="distance", alpha=0.8, zorder=1)
plt.plot([3.0, 3.0], [6.0, 1.5], linewidth=1, linestyle="--", color="red",
label="distance", alpha=0.8, zorder=1)
plt.text(0.1, -0.35, "d0", color="red", fontsize=12)
plt.text(1.1, 1.25, "d1", color="red", fontsize=12)
plt.text(2.1, 2.25, "d2", color="red", fontsize=12)
plt.text(3.1, 3.75, "d3", color="red", fontsize=12)
plt.legend();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment