2 Naive Bayee Algorithm - Jupyter Notebook

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

In 

[ ]: ​

In [1]: import numpy as np


import matplotlib.pyplot as plt
import pandas as pd
import sklearn

In [2]: data = pd.read_csv("D:\\Course\\Python\\Datasets\\Social_Network_Ads.csv")

In [3]: data

...

In [4]: X = data.iloc[:, [2, 3]].values

In [5]: y = data.iloc[:, 4].values

In [6]: # Splitting the dataset into the Training set and Test set

In [7]: from sklearn.model_selection import train_test_split


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, rando

In [8]: # Feature Scaling

In [9]: from sklearn.preprocessing import StandardScaler # importing method and Packages


sc = StandardScaler() # creating an function using imported method
X_train = sc.fit_transform(X_train) # apply that method only on input varabile
#X_test = sc.transform(X_test)

In [10]: # Fitting Naive Bayes to the Training set

In [11]: from sklearn.naive_bayes import GaussianNB


classifier = GaussianNB()
classifier.fit(X_train, y_train)

Out[11]: GaussianNB(priors=None, var_smoothing=1e-09)

In [12]: # Predicting the Test set results

In [13]: y_pred = classifier.predict(X_test)

In [14]: y_pred
...
In [15]: y_test
...

In [16]: # Making the Confusion Matrix


from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score

In [17]: # Confusion Matrix


cm = confusion_matrix(y_test, y_pred)

In [18]: cm

Out[18]: array([[65, 3],

[ 7, 25]], dtype=int64)

In [19]: # Accuracy Score


accuracy_score(y_test, y_pred)

Out[19]: 0.9

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy