-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
42 lines (33 loc) · 1.34 KB
/
model.py
File metadata and controls
42 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This file is showing how model process data form raw to training,
# for modelling there is saperate file
# importing Required libraries
import logging
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import pickle
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
# log file initialization
logging.basicConfig(filename='debug.log', level=logging.DEBUG,
format='%(asctime)s:%(levelname)s:%(message)s')
logging.debug(' Model.py File execution started ')
# loading database with pandas library
df = pd.read_csv("iris.csv")
logging.debug(' Database Loaded ')
# model featuring
X = df[["Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width"]]
y = df["Class"]
# Data Spliting For model training
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
# training a Naive Bayes classifier
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB().fit(X_train, y_train)
gnb_predictions = gnb.predict(X_test)
accuracy = gnb.score(X_test, y_test)
print(accuracy)
# pkl export & finish log
pickle.dump(gnb, open("model.pkl", "wb"))
logging.debug(' Execution of Model.py is finished ')