This repository has been archived by the owner on Oct 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
Machine_Learning_Projects/simple_linear_regression/boston_dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pandas as pd | ||
from sklearn import datasets | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
boton=datasets.load_boston | ||
print(boston.keys()) | ||
df=pd.Dataframe(boston.data) | ||
df.columns=boston.frature_names | ||
df['PRICE']=boston.target | ||
df.head() | ||
|
||
cdf=df[['ZN','INDUS','CHAS','RM','TAX','PTRATIO','PRICE','CRIM']] | ||
cdf.head() | ||
|
||
cdf.head(11) | ||
|
||
ktr=cdf[['ZN','INDUS','RM','TAX','PTRATIO','PRICE','CRIM']] | ||
ktr.hist() | ||
plt.show() | ||
plt.scatter(cdf.CRIM,cdf.PRICE,color='blue') | ||
plt.xlabel('crime_rate') | ||
plt.ylabel('price of houses') | ||
plt.title('crime_rate vs price of houses') | ||
plt.show() | ||
|
||
msk=np.random.rand((len(df)))<0.8 | ||
train=cdf[msk] | ||
test=cdf[~msk] | ||
|
||
plt.scatter(train.CRIM,train.PRICE,color='blue') | ||
plt.xlabel('crime rate') | ||
plt.ylabel('price of houses') | ||
plt.show() | ||
|
||
from sklearn import linear_model | ||
lr=linear_model.LinearRegression() | ||
x=np.asanyarray(train['CRIM']) | ||
print(pd.DataFrame(x)) | ||
print(pd.DataFrame(y)) | ||
print(x) | ||
y=np.asanyarray(train['PRICE']) | ||
a=np.reshape(x,(-1,1)) | ||
b=np.reshape(y,(-1,1)) | ||
lr.fit(a,b) | ||
print(lr.coef_) | ||
print(lr.intercept_) | ||
|
||
plt.scatter(a,b,color='blue') | ||
plt.plot(a,lr.coef_[0][0]*a+lr.intercept_[0],'-r') | ||
plt.xlabel("crime rate") | ||
plt.ylabel("price of houses") | ||
plt.title("crime vs price") | ||
plt.show() |