Semicolon in plot: Video part #36 #297
-
Hello, In the plot_prediction function, what is the reason for using the semi-colon? Usually, in Python, we don't prefer using semi-colon right, so I am confused as to why that is present there. I see the same in the blog post as well. Could you please clarify this? These are the links to refer to what I am talking about: Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The semicolon hides Matplotlib outputs afterwards (only shows the plot). Try with/without in a notebook and you'll see what I mean. With: def plot_predictions(train_data=X_train,
train_labels=y_train,
test_data=X_test,
test_labels=y_test,
predictions=None):
"""
Plots training data, test data and compares predictions.
"""
plt.figure(figsize=(10, 7))
# Plot training data in blue
plt.scatter(train_data, train_labels, c="b", s=4, label="Training data")
# Plot test data in green
plt.scatter(test_data, test_labels, c="g", s=4, label="Testing data")
if predictions is not None:
# Plot the predictions in red (predictions were made on the test data)
plt.scatter(test_data, predictions, c="r", s=4, label="Predictions")
# Show the legend
plt.legend(prop={"size": 14});
plot_predictions(); Without: def plot_predictions(train_data=X_train,
train_labels=y_train,
test_data=X_test,
test_labels=y_test,
predictions=None):
"""
Plots training data, test data and compares predictions.
"""
plt.figure(figsize=(10, 7))
# Plot training data in blue
plt.scatter(train_data, train_labels, c="b", s=4, label="Training data")
# Plot test data in green
plt.scatter(test_data, test_labels, c="g", s=4, label="Testing data")
if predictions is not None:
# Plot the predictions in red (predictions were made on the test data)
plt.scatter(test_data, predictions, c="r", s=4, label="Predictions")
# Show the legend
plt.legend(prop={"size": 14})
plot_predictions() |
Beta Was this translation helpful? Give feedback.
Hey @kaustubhharapanahalli,
The semicolon hides Matplotlib outputs afterwards (only shows the plot).
Try with/without in a notebook and you'll see what I mean.
With: