I having an error in my data vusalization code in pytorch?

(‘’‘’'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 ?

Your code is not formatted properly (you can post code snippets by wrapping them into three backticks ```), but generally it should work as seen here:

Training_SetofX = np.random.randn(10, 10)

def plot_predictions(train_data = Training_SetofX,
                     predictions = None):
    plt.figure(figsize = (10,7))
    if predictions is not None:
        plt.scatter(train_data, predictions, c='r', s=4, label="Predictions")

plot_predictions()
plot_predictions(predictions=np.random.randn(10, 10))

it should, but i am using google co-lab, but i am keep seeing the error

@ptrblck i solved the problem

Great! How did you solve it?

it was the “prediction” i put prediction in if statement, it was “predictions” in function parameter.