(‘’‘’'I am having an error in data visualization code,this is the code:
import torch
from torch import nn
import matplotlib.pyplot as plt
weight =0.7
bias=0.3
X = torch.arange(0,3,0.02)
Y = weight * X * bias
Training_Set = int(0.8 * len(X))
Training_SetofX = len(X[:Training_Set])
Testing_SetofX = len(X[Training_Set:])
Training_SetofY = len(Y[:Training_Set])
Testing_SetofY = len(Y[Training_Set:])
print(f"Training set of X {len(X[:Training_Set])}“)
print(f"Testing set of X {len(X[Training_Set:])}”)
print(f"Training set of Y {len(Y[:Training_Set])}“)
print(f"Testing set of Y {len(Y[Training_Set:])}”)
def plot_predictions(train_data = Training_SetofX,
train_label = Training_SetofY,
test_data = Testing_SetofX,
test_label = Testing_SetofY,
predictions = None):
plt.figure(figsize = (10,7))
plt.scatter(train_data,train_label,c=“b”,s=4,label=“Training data”)
plt.scatter(test_data,test_label, c=“g”,s=4,label=“Testing data”)
if predictions is not None:
plt.scatter(test_data,predictions,c=‘r’,s=4,label=“Predictions”)
plt.legend(prop={“size” : 14})
plot_predictions()
error:-NameError Traceback (most recent call last)
in
26 plt.scatter(train_data,train_label,c=“b”,s=4,label=“Training data”)
27 plt.scatter(test_data,test_label, c=“g”,s=4,label=“Testing data”)
—> 28 if predictions is not None:
29 plt.scatter(test_data,predictions,c=‘r’,s=4,label=“Predictions”)
30 ‘’‘’)
NameError: name ‘predictions’ is not defined
Can any one help me to solve this ?