code show as below:
#-*- encoding:utf-8 -*- import sys reload(sys) sys.setdefaultencoding from sklearn import linear_model import numpy as np import pandas as pd #Read data and create a data table named cost_and_click year_population=pd.DataFrame(pd.read_excel('year_population.xls')) X=np.array(year_population['year']) X=X.tolist() #Set the number of clicks as the dependent variable Y Y=np.array(year_population['population']) Y=Y.tolist() #--------------------------------------------------------------- z1 = np.polyfit(X, Y, 4) #polynomial fit p1 = e.g. poly1d (z1) print"-"*40 print z1 #polynomial coefficients print"-"*40 print p1 # complete output print"☆☆☆☆☆☆☆☆Start prediction☆☆☆☆☆☆☆☆☆☆" print p1(2010)
Data are as follows:
year population 1790 3.9 1800 5.3 1810 7.2 1820 9.6 1830 12.9 1840 17.1 1850 23.2 1860 31.4 1870 38.6 1880 50.2 1890 62.9 1900 76 1910 92 1920 106.5 1930 123.2 1940 131.7 1950 150.7 1960 179.3 1970 204 1980 226.5 1990 251.4 2000 281.4