# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
data = pd.read_csv("/kaggle/input/social-network-ads/Social_Network_Ads.csv")
data.head()
data['Purchased'].value_counts()
data.describe()
data.info()
%matplotlib inline
# for plotting histogram

import matplotlib.pyplot as plt
data.hist(bins = 50, figsize = (20, 15))
import matplotlib.pyplot as plt
import seaborn as sns
sns.lmplot('Age', 'EstimatedSalary', data, hue='Purchased', fit_reg=False)
fig = plt.gcf()
fig.set_size_inches(8, 6)
plt.show()
"""
## Train-Test Splitting
"""
from sklearn.model_selection import train_test_split
train_set, test_set = train_test_split(data, test_size=0.2, random_state=42)

print(len(train_set), len(test_set))
train_set.shape
from pandas.plotting import scatter_matrix
attributes = ["Purchased", "Age", "EstimatedSalary"]
scatter_matrix(train_set[attributes], figsize=(12, 8))
%matplotlib inline
"""
## Correlations
"""
corr_matrix = train_set.corr()
corr_matrix
x_train_set = train_set.drop("Purchased", axis = 1)
y_train_set = train_set["Purchased"]

x_test_set = test_set.drop("Purchased", axis = 1)
y_test_set = test_set["Purchased"]
x_train_set.shape
y_train_set.shape
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(x_train_set,y_train_set) #fitting the model 
y_pred = clf.predict(x_test_set) #prediction
y_train_pred = clf.predict(x_train_set)
"""
## Confusion matrix
"""
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test_set, y_pred)
"""
## Precision and Recall
"""
from sklearn.metrics import precision_score, recall_score
precision_score(y_test_set, y_pred)
recall_score(y_test_set, y_pred)
"""
## F-Score
"""
from sklearn.metrics import f1_score
f1_score(y_test_set, y_pred)
"""
## Accuracy
"""
from sklearn.metrics import accuracy_score
accuracy_score(y_test_set, y_pred)