Professional Documents
Culture Documents
Year Per Capita Income (US$) 0 1970 1 1971 2 1972 3 1973 4 1974
Year Per Capita Income (US$) 0 1970 1 1971 2 1972 3 1973 4 1974
Year Per Capita Income (US$) 0 1970 1 1971 2 1972 3 1973 4 1974
[12]:
import pandas as pd
In [13]:
ca=pd.read_csv(r"C:\Users\Chromsy\Downloads\canada_per_capita_income.csv")
In [14]:
ca.head()
0 1970 3399.299037
1 1971 3768.297935
2 1972 4251.175484
3 1973 4804.463248
4 1974 5576.514583
In [15]:
inc=ca['per capita income (US$)']
In [23]:
plt.scatter(ca.year,inc, marker='+', color='red',s=100)
plt.xlabel('Year',fontsize=20)
plt.show()
In [29]:
reg = linear_model.LinearRegression()
reg.fit(ca[['year']],inc)
Out[29]: LinearRegression()
In [34]:
reg.predict([[2017]])
Out[34]: array([38803.29886875])
In [56]:
df=(1968,1969,2017,2018,2019,2020,2021,2022)
In [57]:
nxt=pd.DataFrame({"year":df})
nxt
Out[57]: year
0 1968
1 1969
2 2017
3 2018
4 2019
5 2020
6 2021
7 2022
In [58]:
jh=reg.predict(nxt)
jh
In [61]:
plt.scatter(ca.year,inc, marker='+', color='red',s=100)
plt.plot(df,jh,color="green")
plt.xlabel('Year',fontsize=20)
plt.show()
In [ ]: