Naivebays

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

from google.

colab import files


upload=files.upload()

Choose Files PlayTennis.csv


PlayTennis.csv(text/csv) - 434 bytes, last modified: 2/4/2024 - 100% done
Saving PlayTennis.csv to PlayTennis.csv

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data=pd.read_csv('PlayTennis.csv')

data.head()

Outlook Temperature Humidity Wind PlayTennis

0 Sunny Hot High Weak No

1 Sunny Hot High Strong No

2 Overcast Hot High Weak Yes

3 Rain Mild High Weak Yes

4 Rain Cool Normal Weak Yes

data.columns

output Index(['Outlook', 'Temperature', 'Humidity', 'Wind', 'PlayTennis'], dtype='object')

X_train=pd.get_dummies(data[['Outlook','Temperature','Humidity','Wind']])
y_train=pd.get_dummies(data[['PlayTennis']])
print(y_train)

PlayTennis_No PlayTennis_Yes
0 1 0
1 1 0
2 0 1
3 0 1
4 0 1
5 1 0
6 0 1
7 1 0
8 0 1
9 0 1
10 0 1
11 0 1
12 0 1
13 1 0

print(X_train)

Outlook_Overcast Outlook_Rain Outlook_Sunny Temperature_Cool \


0 0 0 1 0
1 0 0 1 0
2 1 0 0 0
3 0 1 0 0
4 0 1 0 1
5 0 1 0 1
6 1 0 0 1
7 0 0 1 0
8 0 0 1 1
9 0 1 0 0
10 0 0 1 0
11 1 0 0 0
12 1 0 0 0
13 0 1 0 0

Temperature_Hot Temperature_Mild Humidity_High Humidity_Normal \


0 1 0 1 0
1 1 0 1 0
2 1 0 1 0
3 0 1 1 0
4 0 0 0 1
5 0 0 0 1
6 0 0 0 1
7 0 1 1 0
8 0 0 0 1
9 0 1 0 1
10 0 1 0 1
11 0 1 1 0
12 1 0 0 1
13 0 1 1 0

Wind_Strong Wind_Weak
0 0 1
1 1 0
2 0 1
3 0 1
4 0 1
5 1 0
6 1 0
7 0 1
8 0 1
9 0 1
10 1 0
11 1 0
12 0 1
13 1 0

from sklearn.naive_bayes import GaussianNB

y_train=pd.get_dummies(data['PlayTennis'],drop_first=True)
print(y_train)

Yes
0 0
1 0
2 1
3 1
4 1
5 0
6 1
7 0
8 1
9 1
10 1
11 1
12 1
13 0

model=GaussianNB()

model.fit(X_train,y_train)

/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py:1143: DataConversionWarning: A column-vector y was passed when a


y = column_or_1d(y, warn=True)
▾ GaussianNB
GaussianNB()

predict=model.predict([[1,0,0,0,1,0,1,0,0,1]])

/usr/local/lib/python3.10/dist-packages/sklearn/base.py:439: UserWarning: X does not have valid feature names, but GaussianNB was fi
warnings.warn(

print(predict)

[1]

You might also like