"""
# Introduction of Regression
"""
"""
A regression problem is when the output variable is a real or continuous value, such as “salary” or “weight”. Many different models can be used, the simplest is the linear regression. It tries to fit data with the best hyper-plane which goes through the points.

For Examples:

Predicting age of a person

"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
"""
#How our Data looks
"""
housing_df = pd.read_csv('../input/usa-housing/USA_Housing.csv')
housing_df.head(2)
housing_df.info()
housing_df.describe()
housing_df.columns
"""
#EDA
"""
sns.pairplot(housing_df)
sns.distplot(housing_df['Price'])
sns.heatmap(housing_df.corr())
"""
#Training Linear Regression
"""
X = housing_df[['Avg. Area Income', 'Avg. Area House Age', 'Avg. Area Number of Rooms',
       'Avg. Area Number of Bedrooms', 'Area Population']]
y = housing_df['Price']
"""
#Train Test Spliting
"""
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=123)
X_train.shape
X_test.shape
"""
#Model Creation and training
"""
from sklearn.linear_model import LinearRegression
lr_model = LinearRegression()
lr_model.fit(X_train, y_train)
"""
#Evaluation of Trained Model
"""
print(lr_model.intercept_)
#'''price = c1*'Avg. Area Income'+ c2* 'Avg. Area House Age'+ c3*'Avg. Area Number of Rooms
 #      +c4*'Avg. Area Number of Bedrooms' +c5* 'Area Population''''

coef_hosing = pd.DataFrame(lr_model.coef_, X.columns, columns=['Coefficient'])
coef_hosing
# If all other features are fixed, then 1 unit change in Avg. Area Income Price would increase 21.60 Rupees
# Making Prediction by making use of Trained Model
predictions = lr_model.predict(X_test)
plt.scatter(y_test, predictions)
sns.distplot((y_test-predictions))
from sklearn import metrics
mae = metrics.mean_absolute_error(y_test, predictions)
mse = metrics.mean_squared_error(y_test, predictions)
rmse = np.sqrt(mse)
X_test.head(2)
pred_1 = lr_model.predict(X_test.head(1))
pred_1
y_test.head(1)