"""
<div style="background-color:#98D7C2;padding:1rem 1rem;border-radius:1rem">
<h1 style="color:black">Logistic Regression :Facebook Ads Prediction</h1>

</div>

"""
"""
<p>This prediction model indicates whether the person have clicked on the facebook ads based on various factors. This dataset contains information on
<li>    Names of people
<li> Time spent on the site
<li> Salary
<li> Clicked 
    </li>
    </p>
 

"""
"""
![https://www.adweek.com/wp-content/uploads/2019/07/SocialAdvertisingGraphic.jpg](https://www.adweek.com/wp-content/uploads/2019/07/SocialAdvertisingGraphic.jpg)
"""
"""
# Import the libraries
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
"""
# Import dataset 
"""
data = pd.read_csv("../input/facebook-ads-dataset/Facebook_Ads_2.csv")
data.head()
data.shape
"""
# Separate the features and target variable
"""
X =data.iloc[:,1:-1].values # Independent variables
y =data.iloc[:,-1].values # Dependent variable
X
"""
# Missing data
"""
data.info()
data.isna().sum()
"""
![https://media.giphy.com/media/LwHkZcEhYZYFhDrh8X/giphy.gif](https://media.giphy.com/media/LwHkZcEhYZYFhDrh8X/giphy.gif)

Yayy ! We have no missing data. Dataset is clean and ready to use.
"""
"""
# Visualizing data
"""
"""
[]()
"""
sns.scatterplot(x="Time Spent on Site",y="Salary",data=data,hue='Clicked')
"""
# Splitting dataset to train and test set
"""
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
X_train.shape, X_test.shape
"""
# Train the model
"""
from sklearn.linear_model import LogisticRegression
logit = LogisticRegression()
logit.fit(X_train,y_train)
y_trainpred = logit.predict(X_train)
y_trainpred
#Accuracy score of trained data
print("Accuracy:",np.mean(y_trainpred == y_train))
from sklearn.metrics import accuracy_score,confusion_matrix
accuracy_score(y_train,y_trainpred)
y_testpred = logit.predict(X_test)
y_testpred
y_test
y_testpred
#Accuracy for test data
print("Accuracy:",np.mean(y_testpred == y_test))
# Accuracy score using metrics 
accuracy_score(y_test,y_testpred)
confusion_matrix(y_train,y_trainpred)
"""
# Feature scaling
"""
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train= sc.fit_transform(X_train)
X_train
X_test= sc.transform(X_test)
X_test
"""
# Re train the model
"""
#Fitting the scaled data into logistic mmodel
logit.fit(X_train,y_train)
y_trainpred = logit.predict(X_train)
y_trainpred
print("Accuracy score:",np.mean(y_trainpred== y_train))
accuracy_score(y_train,y_trainpred) 
# Fitting the test model
logit.fit(X_test,y_test)

# Prediction of test data
y_testpred = logit.predict(X_test)
y_testpred
print("Accuracy score:",np.mean(y_testpred== y_test))
#Accuracy score using metrics package
accuracy_score(y_test,y_testpred)
confusion_matrix(y_test,y_testpred)
"""
<h1 style="background-color:#167D7F;color:white;padding:2rem 2rem;text-align: center;border-radius:0.75rem"> THANK YOU</h1>
"""