How to access "points" from the function

Hi, I am doing an online Python course and this following code was something the teacher typed in the video. It worked for him but it does not run on my laptop.
The error messages I receive for the last two lines are " “points” is not defined.
I am confused about how I cann access “points” and make it work, as it is defined in my function.

Thanks for any help!

import numpy as np
import scipy.stats as ss
import matplotlib.pyplot as plt
def generate_synth_data(n=50):
    """Create two sets of points from bivariate normal distributions."""
    points = np.concatenate((ss.norm(0,1).rvs((n,2)), ss.norm(1,1).rvs((n,2))), axis=0)
    outcomes = np.concatenate((np.repeat(0, n), np.repeat(1, n))) 
    return (points, outcomes)

n=20
plt.figure()
plt.plot(points[:n, 0], points[:n, 1], "ro")
plt.plot(points[n:, 0], points[n:, 1], "bo")

You need to call the function. points is then in the first element of the tuple that’s returned.

1 Like

You need to call the function. points is then in the fi

It’s hard to say what your teacher wrote when we weren’t there, but my guess is that you left out a line:


n=20

# Missing line?
points, outcomes = generate_synth_data(n)

plt.figure()
plt.plot(points[:n, 0], points[:n, 1], "ro")
plt.plot(points[n:, 0], points[n:, 1], "bo")
1 Like

Thanks a lot!

Thanks so much!