import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

"""
Explanation: <a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>

Logistic Regression Project
In this project we will be working with a fake advertising data set, indicating whether or not a particular internet user clicked on an Advertisement. We will try to create a model that will predict whether or not they will click on an ad based off the features of that user.
This data set contains the following features:

'Daily Time Spent on Site': consumer time on site in minutes
'Age': cutomer age in years
'Area Income': Avg. Income of geographical area of consumer
'Daily Internet Usage': Avg. minutes a day consumer is on the internet
'Ad Topic Line': Headline of the advertisement
'City': City of consumer
'Male': Whether or not consumer was male
'Country': Country of consumer
'Timestamp': Time at which consumer clicked on Ad or closed window
'Clicked on Ad': 0 or 1 indicated clicking on Ad

Import Libraries
Import a few libraries you think you'll need (Or just import them as you go along!)
End of explanation
"""


ad_data = pd.read_csv('advertising.csv')

"""
Explanation: Get the Data
Read in the advertising.csv file and set it to a data frame called ad_data.
End of explanation
"""


ad_data.head()

"""
Explanation: Check the head of ad_data
End of explanation
"""


ad_data.info()

ad_data.describe()

"""
Explanation: Use info and describe() on ad_data
End of explanation
"""


sns.distplot(ad_data['Age'],kde=False,bins=30,color='blue')

"""
Explanation: Exploratory Data Analysis
Let's use seaborn to explore the data!
Try recreating the plots shown below!
 Create a histogram of the Age
End of explanation
"""


sns.jointplot(data=ad_data,x='Age',y='Area Income')

"""
Explanation: Create a jointplot showing Area Income versus Age.
End of explanation
"""


sns.jointplot(data=ad_data,x='Age',y='Daily Time Spent on Site',kind='kde')

"""
Explanation: Create a jointplot showing the kde distributions of Daily Time spent on site vs. Age.
End of explanation
"""


sns.jointplot(data=ad_data,x='Daily Time Spent on Site',y='Daily Internet Usage',color='green')

"""
Explanation: Create a jointplot of 'Daily Time Spent on Site' vs. 'Daily Internet Usage'
End of explanation
"""


sns.pairplot(ad_data,hue='Clicked on Ad')

"""
Explanation: Finally, create a pairplot with the hue defined by the 'Clicked on Ad' column feature.
End of explanation
"""


ad_data.columns

from sklearn.model_selection import train_test_split

X = ad_data[['Daily Time Spent on Site', 'Age', 'Area Income','Daily Internet Usage','Male']]
y = ad_data['Clicked on Ad']

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=101)

"""
Explanation: Logistic Regression
Now it's time to do a train test split, and train our model!
You'll have the freedom here to choose columns that you want to train on!
 Split the data into training set and testing set using train_test_split
End of explanation
"""


from sklearn.linear_model import LogisticRegression

logmodel = LogisticRegression()

logmodel.fit(X_train,y_train)

logmodel.coef_

"""
Explanation: Train and fit a logistic regression model on the training set.
End of explanation
"""


predictions = logmodel.predict(X_test)

"""
Explanation: Predictions and Evaluations
 Now predict values for the testing data.
End of explanation
"""


from sklearn.metrics import classification_report

print(classification_report(y_test,predictions))

"""
Explanation: Create a classification report for the model.
End of explanation
"""


from collections import OrderedDict

d = OrderedDict({'Daily Time Spent on Site': 500, 'Age': 18, 'Area Income':23000,'Daily Internet Usage': 160,'Male': 1})
df = pd.DataFrame(d,index=[0])

sample_predict = logmodel.predict(df)

print(sample_predict)

"""
Explanation: Great Job!
End of explanation
"""


