-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnaive_bayes_model.py
More file actions
25 lines (20 loc) · 839 Bytes
/
Copy pathnaive_bayes_model.py
File metadata and controls
25 lines (20 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.naive_bayes import GaussianNB
np.random.seed(42)
np.set_printoptions(precision=6,suppress=True)
weather=['sunny','rainy','cloudy','rainy','sunny','sunny','cloudy','cloudy','sunny']
temperature=['warm','cold','warm','warm','warm','cool','cool','warm','cold']
walk=['yes','no','yes','no','yes','yes','no','yes','no']
raw_df=pd.DataFrame(data={'weather':weather,'temperature':temperature,'walk':walk})
df=raw_df.copy()
encoder=LabelEncoder()
df['walk']=encoder.fit_transform(walk)
df=pd.get_dummies(df,columns=['weather','temperature'],drop_first=True)
data=df.copy()
target=data.pop('walk')
model=GaussianNB()
model.fit(data,target)
print("Model score",model.score(data,target))
print(encoder.classes_[model.predict(data.iloc[[0]])][0])