python regeression line 1

python regeression line

x = np.array([1, 2, 3, 4])
y = np.array([ 2, 8, 3, 6 ])

plt.plot(x, y, 'o')

m, b = np.polyfit(x, y, 1)
plt.plot(x, m*x + b)

Here is what the above code is Doing:
1. We’re creating two arrays, x and y, which contain the x and y values of the points we want to plot.
2. We’re plotting the points using the plt.plot() function. The ‘o’ parameter tells Python to plot the points as circles.
3. We’re using the np.polyfit() function to find the slope and y-intercept of the line of best fit.
4. We’re plotting the line of best fit using the plt.plot() function.

Similar Posts