Using numpy to enter noise into data

I am new to data science and have to generate 200 numbers from a uniform distribution
set this as x and generate y data using x and injecting noise from the gaussian distribution
y = 12x-4 + noise

My Approach:
x = numpy.random.rand(200) -- This will generate 200 numbers form a uniform distribution
I am not sure hot to inject noise from the guassian distribution
probably it's like z = numpy.random.randn(200) and y = 12 * x - 4 + z
Is that a correct way to inject noise?

Topic noise gaussian

Category Data Science


Yes. numpy.random.randn(n) will generate an array of random numbers (generated by the normal distribution centered at 0) of size n. So just do:

import numpy as np
x = np.random.rand(200)
y = 12 * x - 4 + np.random.rand(200)

Just as you put in your question.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.