Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scipy import stats
- import matplotlib.pyplot as plt
- import sklearn.metrics
- def main():
- xs = np.random.normal(4.0, 1.2, 1000)
- ys = np.random.normal(40.0, 1.2, 1000) / xs
- f2 = np.poly1d(np.polyfit(np.array(xs), np.array(ys), 2))
- f3 = np.poly1d(np.polyfit(np.array(xs), np.array(ys), 3))
- f4 = np.poly1d(np.polyfit(np.array(xs), np.array(ys), 4))
- f5 = np.poly1d(np.polyfit(np.array(xs), np.array(ys), 5))
- xp = np.linspace(0, 7, 100)
- plt.title("Polynomial Regression")
- plt.scatter(xs, ys)
- p2, = plt.plot(xp, f2(xp), c = 'r')
- p3, = plt.plot(xp, f3(xp), c = 'g')
- p4, = plt.plot(xp, f4(xp), c = 'y')
- p5, = plt.plot(xp, f5(xp), c = 'b')
- plt.legend([p2, p3, p4, p5], [label + " degree" for label in ["2nd", "3rd", "4th", "5th"]])
- plt.show()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement