Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created October 1, 2020 18:17
Show Gist options
  • Save Abhayparashar31/7905506da955dc5a0bd7917792dbd7bf to your computer and use it in GitHub Desktop.
Save Abhayparashar31/7905506da955dc5a0bd7917792dbd7bf to your computer and use it in GitHub Desktop.
# Naive Bayes
# Importing the libraries
import numpy as np ## scientific comutaion
import matplotlib.pyplot as plt ## Visulization
import pandas as pd ## Reading data
# Importing the dataset
dataset = pd.read_csv('https://raw.githubusercontent.com/shivang98/Social-Network-ads-Boost/master/Social_Network_Ads.csv') ## Reading data from the url
X = dataset.iloc[:, [2, 3]].values ##
y = dataset.iloc[:, -1].values
# Splitting the dataset into the Training set 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.25, random_state = 0)
# Feature Scaling
# Training the Naive Bayes model on the Training set
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
# Predicting the Test set results
y_pred = classifier.predict(X_test)
print(y_pred)
# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix,accuracy_score
cm = confusion_matrix(y_test, y_pred)
score = accuracy_score(y_test,y_pred)
print(cm)
print(score*100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment