Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ML/1_linear_reg/Exercise/ans
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
df=pd.read_csv(r"C:\Users\Lenovo\Documents\Machine Learning\canada_per_capita_income.csv")
df
reg=linear_model.LinearRegression()
reg.fit(df[['year']],df['per_capita_income (US$)'])
reg.predict([[2020]])
%matplotlib inline
import matplotlib.pyplot as plt

plt.xlabel('Year')
plt.ylabel('Per Capita Income')
plt.scatter(df.year, df['per_capita_income (US$)'], color='red', marker='+')
plt.plot(df.year, reg.predict(df[['year']]), color='green')
plt.show()