pastebin

Paste Search Dynamic
Recent pastes
pipeline
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from sklearn.linear_model import LinearRegression
  4. from sklearn.preprocessing import PolynomialFeatures
  5. from sklearn.pipeline import Pipeline
  6.  
  7. x = np.array([[1920,1925,1930,1935,1940,1945,1950,1955,1960,1965,1970,1975,1980,1985,1990,1995,2000,2005,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2020,2025,2030,2035,2045,2055,2065,2075,2085,2095]]).T
  8. y = np.array([[55963,59737,64450,69254,71933,72147,84115,90077,94302,99209,104665,111940,117060,121049,123611,125570,126926,127768,128033,128084,128032,128057,127834,127593,127414,127237,127095,126933,125325,122544,119125,115216,106421,97441,88077,78564,70381,63125]]).T
  9.  
  10. # train a linear regression model
  11. regr = Pipeline([
  12.     ('poly', PolynomialFeatures(degree=4)),
  13.     ('linear', LinearRegression())
  14. ])
  15. regr.fit(x, y)
  16.  
  17. # make predictions
  18. xt = np.linspace(1920, 2100, num=300, dtype = 'int').reshape(300, 1)
  19. yt = regr.predict(xt)
  20.  
  21. # plot samples and regression result
  22. plt.plot(x, y, 'o')
  23. plt.plot(xt, yt)
  24. plt.show()
Parsed in 0.030 seconds