0% found this document useful (0 votes)
6 views2 pages

HOUSEPRICENB - Ipynb - Colab

Uploaded by

Shivani Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

HOUSEPRICENB - Ipynb - Colab

Uploaded by

Shivani Ray
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/23/24, 11:34 PM HOUSEPRICENB.

ipynb - Colab

Double-click (or enter) to edit

# Import packages
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, classification_report
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()

houseprice_data = pd.read_csv("housepricedata.csv")

# Creating test and training sets


feature_cols = ['LotArea', 'OverallQual', 'OverallCond', 'TotalBsmtSF', 'FullBath', 'HalfBath', 'BedroomAbvGr', 'TotRmsAbvGrd', 'Fireplaces', 'GarageArea'] # Feature selection
x = houseprice_data[feature_cols] # Features
y = houseprice_data['AboveMedianPrice'] # Target variable

# Split dataset into training set and test set


xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.3, random_state=1) # 70% training and 30% test

# Running the model


# Init the Gaussian Classifier
model = GaussianNB()
# Train the model
model.fit(xtrain, ytrain)
# Predict Output
pred = model.predict(xtest)

# Model Evaluation
print(confusion_matrix(ytest, pred))
print(classification_report(ytest, pred))

[[202 19]
[ 34 183]]
precision recall f1-score support

0 0.86 0.91 0.88 221


1 0.91 0.84 0.87 217

accuracy 0.88 438


macro avg 0.88 0.88 0.88 438
weighted avg 0.88 0.88 0.88 438

https://colab.research.google.com/drive/199gaWiUJE4ekm2U_i0WO1-LVnjujrFp7#scrollTo=GSeR838OgX-d&printMode=true 1/2
6/23/24, 11:34 PM HOUSEPRICENB.ipynb - Colab
# Creating a heatmap
# Plot Confusion Matrix
mat = confusion_matrix(pred, ytest)
names = np.unique(pred)
sns.heatmap(mat, square=True, annot=True, fmt='d', cbar=False,
xticklabels=names, yticklabels=names)
plt.xlabel('Truth')
plt.ylabel('Predicted')
plt.show()

https://colab.research.google.com/drive/199gaWiUJE4ekm2U_i0WO1-LVnjujrFp7#scrollTo=GSeR838OgX-d&printMode=true 2/2

You might also like