Naivy
Bay’s Classification Demo 2
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import sklearn
dataset =
pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:, [1, 2, 3]].values
y = dataset.iloc[:, -1].values
X
y
from sklearn.preprocessing import
LabelEncoder
le = LabelEncoder()
X[:,0] = le.fit_transform(X[:,0])
X
from sklearn.model_selection import
train_test_split
X_train, X_test, y_train, y_test =
train_test_split(X, y, test_size = 0.20, random_state = 0)
from sklearn.preprocessing import
StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
X_train
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
y_pred
= classifier.predict(X_test)
y_pred
y_test
# Making the Confusion Matrix
from sklearn.metrics import
confusion_matrix, accuracy_score
ac = accuracy_score(y_test,y_pred)
cm = confusion_matrix(y_test, y_pred)
ac
cm
No comments:
Post a Comment