forked from luficerg/churn.ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
78 lines (55 loc) · 1.97 KB
/
train.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from src.data_validation import DataValidation
from src.data_transformation import DataTransformation
from src.model_trainer import ModelTrainer
from src.model_evaluation import ModelEvaluation
import pandas as pd
import pickle
from pathlib import Path
train = pd.read_csv(Path('artifacts\data_ingestion\\train.csv'))
test = pd.read_csv(Path('artifacts\data_ingestion\\test.csv'))
model_name = Path('artifacts/model_trainer/model.pkl')
X = train.drop('Exited', axis=1)
y = train['Exited']
X_test = test.drop('Exited', axis = 1)
y_test = test['Exited']
STAGE_NAME = "Data Validation stage"
try:
print(f">>>>>> stage {STAGE_NAME} started <<<<<<")
data_validation = DataValidation(train, 'schema.yaml')
data_validation.run_validation()
print(f">>>>>> stage {STAGE_NAME} completed <<<<<<\n\nx==========x")
except Exception as e:
print(e)
raise e
STAGE_NAME = "Data Transformation stage"
try:
print(f">>>>>> stage {STAGE_NAME} started <<<<<<")
trans = DataTransformation()
dataframe = trans.drop_duplicate(X)
dataframe = trans.surname(dataframe)
X_train = trans.sklearn_pipeline(dataframe)
print(f">>>>>> stage {STAGE_NAME} completed <<<<<<\n\nx==========x")
except Exception as e:
print(e)
raise e
STAGE_NAME = "Model Trainer stage"
try:
print(f">>>>>> stage {STAGE_NAME} started <<<<<<")
model_trainer = ModelTrainer(model = "vote")
vote = model_trainer.train(train = train)
# Open the file in binary write mode
with open(model_name, "wb") as f:
pickle.dump(vote, f)
print(f">>>>>> stage {STAGE_NAME} completed <<<<<<\n\nx==========x")
except Exception as e:
print(e)
raise e
STAGE_NAME = "Model evaluation stage"
try:
print(f">>>>>> stage {STAGE_NAME} started <<<<<<")
config = ModelEvaluation()
config.test_log_into_mlflow(X_test, y_test, model_name)
print(f">>>>>> stage {STAGE_NAME} completed <<<<<<\n\nx==========x")
except Exception as e:
print(e)
raise e