Created
July 10, 2018 22:39
-
-
Save FisherKK/86f400f6d88facbf5375286db7029ca2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([5.0])} | |
y_predicted = [predict(x, model_parameters) for x in X] | |
plt.figure(figsize=(8, 5)) | |
plt.yticks(np.arange(0, 16, 1)) | |
plt.xticks(np.arange(0, 4, 1)) | |
plt.ylabel("y") | |
plt.xlabel("x") | |
plt.ylim(-1, 16) | |
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=5.0]") | |
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, 5.0], linewidth=1, linestyle="--", color="red", | |
label="distance", alpha=0.8, zorder=1) | |
plt.plot([2.0, 2.0], [4.0, 10.0], linewidth=1, linestyle="--", color="red", | |
label="distance", alpha=0.8, zorder=1) | |
plt.plot([3.0, 3.0], [6.0, 15.0], 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, 3.25, "d1", color="red", fontsize=12) | |
plt.text(2.1, 6.75, "d2", color="red", fontsize=12) | |
plt.text(3.1, 10.25, "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