JustDataML 0.0.26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- JDML/JDML.py +153 -0
- JDML/__init__.py +1 -0
- JDML/source/Configuration.py +64 -0
- JDML/source/Exception.py +21 -0
- JDML/source/Logger.py +16 -0
- JDML/source/Pipeline/Predict_Pipeline.py +2249 -0
- JDML/source/Pipeline/Train_Pipeline.py +49 -0
- JDML/source/Pipeline/__init__.py +0 -0
- JDML/source/Utils.py +356 -0
- JDML/source/__init__.py +0 -0
- JDML/source/components/Data_Transformation.py +161 -0
- JDML/source/components/Data_ingestion.py +60 -0
- JDML/source/components/Model_Trainer.py +103 -0
- JDML/source/components/__init__.py +0 -0
- JustDataML-0.0.26.dist-info/METADATA +266 -0
- JustDataML-0.0.26.dist-info/RECORD +19 -0
- JustDataML-0.0.26.dist-info/WHEEL +5 -0
- JustDataML-0.0.26.dist-info/entry_points.txt +2 -0
- JustDataML-0.0.26.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2249 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import pandas as pd
|
|
4
|
+
|
|
5
|
+
from ...source.Logger import logging
|
|
6
|
+
from ...source.Exception import CustomException
|
|
7
|
+
from ...source.Utils import load_object
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PredictPipeline:
|
|
11
|
+
|
|
12
|
+
""""
|
|
13
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
14
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, problem_objective):
|
|
19
|
+
self.Problem_Objective = problem_objective
|
|
20
|
+
|
|
21
|
+
def predict(self, features):
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
25
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
31
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
32
|
+
|
|
33
|
+
if self.Problem_Objective=="Classification":
|
|
34
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
35
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
36
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
37
|
+
|
|
38
|
+
model = load_object(file_path=model_path)
|
|
39
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
40
|
+
print("Model Loaded Succesfully")
|
|
41
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
42
|
+
data_scaled = preprocessor.transform(features)
|
|
43
|
+
preds = model.predict(data_scaled)
|
|
44
|
+
if self.Problem_Objective=="Classification":
|
|
45
|
+
preds = preds.astype(int)
|
|
46
|
+
preds = label_encoder.inverse_transform(preds)
|
|
47
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
48
|
+
|
|
49
|
+
return preds
|
|
50
|
+
|
|
51
|
+
except Exception as e:
|
|
52
|
+
raise CustomException(e, sys)
|
|
53
|
+
|
|
54
|
+
class CustomData:
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
58
|
+
It will take care of all the Features .
|
|
59
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
60
|
+
providing flexibility in working with different datasets.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __init__(self,features_cols, **kwargs):
|
|
65
|
+
try:
|
|
66
|
+
self.Features_Cols = features_cols
|
|
67
|
+
for feature in self.Features_Cols:
|
|
68
|
+
# print(feature)
|
|
69
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
70
|
+
|
|
71
|
+
except Exception as e:
|
|
72
|
+
raise CustomException(e, sys)
|
|
73
|
+
|
|
74
|
+
def get_data_as_data_frame(self):
|
|
75
|
+
|
|
76
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
custom_data_input_dict = {}
|
|
80
|
+
for feature in self.Features_Cols:
|
|
81
|
+
feature_value = getattr(self,feature)
|
|
82
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
83
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
84
|
+
logging.info("Features Loaded Succesfully")
|
|
85
|
+
#print(custom_data_input_dict)
|
|
86
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
87
|
+
|
|
88
|
+
except Exception as e:
|
|
89
|
+
raise CustomException(e, sys)
|
|
90
|
+
class PredictPipeline:
|
|
91
|
+
|
|
92
|
+
""""
|
|
93
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
94
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
def __init__(self, problem_objective):
|
|
99
|
+
self.Problem_Objective = problem_objective
|
|
100
|
+
|
|
101
|
+
def predict(self, features):
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
105
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
111
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
112
|
+
|
|
113
|
+
if self.Problem_Objective=="Classification":
|
|
114
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
115
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
116
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
117
|
+
|
|
118
|
+
model = load_object(file_path=model_path)
|
|
119
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
120
|
+
print("Model Loaded Succesfully")
|
|
121
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
122
|
+
data_scaled = preprocessor.transform(features)
|
|
123
|
+
preds = model.predict(data_scaled)
|
|
124
|
+
if self.Problem_Objective=="Classification":
|
|
125
|
+
preds = preds.astype(int)
|
|
126
|
+
preds = label_encoder.inverse_transform(preds)
|
|
127
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
128
|
+
|
|
129
|
+
return preds
|
|
130
|
+
|
|
131
|
+
except Exception as e:
|
|
132
|
+
raise CustomException(e, sys)
|
|
133
|
+
|
|
134
|
+
class CustomData:
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
138
|
+
It will take care of all the Features .
|
|
139
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
140
|
+
providing flexibility in working with different datasets.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def __init__(self,features_cols, **kwargs):
|
|
145
|
+
try:
|
|
146
|
+
self.Features_Cols = features_cols
|
|
147
|
+
for feature in self.Features_Cols:
|
|
148
|
+
# print(feature)
|
|
149
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
150
|
+
|
|
151
|
+
except Exception as e:
|
|
152
|
+
raise CustomException(e, sys)
|
|
153
|
+
|
|
154
|
+
def get_data_as_data_frame(self):
|
|
155
|
+
|
|
156
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
custom_data_input_dict = {}
|
|
160
|
+
for feature in self.Features_Cols:
|
|
161
|
+
feature_value = getattr(self,feature)
|
|
162
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
163
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
164
|
+
logging.info("Features Loaded Succesfully")
|
|
165
|
+
#print(custom_data_input_dict)
|
|
166
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
167
|
+
|
|
168
|
+
except Exception as e:
|
|
169
|
+
raise CustomException(e, sys)
|
|
170
|
+
class PredictPipeline:
|
|
171
|
+
|
|
172
|
+
""""
|
|
173
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
174
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
175
|
+
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
def __init__(self, problem_objective):
|
|
179
|
+
self.Problem_Objective = problem_objective
|
|
180
|
+
|
|
181
|
+
def predict(self, features):
|
|
182
|
+
|
|
183
|
+
"""
|
|
184
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
185
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
186
|
+
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
try:
|
|
190
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
191
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
192
|
+
|
|
193
|
+
if self.Problem_Objective=="Classification":
|
|
194
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
195
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
196
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
197
|
+
|
|
198
|
+
model = load_object(file_path=model_path)
|
|
199
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
200
|
+
print("Model Loaded Succesfully")
|
|
201
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
202
|
+
data_scaled = preprocessor.transform(features)
|
|
203
|
+
preds = model.predict(data_scaled)
|
|
204
|
+
if self.Problem_Objective=="Classification":
|
|
205
|
+
preds = preds.astype(int)
|
|
206
|
+
preds = label_encoder.inverse_transform(preds)
|
|
207
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
208
|
+
|
|
209
|
+
return preds
|
|
210
|
+
|
|
211
|
+
except Exception as e:
|
|
212
|
+
raise CustomException(e, sys)
|
|
213
|
+
|
|
214
|
+
class CustomData:
|
|
215
|
+
|
|
216
|
+
"""
|
|
217
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
218
|
+
It will take care of all the Features .
|
|
219
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
220
|
+
providing flexibility in working with different datasets.
|
|
221
|
+
"""
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def __init__(self,features_cols, **kwargs):
|
|
225
|
+
try:
|
|
226
|
+
self.Features_Cols = features_cols
|
|
227
|
+
for feature in self.Features_Cols:
|
|
228
|
+
# print(feature)
|
|
229
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
230
|
+
|
|
231
|
+
except Exception as e:
|
|
232
|
+
raise CustomException(e, sys)
|
|
233
|
+
|
|
234
|
+
def get_data_as_data_frame(self):
|
|
235
|
+
|
|
236
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
237
|
+
|
|
238
|
+
try:
|
|
239
|
+
custom_data_input_dict = {}
|
|
240
|
+
for feature in self.Features_Cols:
|
|
241
|
+
feature_value = getattr(self,feature)
|
|
242
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
243
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
244
|
+
logging.info("Features Loaded Succesfully")
|
|
245
|
+
#print(custom_data_input_dict)
|
|
246
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
247
|
+
|
|
248
|
+
except Exception as e:
|
|
249
|
+
raise CustomException(e, sys)
|
|
250
|
+
class PredictPipeline:
|
|
251
|
+
|
|
252
|
+
""""
|
|
253
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
254
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
def __init__(self, problem_objective):
|
|
259
|
+
self.Problem_Objective = problem_objective
|
|
260
|
+
|
|
261
|
+
def predict(self, features):
|
|
262
|
+
|
|
263
|
+
"""
|
|
264
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
265
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
266
|
+
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
271
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
272
|
+
|
|
273
|
+
if self.Problem_Objective=="Classification":
|
|
274
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
275
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
276
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
277
|
+
|
|
278
|
+
model = load_object(file_path=model_path)
|
|
279
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
280
|
+
print("Model Loaded Succesfully")
|
|
281
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
282
|
+
data_scaled = preprocessor.transform(features)
|
|
283
|
+
preds = model.predict(data_scaled)
|
|
284
|
+
if self.Problem_Objective=="Classification":
|
|
285
|
+
preds = preds.astype(int)
|
|
286
|
+
preds = label_encoder.inverse_transform(preds)
|
|
287
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
288
|
+
|
|
289
|
+
return preds
|
|
290
|
+
|
|
291
|
+
except Exception as e:
|
|
292
|
+
raise CustomException(e, sys)
|
|
293
|
+
|
|
294
|
+
class CustomData:
|
|
295
|
+
|
|
296
|
+
"""
|
|
297
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
298
|
+
It will take care of all the Features .
|
|
299
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
300
|
+
providing flexibility in working with different datasets.
|
|
301
|
+
"""
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def __init__(self,features_cols, **kwargs):
|
|
305
|
+
try:
|
|
306
|
+
self.Features_Cols = features_cols
|
|
307
|
+
for feature in self.Features_Cols:
|
|
308
|
+
# print(feature)
|
|
309
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
310
|
+
|
|
311
|
+
except Exception as e:
|
|
312
|
+
raise CustomException(e, sys)
|
|
313
|
+
|
|
314
|
+
def get_data_as_data_frame(self):
|
|
315
|
+
|
|
316
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
317
|
+
|
|
318
|
+
try:
|
|
319
|
+
custom_data_input_dict = {}
|
|
320
|
+
for feature in self.Features_Cols:
|
|
321
|
+
feature_value = getattr(self,feature)
|
|
322
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
323
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
324
|
+
logging.info("Features Loaded Succesfully")
|
|
325
|
+
#print(custom_data_input_dict)
|
|
326
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
327
|
+
|
|
328
|
+
except Exception as e:
|
|
329
|
+
raise CustomException(e, sys)
|
|
330
|
+
class PredictPipeline:
|
|
331
|
+
|
|
332
|
+
""""
|
|
333
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
334
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
335
|
+
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
def __init__(self, problem_objective):
|
|
339
|
+
self.Problem_Objective = problem_objective
|
|
340
|
+
|
|
341
|
+
def predict(self, features):
|
|
342
|
+
|
|
343
|
+
"""
|
|
344
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
345
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
346
|
+
|
|
347
|
+
"""
|
|
348
|
+
|
|
349
|
+
try:
|
|
350
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
351
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
352
|
+
|
|
353
|
+
if self.Problem_Objective=="Classification":
|
|
354
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
355
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
356
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
357
|
+
|
|
358
|
+
model = load_object(file_path=model_path)
|
|
359
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
360
|
+
print("Model Loaded Succesfully")
|
|
361
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
362
|
+
data_scaled = preprocessor.transform(features)
|
|
363
|
+
preds = model.predict(data_scaled)
|
|
364
|
+
if self.Problem_Objective=="Classification":
|
|
365
|
+
preds = preds.astype(int)
|
|
366
|
+
preds = label_encoder.inverse_transform(preds)
|
|
367
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
368
|
+
|
|
369
|
+
return preds
|
|
370
|
+
|
|
371
|
+
except Exception as e:
|
|
372
|
+
raise CustomException(e, sys)
|
|
373
|
+
|
|
374
|
+
class CustomData:
|
|
375
|
+
|
|
376
|
+
"""
|
|
377
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
378
|
+
It will take care of all the Features .
|
|
379
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
380
|
+
providing flexibility in working with different datasets.
|
|
381
|
+
"""
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def __init__(self,features_cols, **kwargs):
|
|
385
|
+
try:
|
|
386
|
+
self.Features_Cols = features_cols
|
|
387
|
+
for feature in self.Features_Cols:
|
|
388
|
+
# print(feature)
|
|
389
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
390
|
+
|
|
391
|
+
except Exception as e:
|
|
392
|
+
raise CustomException(e, sys)
|
|
393
|
+
|
|
394
|
+
def get_data_as_data_frame(self):
|
|
395
|
+
|
|
396
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
397
|
+
|
|
398
|
+
try:
|
|
399
|
+
custom_data_input_dict = {}
|
|
400
|
+
for feature in self.Features_Cols:
|
|
401
|
+
feature_value = getattr(self,feature)
|
|
402
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
403
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
404
|
+
logging.info("Features Loaded Succesfully")
|
|
405
|
+
#print(custom_data_input_dict)
|
|
406
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
407
|
+
|
|
408
|
+
except Exception as e:
|
|
409
|
+
raise CustomException(e, sys)
|
|
410
|
+
class PredictPipeline:
|
|
411
|
+
|
|
412
|
+
""""
|
|
413
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
414
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
415
|
+
|
|
416
|
+
"""
|
|
417
|
+
|
|
418
|
+
def __init__(self, problem_objective):
|
|
419
|
+
self.Problem_Objective = problem_objective
|
|
420
|
+
|
|
421
|
+
def predict(self, features):
|
|
422
|
+
|
|
423
|
+
"""
|
|
424
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
425
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
426
|
+
|
|
427
|
+
"""
|
|
428
|
+
|
|
429
|
+
try:
|
|
430
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
431
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
432
|
+
|
|
433
|
+
if self.Problem_Objective=="Classification":
|
|
434
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
435
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
436
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
437
|
+
|
|
438
|
+
model = load_object(file_path=model_path)
|
|
439
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
440
|
+
print("Model Loaded Succesfully")
|
|
441
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
442
|
+
data_scaled = preprocessor.transform(features)
|
|
443
|
+
preds = model.predict(data_scaled)
|
|
444
|
+
if self.Problem_Objective=="Classification":
|
|
445
|
+
preds = preds.astype(int)
|
|
446
|
+
preds = label_encoder.inverse_transform(preds)
|
|
447
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
448
|
+
|
|
449
|
+
return preds
|
|
450
|
+
|
|
451
|
+
except Exception as e:
|
|
452
|
+
raise CustomException(e, sys)
|
|
453
|
+
|
|
454
|
+
class CustomData:
|
|
455
|
+
|
|
456
|
+
"""
|
|
457
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
458
|
+
It will take care of all the Features .
|
|
459
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
460
|
+
providing flexibility in working with different datasets.
|
|
461
|
+
"""
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def __init__(self,features_cols, **kwargs):
|
|
465
|
+
try:
|
|
466
|
+
self.Features_Cols = features_cols
|
|
467
|
+
for feature in self.Features_Cols:
|
|
468
|
+
# print(feature)
|
|
469
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
470
|
+
|
|
471
|
+
except Exception as e:
|
|
472
|
+
raise CustomException(e, sys)
|
|
473
|
+
|
|
474
|
+
def get_data_as_data_frame(self):
|
|
475
|
+
|
|
476
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
477
|
+
|
|
478
|
+
try:
|
|
479
|
+
custom_data_input_dict = {}
|
|
480
|
+
for feature in self.Features_Cols:
|
|
481
|
+
feature_value = getattr(self,feature)
|
|
482
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
483
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
484
|
+
logging.info("Features Loaded Succesfully")
|
|
485
|
+
#print(custom_data_input_dict)
|
|
486
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
487
|
+
|
|
488
|
+
except Exception as e:
|
|
489
|
+
raise CustomException(e, sys)
|
|
490
|
+
class PredictPipeline:
|
|
491
|
+
|
|
492
|
+
""""
|
|
493
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
494
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
495
|
+
|
|
496
|
+
"""
|
|
497
|
+
|
|
498
|
+
def __init__(self, problem_objective):
|
|
499
|
+
self.Problem_Objective = problem_objective
|
|
500
|
+
|
|
501
|
+
def predict(self, features):
|
|
502
|
+
|
|
503
|
+
"""
|
|
504
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
505
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
506
|
+
|
|
507
|
+
"""
|
|
508
|
+
|
|
509
|
+
try:
|
|
510
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
511
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
512
|
+
|
|
513
|
+
if self.Problem_Objective=="Classification":
|
|
514
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
515
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
516
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
517
|
+
|
|
518
|
+
model = load_object(file_path=model_path)
|
|
519
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
520
|
+
print("Model Loaded Succesfully")
|
|
521
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
522
|
+
data_scaled = preprocessor.transform(features)
|
|
523
|
+
preds = model.predict(data_scaled)
|
|
524
|
+
if self.Problem_Objective=="Classification":
|
|
525
|
+
preds = preds.astype(int)
|
|
526
|
+
preds = label_encoder.inverse_transform(preds)
|
|
527
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
528
|
+
|
|
529
|
+
return preds
|
|
530
|
+
|
|
531
|
+
except Exception as e:
|
|
532
|
+
raise CustomException(e, sys)
|
|
533
|
+
|
|
534
|
+
class CustomData:
|
|
535
|
+
|
|
536
|
+
"""
|
|
537
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
538
|
+
It will take care of all the Features .
|
|
539
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
540
|
+
providing flexibility in working with different datasets.
|
|
541
|
+
"""
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def __init__(self,features_cols, **kwargs):
|
|
545
|
+
try:
|
|
546
|
+
self.Features_Cols = features_cols
|
|
547
|
+
for feature in self.Features_Cols:
|
|
548
|
+
# print(feature)
|
|
549
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
550
|
+
|
|
551
|
+
except Exception as e:
|
|
552
|
+
raise CustomException(e, sys)
|
|
553
|
+
|
|
554
|
+
def get_data_as_data_frame(self):
|
|
555
|
+
|
|
556
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
557
|
+
|
|
558
|
+
try:
|
|
559
|
+
custom_data_input_dict = {}
|
|
560
|
+
for feature in self.Features_Cols:
|
|
561
|
+
feature_value = getattr(self,feature)
|
|
562
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
563
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
564
|
+
logging.info("Features Loaded Succesfully")
|
|
565
|
+
#print(custom_data_input_dict)
|
|
566
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
567
|
+
|
|
568
|
+
except Exception as e:
|
|
569
|
+
raise CustomException(e, sys)
|
|
570
|
+
class PredictPipeline:
|
|
571
|
+
|
|
572
|
+
""""
|
|
573
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
574
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
575
|
+
|
|
576
|
+
"""
|
|
577
|
+
|
|
578
|
+
def __init__(self, problem_objective):
|
|
579
|
+
self.Problem_Objective = problem_objective
|
|
580
|
+
|
|
581
|
+
def predict(self, features):
|
|
582
|
+
|
|
583
|
+
"""
|
|
584
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
585
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
586
|
+
|
|
587
|
+
"""
|
|
588
|
+
|
|
589
|
+
try:
|
|
590
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
591
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
592
|
+
|
|
593
|
+
if self.Problem_Objective=="Classification":
|
|
594
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
595
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
596
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
597
|
+
|
|
598
|
+
model = load_object(file_path=model_path)
|
|
599
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
600
|
+
print("Model Loaded Succesfully")
|
|
601
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
602
|
+
data_scaled = preprocessor.transform(features)
|
|
603
|
+
preds = model.predict(data_scaled)
|
|
604
|
+
if self.Problem_Objective=="Classification":
|
|
605
|
+
preds = preds.astype(int)
|
|
606
|
+
preds = label_encoder.inverse_transform(preds)
|
|
607
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
608
|
+
|
|
609
|
+
return preds
|
|
610
|
+
|
|
611
|
+
except Exception as e:
|
|
612
|
+
raise CustomException(e, sys)
|
|
613
|
+
|
|
614
|
+
class CustomData:
|
|
615
|
+
|
|
616
|
+
"""
|
|
617
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
618
|
+
It will take care of all the Features .
|
|
619
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
620
|
+
providing flexibility in working with different datasets.
|
|
621
|
+
"""
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
def __init__(self,features_cols, **kwargs):
|
|
625
|
+
try:
|
|
626
|
+
self.Features_Cols = features_cols
|
|
627
|
+
for feature in self.Features_Cols:
|
|
628
|
+
# print(feature)
|
|
629
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
630
|
+
|
|
631
|
+
except Exception as e:
|
|
632
|
+
raise CustomException(e, sys)
|
|
633
|
+
|
|
634
|
+
def get_data_as_data_frame(self):
|
|
635
|
+
|
|
636
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
637
|
+
|
|
638
|
+
try:
|
|
639
|
+
custom_data_input_dict = {}
|
|
640
|
+
for feature in self.Features_Cols:
|
|
641
|
+
feature_value = getattr(self,feature)
|
|
642
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
643
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
644
|
+
logging.info("Features Loaded Succesfully")
|
|
645
|
+
#print(custom_data_input_dict)
|
|
646
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
647
|
+
|
|
648
|
+
except Exception as e:
|
|
649
|
+
raise CustomException(e, sys)
|
|
650
|
+
class PredictPipeline:
|
|
651
|
+
|
|
652
|
+
""""
|
|
653
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
654
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
655
|
+
|
|
656
|
+
"""
|
|
657
|
+
|
|
658
|
+
def __init__(self, problem_objective):
|
|
659
|
+
self.Problem_Objective = problem_objective
|
|
660
|
+
|
|
661
|
+
def predict(self, features):
|
|
662
|
+
|
|
663
|
+
"""
|
|
664
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
665
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
666
|
+
|
|
667
|
+
"""
|
|
668
|
+
|
|
669
|
+
try:
|
|
670
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
671
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
672
|
+
|
|
673
|
+
if self.Problem_Objective=="Classification":
|
|
674
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
675
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
676
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
677
|
+
|
|
678
|
+
model = load_object(file_path=model_path)
|
|
679
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
680
|
+
print("Model Loaded Succesfully")
|
|
681
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
682
|
+
data_scaled = preprocessor.transform(features)
|
|
683
|
+
preds = model.predict(data_scaled)
|
|
684
|
+
if self.Problem_Objective=="Classification":
|
|
685
|
+
preds = preds.astype(int)
|
|
686
|
+
preds = label_encoder.inverse_transform(preds)
|
|
687
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
688
|
+
|
|
689
|
+
return preds
|
|
690
|
+
|
|
691
|
+
except Exception as e:
|
|
692
|
+
raise CustomException(e, sys)
|
|
693
|
+
|
|
694
|
+
class CustomData:
|
|
695
|
+
|
|
696
|
+
"""
|
|
697
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
698
|
+
It will take care of all the Features .
|
|
699
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
700
|
+
providing flexibility in working with different datasets.
|
|
701
|
+
"""
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def __init__(self,features_cols, **kwargs):
|
|
705
|
+
try:
|
|
706
|
+
self.Features_Cols = features_cols
|
|
707
|
+
for feature in self.Features_Cols:
|
|
708
|
+
# print(feature)
|
|
709
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
710
|
+
|
|
711
|
+
except Exception as e:
|
|
712
|
+
raise CustomException(e, sys)
|
|
713
|
+
|
|
714
|
+
def get_data_as_data_frame(self):
|
|
715
|
+
|
|
716
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
717
|
+
|
|
718
|
+
try:
|
|
719
|
+
custom_data_input_dict = {}
|
|
720
|
+
for feature in self.Features_Cols:
|
|
721
|
+
feature_value = getattr(self,feature)
|
|
722
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
723
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
724
|
+
logging.info("Features Loaded Succesfully")
|
|
725
|
+
#print(custom_data_input_dict)
|
|
726
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
727
|
+
|
|
728
|
+
except Exception as e:
|
|
729
|
+
raise CustomException(e, sys)
|
|
730
|
+
class PredictPipeline:
|
|
731
|
+
|
|
732
|
+
""""
|
|
733
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
734
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
735
|
+
|
|
736
|
+
"""
|
|
737
|
+
|
|
738
|
+
def __init__(self, problem_objective):
|
|
739
|
+
self.Problem_Objective = problem_objective
|
|
740
|
+
|
|
741
|
+
def predict(self, features):
|
|
742
|
+
|
|
743
|
+
"""
|
|
744
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
745
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
746
|
+
|
|
747
|
+
"""
|
|
748
|
+
|
|
749
|
+
try:
|
|
750
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
751
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
752
|
+
|
|
753
|
+
if self.Problem_Objective=="Classification":
|
|
754
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
755
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
756
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
757
|
+
|
|
758
|
+
model = load_object(file_path=model_path)
|
|
759
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
760
|
+
print("Model Loaded Succesfully")
|
|
761
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
762
|
+
data_scaled = preprocessor.transform(features)
|
|
763
|
+
preds = model.predict(data_scaled)
|
|
764
|
+
if self.Problem_Objective=="Classification":
|
|
765
|
+
preds = preds.astype(int)
|
|
766
|
+
preds = label_encoder.inverse_transform(preds)
|
|
767
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
768
|
+
|
|
769
|
+
return preds
|
|
770
|
+
|
|
771
|
+
except Exception as e:
|
|
772
|
+
raise CustomException(e, sys)
|
|
773
|
+
|
|
774
|
+
class CustomData:
|
|
775
|
+
|
|
776
|
+
"""
|
|
777
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
778
|
+
It will take care of all the Features .
|
|
779
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
780
|
+
providing flexibility in working with different datasets.
|
|
781
|
+
"""
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def __init__(self,features_cols, **kwargs):
|
|
785
|
+
try:
|
|
786
|
+
self.Features_Cols = features_cols
|
|
787
|
+
for feature in self.Features_Cols:
|
|
788
|
+
# print(feature)
|
|
789
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
790
|
+
|
|
791
|
+
except Exception as e:
|
|
792
|
+
raise CustomException(e, sys)
|
|
793
|
+
|
|
794
|
+
def get_data_as_data_frame(self):
|
|
795
|
+
|
|
796
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
797
|
+
|
|
798
|
+
try:
|
|
799
|
+
custom_data_input_dict = {}
|
|
800
|
+
for feature in self.Features_Cols:
|
|
801
|
+
feature_value = getattr(self,feature)
|
|
802
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
803
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
804
|
+
logging.info("Features Loaded Succesfully")
|
|
805
|
+
#print(custom_data_input_dict)
|
|
806
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
807
|
+
|
|
808
|
+
except Exception as e:
|
|
809
|
+
raise CustomException(e, sys)
|
|
810
|
+
class PredictPipeline:
|
|
811
|
+
|
|
812
|
+
""""
|
|
813
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
814
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
815
|
+
|
|
816
|
+
"""
|
|
817
|
+
|
|
818
|
+
def __init__(self, problem_objective):
|
|
819
|
+
self.Problem_Objective = problem_objective
|
|
820
|
+
|
|
821
|
+
def predict(self, features):
|
|
822
|
+
|
|
823
|
+
"""
|
|
824
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
825
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
826
|
+
|
|
827
|
+
"""
|
|
828
|
+
|
|
829
|
+
try:
|
|
830
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
831
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
832
|
+
|
|
833
|
+
if self.Problem_Objective=="Classification":
|
|
834
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
835
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
836
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
837
|
+
|
|
838
|
+
model = load_object(file_path=model_path)
|
|
839
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
840
|
+
print("Model Loaded Succesfully")
|
|
841
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
842
|
+
data_scaled = preprocessor.transform(features)
|
|
843
|
+
preds = model.predict(data_scaled)
|
|
844
|
+
if self.Problem_Objective=="Classification":
|
|
845
|
+
preds = preds.astype(int)
|
|
846
|
+
preds = label_encoder.inverse_transform(preds)
|
|
847
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
848
|
+
|
|
849
|
+
return preds
|
|
850
|
+
|
|
851
|
+
except Exception as e:
|
|
852
|
+
raise CustomException(e, sys)
|
|
853
|
+
|
|
854
|
+
class CustomData:
|
|
855
|
+
|
|
856
|
+
"""
|
|
857
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
858
|
+
It will take care of all the Features .
|
|
859
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
860
|
+
providing flexibility in working with different datasets.
|
|
861
|
+
"""
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
def __init__(self,features_cols, **kwargs):
|
|
865
|
+
try:
|
|
866
|
+
self.Features_Cols = features_cols
|
|
867
|
+
for feature in self.Features_Cols:
|
|
868
|
+
# print(feature)
|
|
869
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
870
|
+
|
|
871
|
+
except Exception as e:
|
|
872
|
+
raise CustomException(e, sys)
|
|
873
|
+
|
|
874
|
+
def get_data_as_data_frame(self):
|
|
875
|
+
|
|
876
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
877
|
+
|
|
878
|
+
try:
|
|
879
|
+
custom_data_input_dict = {}
|
|
880
|
+
for feature in self.Features_Cols:
|
|
881
|
+
feature_value = getattr(self,feature)
|
|
882
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
883
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
884
|
+
logging.info("Features Loaded Succesfully")
|
|
885
|
+
#print(custom_data_input_dict)
|
|
886
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
887
|
+
|
|
888
|
+
except Exception as e:
|
|
889
|
+
raise CustomException(e, sys)
|
|
890
|
+
class PredictPipeline:
|
|
891
|
+
|
|
892
|
+
""""
|
|
893
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
894
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
895
|
+
|
|
896
|
+
"""
|
|
897
|
+
|
|
898
|
+
def __init__(self, problem_objective):
|
|
899
|
+
self.Problem_Objective = problem_objective
|
|
900
|
+
|
|
901
|
+
def predict(self, features):
|
|
902
|
+
|
|
903
|
+
"""
|
|
904
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
905
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
906
|
+
|
|
907
|
+
"""
|
|
908
|
+
|
|
909
|
+
try:
|
|
910
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
911
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
912
|
+
|
|
913
|
+
if self.Problem_Objective=="Classification":
|
|
914
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
915
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
916
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
917
|
+
|
|
918
|
+
model = load_object(file_path=model_path)
|
|
919
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
920
|
+
print("Model Loaded Succesfully")
|
|
921
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
922
|
+
data_scaled = preprocessor.transform(features)
|
|
923
|
+
preds = model.predict(data_scaled)
|
|
924
|
+
if self.Problem_Objective=="Classification":
|
|
925
|
+
preds = preds.astype(int)
|
|
926
|
+
preds = label_encoder.inverse_transform(preds)
|
|
927
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
928
|
+
|
|
929
|
+
return preds
|
|
930
|
+
|
|
931
|
+
except Exception as e:
|
|
932
|
+
raise CustomException(e, sys)
|
|
933
|
+
|
|
934
|
+
class CustomData:
|
|
935
|
+
|
|
936
|
+
"""
|
|
937
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
938
|
+
It will take care of all the Features .
|
|
939
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
940
|
+
providing flexibility in working with different datasets.
|
|
941
|
+
"""
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
def __init__(self,features_cols, **kwargs):
|
|
945
|
+
try:
|
|
946
|
+
self.Features_Cols = features_cols
|
|
947
|
+
for feature in self.Features_Cols:
|
|
948
|
+
# print(feature)
|
|
949
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
950
|
+
|
|
951
|
+
except Exception as e:
|
|
952
|
+
raise CustomException(e, sys)
|
|
953
|
+
|
|
954
|
+
def get_data_as_data_frame(self):
|
|
955
|
+
|
|
956
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
957
|
+
|
|
958
|
+
try:
|
|
959
|
+
custom_data_input_dict = {}
|
|
960
|
+
for feature in self.Features_Cols:
|
|
961
|
+
feature_value = getattr(self,feature)
|
|
962
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
963
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
964
|
+
logging.info("Features Loaded Succesfully")
|
|
965
|
+
#print(custom_data_input_dict)
|
|
966
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
967
|
+
|
|
968
|
+
except Exception as e:
|
|
969
|
+
raise CustomException(e, sys)
|
|
970
|
+
class PredictPipeline:
|
|
971
|
+
|
|
972
|
+
""""
|
|
973
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
974
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
975
|
+
|
|
976
|
+
"""
|
|
977
|
+
|
|
978
|
+
def __init__(self, problem_objective):
|
|
979
|
+
self.Problem_Objective = problem_objective
|
|
980
|
+
|
|
981
|
+
def predict(self, features):
|
|
982
|
+
|
|
983
|
+
"""
|
|
984
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
985
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
986
|
+
|
|
987
|
+
"""
|
|
988
|
+
|
|
989
|
+
try:
|
|
990
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
991
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
992
|
+
|
|
993
|
+
if self.Problem_Objective=="Classification":
|
|
994
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
995
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
996
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
997
|
+
|
|
998
|
+
model = load_object(file_path=model_path)
|
|
999
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1000
|
+
print("Model Loaded Succesfully")
|
|
1001
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1002
|
+
data_scaled = preprocessor.transform(features)
|
|
1003
|
+
preds = model.predict(data_scaled)
|
|
1004
|
+
if self.Problem_Objective=="Classification":
|
|
1005
|
+
preds = preds.astype(int)
|
|
1006
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1007
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1008
|
+
|
|
1009
|
+
return preds
|
|
1010
|
+
|
|
1011
|
+
except Exception as e:
|
|
1012
|
+
raise CustomException(e, sys)
|
|
1013
|
+
|
|
1014
|
+
class CustomData:
|
|
1015
|
+
|
|
1016
|
+
"""
|
|
1017
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1018
|
+
It will take care of all the Features .
|
|
1019
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1020
|
+
providing flexibility in working with different datasets.
|
|
1021
|
+
"""
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
def __init__(self,features_cols, **kwargs):
|
|
1025
|
+
try:
|
|
1026
|
+
self.Features_Cols = features_cols
|
|
1027
|
+
for feature in self.Features_Cols:
|
|
1028
|
+
# print(feature)
|
|
1029
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1030
|
+
|
|
1031
|
+
except Exception as e:
|
|
1032
|
+
raise CustomException(e, sys)
|
|
1033
|
+
|
|
1034
|
+
def get_data_as_data_frame(self):
|
|
1035
|
+
|
|
1036
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1037
|
+
|
|
1038
|
+
try:
|
|
1039
|
+
custom_data_input_dict = {}
|
|
1040
|
+
for feature in self.Features_Cols:
|
|
1041
|
+
feature_value = getattr(self,feature)
|
|
1042
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1043
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1044
|
+
logging.info("Features Loaded Succesfully")
|
|
1045
|
+
#print(custom_data_input_dict)
|
|
1046
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1047
|
+
|
|
1048
|
+
except Exception as e:
|
|
1049
|
+
raise CustomException(e, sys)
|
|
1050
|
+
class PredictPipeline:
|
|
1051
|
+
|
|
1052
|
+
""""
|
|
1053
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1054
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1055
|
+
|
|
1056
|
+
"""
|
|
1057
|
+
|
|
1058
|
+
def __init__(self, problem_objective):
|
|
1059
|
+
self.Problem_Objective = problem_objective
|
|
1060
|
+
|
|
1061
|
+
def predict(self, features):
|
|
1062
|
+
|
|
1063
|
+
"""
|
|
1064
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1065
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1066
|
+
|
|
1067
|
+
"""
|
|
1068
|
+
|
|
1069
|
+
try:
|
|
1070
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1071
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1072
|
+
|
|
1073
|
+
if self.Problem_Objective=="Classification":
|
|
1074
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1075
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1076
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1077
|
+
|
|
1078
|
+
model = load_object(file_path=model_path)
|
|
1079
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1080
|
+
print("Model Loaded Succesfully")
|
|
1081
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1082
|
+
data_scaled = preprocessor.transform(features)
|
|
1083
|
+
preds = model.predict(data_scaled)
|
|
1084
|
+
if self.Problem_Objective=="Classification":
|
|
1085
|
+
preds = preds.astype(int)
|
|
1086
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1087
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1088
|
+
|
|
1089
|
+
return preds
|
|
1090
|
+
|
|
1091
|
+
except Exception as e:
|
|
1092
|
+
raise CustomException(e, sys)
|
|
1093
|
+
|
|
1094
|
+
class CustomData:
|
|
1095
|
+
|
|
1096
|
+
"""
|
|
1097
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1098
|
+
It will take care of all the Features .
|
|
1099
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1100
|
+
providing flexibility in working with different datasets.
|
|
1101
|
+
"""
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
def __init__(self,features_cols, **kwargs):
|
|
1105
|
+
try:
|
|
1106
|
+
self.Features_Cols = features_cols
|
|
1107
|
+
for feature in self.Features_Cols:
|
|
1108
|
+
# print(feature)
|
|
1109
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1110
|
+
|
|
1111
|
+
except Exception as e:
|
|
1112
|
+
raise CustomException(e, sys)
|
|
1113
|
+
|
|
1114
|
+
def get_data_as_data_frame(self):
|
|
1115
|
+
|
|
1116
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1117
|
+
|
|
1118
|
+
try:
|
|
1119
|
+
custom_data_input_dict = {}
|
|
1120
|
+
for feature in self.Features_Cols:
|
|
1121
|
+
feature_value = getattr(self,feature)
|
|
1122
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1123
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1124
|
+
logging.info("Features Loaded Succesfully")
|
|
1125
|
+
#print(custom_data_input_dict)
|
|
1126
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1127
|
+
|
|
1128
|
+
except Exception as e:
|
|
1129
|
+
raise CustomException(e, sys)
|
|
1130
|
+
class PredictPipeline:
|
|
1131
|
+
|
|
1132
|
+
""""
|
|
1133
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1134
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1135
|
+
|
|
1136
|
+
"""
|
|
1137
|
+
|
|
1138
|
+
def __init__(self, problem_objective):
|
|
1139
|
+
self.Problem_Objective = problem_objective
|
|
1140
|
+
|
|
1141
|
+
def predict(self, features):
|
|
1142
|
+
|
|
1143
|
+
"""
|
|
1144
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1145
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1146
|
+
|
|
1147
|
+
"""
|
|
1148
|
+
|
|
1149
|
+
try:
|
|
1150
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1151
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1152
|
+
|
|
1153
|
+
if self.Problem_Objective=="Classification":
|
|
1154
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1155
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1156
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1157
|
+
|
|
1158
|
+
model = load_object(file_path=model_path)
|
|
1159
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1160
|
+
print("Model Loaded Succesfully")
|
|
1161
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1162
|
+
data_scaled = preprocessor.transform(features)
|
|
1163
|
+
preds = model.predict(data_scaled)
|
|
1164
|
+
if self.Problem_Objective=="Classification":
|
|
1165
|
+
preds = preds.astype(int)
|
|
1166
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1167
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1168
|
+
|
|
1169
|
+
return preds
|
|
1170
|
+
|
|
1171
|
+
except Exception as e:
|
|
1172
|
+
raise CustomException(e, sys)
|
|
1173
|
+
|
|
1174
|
+
class CustomData:
|
|
1175
|
+
|
|
1176
|
+
"""
|
|
1177
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1178
|
+
It will take care of all the Features .
|
|
1179
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1180
|
+
providing flexibility in working with different datasets.
|
|
1181
|
+
"""
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
def __init__(self,features_cols, **kwargs):
|
|
1185
|
+
try:
|
|
1186
|
+
self.Features_Cols = features_cols
|
|
1187
|
+
for feature in self.Features_Cols:
|
|
1188
|
+
# print(feature)
|
|
1189
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1190
|
+
|
|
1191
|
+
except Exception as e:
|
|
1192
|
+
raise CustomException(e, sys)
|
|
1193
|
+
|
|
1194
|
+
def get_data_as_data_frame(self):
|
|
1195
|
+
|
|
1196
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1197
|
+
|
|
1198
|
+
try:
|
|
1199
|
+
custom_data_input_dict = {}
|
|
1200
|
+
for feature in self.Features_Cols:
|
|
1201
|
+
feature_value = getattr(self,feature)
|
|
1202
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1203
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1204
|
+
logging.info("Features Loaded Succesfully")
|
|
1205
|
+
#print(custom_data_input_dict)
|
|
1206
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1207
|
+
|
|
1208
|
+
except Exception as e:
|
|
1209
|
+
raise CustomException(e, sys)
|
|
1210
|
+
class PredictPipeline:
|
|
1211
|
+
|
|
1212
|
+
""""
|
|
1213
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1214
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1215
|
+
|
|
1216
|
+
"""
|
|
1217
|
+
|
|
1218
|
+
def __init__(self, problem_objective):
|
|
1219
|
+
self.Problem_Objective = problem_objective
|
|
1220
|
+
|
|
1221
|
+
def predict(self, features):
|
|
1222
|
+
|
|
1223
|
+
"""
|
|
1224
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1225
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1226
|
+
|
|
1227
|
+
"""
|
|
1228
|
+
|
|
1229
|
+
try:
|
|
1230
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1231
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1232
|
+
|
|
1233
|
+
if self.Problem_Objective=="Classification":
|
|
1234
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1235
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1236
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1237
|
+
|
|
1238
|
+
model = load_object(file_path=model_path)
|
|
1239
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1240
|
+
print("Model Loaded Succesfully")
|
|
1241
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1242
|
+
data_scaled = preprocessor.transform(features)
|
|
1243
|
+
preds = model.predict(data_scaled)
|
|
1244
|
+
if self.Problem_Objective=="Classification":
|
|
1245
|
+
preds = preds.astype(int)
|
|
1246
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1247
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1248
|
+
|
|
1249
|
+
return preds
|
|
1250
|
+
|
|
1251
|
+
except Exception as e:
|
|
1252
|
+
raise CustomException(e, sys)
|
|
1253
|
+
|
|
1254
|
+
class CustomData:
|
|
1255
|
+
|
|
1256
|
+
"""
|
|
1257
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1258
|
+
It will take care of all the Features .
|
|
1259
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1260
|
+
providing flexibility in working with different datasets.
|
|
1261
|
+
"""
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
def __init__(self,features_cols, **kwargs):
|
|
1265
|
+
try:
|
|
1266
|
+
self.Features_Cols = features_cols
|
|
1267
|
+
for feature in self.Features_Cols:
|
|
1268
|
+
# print(feature)
|
|
1269
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1270
|
+
|
|
1271
|
+
except Exception as e:
|
|
1272
|
+
raise CustomException(e, sys)
|
|
1273
|
+
|
|
1274
|
+
def get_data_as_data_frame(self):
|
|
1275
|
+
|
|
1276
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1277
|
+
|
|
1278
|
+
try:
|
|
1279
|
+
custom_data_input_dict = {}
|
|
1280
|
+
for feature in self.Features_Cols:
|
|
1281
|
+
feature_value = getattr(self,feature)
|
|
1282
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1283
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1284
|
+
logging.info("Features Loaded Succesfully")
|
|
1285
|
+
#print(custom_data_input_dict)
|
|
1286
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1287
|
+
|
|
1288
|
+
except Exception as e:
|
|
1289
|
+
raise CustomException(e, sys)
|
|
1290
|
+
class PredictPipeline:
|
|
1291
|
+
|
|
1292
|
+
""""
|
|
1293
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1294
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1295
|
+
|
|
1296
|
+
"""
|
|
1297
|
+
|
|
1298
|
+
def __init__(self, problem_objective):
|
|
1299
|
+
self.Problem_Objective = problem_objective
|
|
1300
|
+
|
|
1301
|
+
def predict(self, features):
|
|
1302
|
+
|
|
1303
|
+
"""
|
|
1304
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1305
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1306
|
+
|
|
1307
|
+
"""
|
|
1308
|
+
|
|
1309
|
+
try:
|
|
1310
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1311
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1312
|
+
|
|
1313
|
+
if self.Problem_Objective=="Classification":
|
|
1314
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1315
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1316
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1317
|
+
|
|
1318
|
+
model = load_object(file_path=model_path)
|
|
1319
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1320
|
+
print("Model Loaded Succesfully")
|
|
1321
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1322
|
+
data_scaled = preprocessor.transform(features)
|
|
1323
|
+
preds = model.predict(data_scaled)
|
|
1324
|
+
if self.Problem_Objective=="Classification":
|
|
1325
|
+
preds = preds.astype(int)
|
|
1326
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1327
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1328
|
+
|
|
1329
|
+
return preds
|
|
1330
|
+
|
|
1331
|
+
except Exception as e:
|
|
1332
|
+
raise CustomException(e, sys)
|
|
1333
|
+
|
|
1334
|
+
class CustomData:
|
|
1335
|
+
|
|
1336
|
+
"""
|
|
1337
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1338
|
+
It will take care of all the Features .
|
|
1339
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1340
|
+
providing flexibility in working with different datasets.
|
|
1341
|
+
"""
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
def __init__(self,features_cols, **kwargs):
|
|
1345
|
+
try:
|
|
1346
|
+
self.Features_Cols = features_cols
|
|
1347
|
+
for feature in self.Features_Cols:
|
|
1348
|
+
# print(feature)
|
|
1349
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1350
|
+
|
|
1351
|
+
except Exception as e:
|
|
1352
|
+
raise CustomException(e, sys)
|
|
1353
|
+
|
|
1354
|
+
def get_data_as_data_frame(self):
|
|
1355
|
+
|
|
1356
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1357
|
+
|
|
1358
|
+
try:
|
|
1359
|
+
custom_data_input_dict = {}
|
|
1360
|
+
for feature in self.Features_Cols:
|
|
1361
|
+
feature_value = getattr(self,feature)
|
|
1362
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1363
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1364
|
+
logging.info("Features Loaded Succesfully")
|
|
1365
|
+
#print(custom_data_input_dict)
|
|
1366
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1367
|
+
|
|
1368
|
+
except Exception as e:
|
|
1369
|
+
raise CustomException(e, sys)
|
|
1370
|
+
class PredictPipeline:
|
|
1371
|
+
|
|
1372
|
+
""""
|
|
1373
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1374
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1375
|
+
|
|
1376
|
+
"""
|
|
1377
|
+
|
|
1378
|
+
def __init__(self, problem_objective):
|
|
1379
|
+
self.Problem_Objective = problem_objective
|
|
1380
|
+
|
|
1381
|
+
def predict(self, features):
|
|
1382
|
+
|
|
1383
|
+
"""
|
|
1384
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1385
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1386
|
+
|
|
1387
|
+
"""
|
|
1388
|
+
|
|
1389
|
+
try:
|
|
1390
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1391
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1392
|
+
|
|
1393
|
+
if self.Problem_Objective=="Classification":
|
|
1394
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1395
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1396
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1397
|
+
|
|
1398
|
+
model = load_object(file_path=model_path)
|
|
1399
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1400
|
+
print("Model Loaded Succesfully")
|
|
1401
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1402
|
+
data_scaled = preprocessor.transform(features)
|
|
1403
|
+
preds = model.predict(data_scaled)
|
|
1404
|
+
if self.Problem_Objective=="Classification":
|
|
1405
|
+
preds = preds.astype(int)
|
|
1406
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1407
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1408
|
+
|
|
1409
|
+
return preds
|
|
1410
|
+
|
|
1411
|
+
except Exception as e:
|
|
1412
|
+
raise CustomException(e, sys)
|
|
1413
|
+
|
|
1414
|
+
class CustomData:
|
|
1415
|
+
|
|
1416
|
+
"""
|
|
1417
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1418
|
+
It will take care of all the Features .
|
|
1419
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1420
|
+
providing flexibility in working with different datasets.
|
|
1421
|
+
"""
|
|
1422
|
+
|
|
1423
|
+
|
|
1424
|
+
def __init__(self,features_cols, **kwargs):
|
|
1425
|
+
try:
|
|
1426
|
+
self.Features_Cols = features_cols
|
|
1427
|
+
for feature in self.Features_Cols:
|
|
1428
|
+
# print(feature)
|
|
1429
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1430
|
+
|
|
1431
|
+
except Exception as e:
|
|
1432
|
+
raise CustomException(e, sys)
|
|
1433
|
+
|
|
1434
|
+
def get_data_as_data_frame(self):
|
|
1435
|
+
|
|
1436
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1437
|
+
|
|
1438
|
+
try:
|
|
1439
|
+
custom_data_input_dict = {}
|
|
1440
|
+
for feature in self.Features_Cols:
|
|
1441
|
+
feature_value = getattr(self,feature)
|
|
1442
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1443
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1444
|
+
logging.info("Features Loaded Succesfully")
|
|
1445
|
+
#print(custom_data_input_dict)
|
|
1446
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1447
|
+
|
|
1448
|
+
except Exception as e:
|
|
1449
|
+
raise CustomException(e, sys)
|
|
1450
|
+
class PredictPipeline:
|
|
1451
|
+
|
|
1452
|
+
""""
|
|
1453
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1454
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1455
|
+
|
|
1456
|
+
"""
|
|
1457
|
+
|
|
1458
|
+
def __init__(self, problem_objective):
|
|
1459
|
+
self.Problem_Objective = problem_objective
|
|
1460
|
+
|
|
1461
|
+
def predict(self, features):
|
|
1462
|
+
|
|
1463
|
+
"""
|
|
1464
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1465
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1466
|
+
|
|
1467
|
+
"""
|
|
1468
|
+
|
|
1469
|
+
try:
|
|
1470
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1471
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1472
|
+
|
|
1473
|
+
if self.Problem_Objective=="Classification":
|
|
1474
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1475
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1476
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1477
|
+
|
|
1478
|
+
model = load_object(file_path=model_path)
|
|
1479
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1480
|
+
print("Model Loaded Succesfully")
|
|
1481
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1482
|
+
data_scaled = preprocessor.transform(features)
|
|
1483
|
+
preds = model.predict(data_scaled)
|
|
1484
|
+
if self.Problem_Objective=="Classification":
|
|
1485
|
+
preds = preds.astype(int)
|
|
1486
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1487
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1488
|
+
|
|
1489
|
+
return preds
|
|
1490
|
+
|
|
1491
|
+
except Exception as e:
|
|
1492
|
+
raise CustomException(e, sys)
|
|
1493
|
+
|
|
1494
|
+
class CustomData:
|
|
1495
|
+
|
|
1496
|
+
"""
|
|
1497
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1498
|
+
It will take care of all the Features .
|
|
1499
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1500
|
+
providing flexibility in working with different datasets.
|
|
1501
|
+
"""
|
|
1502
|
+
|
|
1503
|
+
|
|
1504
|
+
def __init__(self,features_cols, **kwargs):
|
|
1505
|
+
try:
|
|
1506
|
+
self.Features_Cols = features_cols
|
|
1507
|
+
for feature in self.Features_Cols:
|
|
1508
|
+
# print(feature)
|
|
1509
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1510
|
+
|
|
1511
|
+
except Exception as e:
|
|
1512
|
+
raise CustomException(e, sys)
|
|
1513
|
+
|
|
1514
|
+
def get_data_as_data_frame(self):
|
|
1515
|
+
|
|
1516
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1517
|
+
|
|
1518
|
+
try:
|
|
1519
|
+
custom_data_input_dict = {}
|
|
1520
|
+
for feature in self.Features_Cols:
|
|
1521
|
+
feature_value = getattr(self,feature)
|
|
1522
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1523
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1524
|
+
logging.info("Features Loaded Succesfully")
|
|
1525
|
+
#print(custom_data_input_dict)
|
|
1526
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1527
|
+
|
|
1528
|
+
except Exception as e:
|
|
1529
|
+
raise CustomException(e, sys)
|
|
1530
|
+
class PredictPipeline:
|
|
1531
|
+
|
|
1532
|
+
""""
|
|
1533
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1534
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1535
|
+
|
|
1536
|
+
"""
|
|
1537
|
+
|
|
1538
|
+
def __init__(self, problem_objective):
|
|
1539
|
+
self.Problem_Objective = problem_objective
|
|
1540
|
+
|
|
1541
|
+
def predict(self, features):
|
|
1542
|
+
|
|
1543
|
+
"""
|
|
1544
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1545
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1546
|
+
|
|
1547
|
+
"""
|
|
1548
|
+
|
|
1549
|
+
try:
|
|
1550
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1551
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1552
|
+
|
|
1553
|
+
if self.Problem_Objective=="Classification":
|
|
1554
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1555
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1556
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1557
|
+
|
|
1558
|
+
model = load_object(file_path=model_path)
|
|
1559
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1560
|
+
print("Model Loaded Succesfully")
|
|
1561
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1562
|
+
data_scaled = preprocessor.transform(features)
|
|
1563
|
+
preds = model.predict(data_scaled)
|
|
1564
|
+
if self.Problem_Objective=="Classification":
|
|
1565
|
+
preds = preds.astype(int)
|
|
1566
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1567
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1568
|
+
|
|
1569
|
+
return preds
|
|
1570
|
+
|
|
1571
|
+
except Exception as e:
|
|
1572
|
+
raise CustomException(e, sys)
|
|
1573
|
+
|
|
1574
|
+
class CustomData:
|
|
1575
|
+
|
|
1576
|
+
"""
|
|
1577
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1578
|
+
It will take care of all the Features .
|
|
1579
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1580
|
+
providing flexibility in working with different datasets.
|
|
1581
|
+
"""
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
def __init__(self,features_cols, **kwargs):
|
|
1585
|
+
try:
|
|
1586
|
+
self.Features_Cols = features_cols
|
|
1587
|
+
for feature in self.Features_Cols:
|
|
1588
|
+
# print(feature)
|
|
1589
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1590
|
+
|
|
1591
|
+
except Exception as e:
|
|
1592
|
+
raise CustomException(e, sys)
|
|
1593
|
+
|
|
1594
|
+
def get_data_as_data_frame(self):
|
|
1595
|
+
|
|
1596
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1597
|
+
|
|
1598
|
+
try:
|
|
1599
|
+
custom_data_input_dict = {}
|
|
1600
|
+
for feature in self.Features_Cols:
|
|
1601
|
+
feature_value = getattr(self,feature)
|
|
1602
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1603
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1604
|
+
logging.info("Features Loaded Succesfully")
|
|
1605
|
+
#print(custom_data_input_dict)
|
|
1606
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1607
|
+
|
|
1608
|
+
except Exception as e:
|
|
1609
|
+
raise CustomException(e, sys)
|
|
1610
|
+
class PredictPipeline:
|
|
1611
|
+
|
|
1612
|
+
""""
|
|
1613
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1614
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1615
|
+
|
|
1616
|
+
"""
|
|
1617
|
+
|
|
1618
|
+
def __init__(self, problem_objective):
|
|
1619
|
+
self.Problem_Objective = problem_objective
|
|
1620
|
+
|
|
1621
|
+
def predict(self, features):
|
|
1622
|
+
|
|
1623
|
+
"""
|
|
1624
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1625
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1626
|
+
|
|
1627
|
+
"""
|
|
1628
|
+
|
|
1629
|
+
try:
|
|
1630
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1631
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1632
|
+
|
|
1633
|
+
if self.Problem_Objective=="Classification":
|
|
1634
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1635
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1636
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1637
|
+
|
|
1638
|
+
model = load_object(file_path=model_path)
|
|
1639
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1640
|
+
print("Model Loaded Succesfully")
|
|
1641
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1642
|
+
data_scaled = preprocessor.transform(features)
|
|
1643
|
+
preds = model.predict(data_scaled)
|
|
1644
|
+
if self.Problem_Objective=="Classification":
|
|
1645
|
+
preds = preds.astype(int)
|
|
1646
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1647
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1648
|
+
|
|
1649
|
+
return preds
|
|
1650
|
+
|
|
1651
|
+
except Exception as e:
|
|
1652
|
+
raise CustomException(e, sys)
|
|
1653
|
+
|
|
1654
|
+
class CustomData:
|
|
1655
|
+
|
|
1656
|
+
"""
|
|
1657
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1658
|
+
It will take care of all the Features .
|
|
1659
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1660
|
+
providing flexibility in working with different datasets.
|
|
1661
|
+
"""
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
def __init__(self,features_cols, **kwargs):
|
|
1665
|
+
try:
|
|
1666
|
+
self.Features_Cols = features_cols
|
|
1667
|
+
for feature in self.Features_Cols:
|
|
1668
|
+
# print(feature)
|
|
1669
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1670
|
+
|
|
1671
|
+
except Exception as e:
|
|
1672
|
+
raise CustomException(e, sys)
|
|
1673
|
+
|
|
1674
|
+
def get_data_as_data_frame(self):
|
|
1675
|
+
|
|
1676
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1677
|
+
|
|
1678
|
+
try:
|
|
1679
|
+
custom_data_input_dict = {}
|
|
1680
|
+
for feature in self.Features_Cols:
|
|
1681
|
+
feature_value = getattr(self,feature)
|
|
1682
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1683
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1684
|
+
logging.info("Features Loaded Succesfully")
|
|
1685
|
+
#print(custom_data_input_dict)
|
|
1686
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1687
|
+
|
|
1688
|
+
except Exception as e:
|
|
1689
|
+
raise CustomException(e, sys)
|
|
1690
|
+
class PredictPipeline:
|
|
1691
|
+
|
|
1692
|
+
""""
|
|
1693
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1694
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1695
|
+
|
|
1696
|
+
"""
|
|
1697
|
+
|
|
1698
|
+
def __init__(self, problem_objective):
|
|
1699
|
+
self.Problem_Objective = problem_objective
|
|
1700
|
+
|
|
1701
|
+
def predict(self, features):
|
|
1702
|
+
|
|
1703
|
+
"""
|
|
1704
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1705
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1706
|
+
|
|
1707
|
+
"""
|
|
1708
|
+
|
|
1709
|
+
try:
|
|
1710
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1711
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1712
|
+
|
|
1713
|
+
if self.Problem_Objective=="Classification":
|
|
1714
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1715
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1716
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1717
|
+
|
|
1718
|
+
model = load_object(file_path=model_path)
|
|
1719
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1720
|
+
print("Model Loaded Succesfully")
|
|
1721
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1722
|
+
data_scaled = preprocessor.transform(features)
|
|
1723
|
+
preds = model.predict(data_scaled)
|
|
1724
|
+
if self.Problem_Objective=="Classification":
|
|
1725
|
+
preds = preds.astype(int)
|
|
1726
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1727
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1728
|
+
|
|
1729
|
+
return preds
|
|
1730
|
+
|
|
1731
|
+
except Exception as e:
|
|
1732
|
+
raise CustomException(e, sys)
|
|
1733
|
+
|
|
1734
|
+
class CustomData:
|
|
1735
|
+
|
|
1736
|
+
"""
|
|
1737
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1738
|
+
It will take care of all the Features .
|
|
1739
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1740
|
+
providing flexibility in working with different datasets.
|
|
1741
|
+
"""
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
def __init__(self,features_cols, **kwargs):
|
|
1745
|
+
try:
|
|
1746
|
+
self.Features_Cols = features_cols
|
|
1747
|
+
for feature in self.Features_Cols:
|
|
1748
|
+
# print(feature)
|
|
1749
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1750
|
+
|
|
1751
|
+
except Exception as e:
|
|
1752
|
+
raise CustomException(e, sys)
|
|
1753
|
+
|
|
1754
|
+
def get_data_as_data_frame(self):
|
|
1755
|
+
|
|
1756
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1757
|
+
|
|
1758
|
+
try:
|
|
1759
|
+
custom_data_input_dict = {}
|
|
1760
|
+
for feature in self.Features_Cols:
|
|
1761
|
+
feature_value = getattr(self,feature)
|
|
1762
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1763
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1764
|
+
logging.info("Features Loaded Succesfully")
|
|
1765
|
+
#print(custom_data_input_dict)
|
|
1766
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1767
|
+
|
|
1768
|
+
except Exception as e:
|
|
1769
|
+
raise CustomException(e, sys)
|
|
1770
|
+
class PredictPipeline:
|
|
1771
|
+
|
|
1772
|
+
""""
|
|
1773
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1774
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1775
|
+
|
|
1776
|
+
"""
|
|
1777
|
+
|
|
1778
|
+
def __init__(self, problem_objective):
|
|
1779
|
+
self.Problem_Objective = problem_objective
|
|
1780
|
+
|
|
1781
|
+
def predict(self, features):
|
|
1782
|
+
|
|
1783
|
+
"""
|
|
1784
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1785
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1786
|
+
|
|
1787
|
+
"""
|
|
1788
|
+
|
|
1789
|
+
try:
|
|
1790
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1791
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1792
|
+
|
|
1793
|
+
if self.Problem_Objective=="Classification":
|
|
1794
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1795
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1796
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1797
|
+
|
|
1798
|
+
model = load_object(file_path=model_path)
|
|
1799
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1800
|
+
print("Model Loaded Succesfully")
|
|
1801
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1802
|
+
data_scaled = preprocessor.transform(features)
|
|
1803
|
+
preds = model.predict(data_scaled)
|
|
1804
|
+
if self.Problem_Objective=="Classification":
|
|
1805
|
+
preds = preds.astype(int)
|
|
1806
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1807
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1808
|
+
|
|
1809
|
+
return preds
|
|
1810
|
+
|
|
1811
|
+
except Exception as e:
|
|
1812
|
+
raise CustomException(e, sys)
|
|
1813
|
+
|
|
1814
|
+
class CustomData:
|
|
1815
|
+
|
|
1816
|
+
"""
|
|
1817
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1818
|
+
It will take care of all the Features .
|
|
1819
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1820
|
+
providing flexibility in working with different datasets.
|
|
1821
|
+
"""
|
|
1822
|
+
|
|
1823
|
+
|
|
1824
|
+
def __init__(self,features_cols, **kwargs):
|
|
1825
|
+
try:
|
|
1826
|
+
self.Features_Cols = features_cols
|
|
1827
|
+
for feature in self.Features_Cols:
|
|
1828
|
+
# print(feature)
|
|
1829
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1830
|
+
|
|
1831
|
+
except Exception as e:
|
|
1832
|
+
raise CustomException(e, sys)
|
|
1833
|
+
|
|
1834
|
+
def get_data_as_data_frame(self):
|
|
1835
|
+
|
|
1836
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1837
|
+
|
|
1838
|
+
try:
|
|
1839
|
+
custom_data_input_dict = {}
|
|
1840
|
+
for feature in self.Features_Cols:
|
|
1841
|
+
feature_value = getattr(self,feature)
|
|
1842
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1843
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1844
|
+
logging.info("Features Loaded Succesfully")
|
|
1845
|
+
#print(custom_data_input_dict)
|
|
1846
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1847
|
+
|
|
1848
|
+
except Exception as e:
|
|
1849
|
+
raise CustomException(e, sys)
|
|
1850
|
+
class PredictPipeline:
|
|
1851
|
+
|
|
1852
|
+
""""
|
|
1853
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1854
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1855
|
+
|
|
1856
|
+
"""
|
|
1857
|
+
|
|
1858
|
+
def __init__(self, problem_objective):
|
|
1859
|
+
self.Problem_Objective = problem_objective
|
|
1860
|
+
|
|
1861
|
+
def predict(self, features):
|
|
1862
|
+
|
|
1863
|
+
"""
|
|
1864
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1865
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1866
|
+
|
|
1867
|
+
"""
|
|
1868
|
+
|
|
1869
|
+
try:
|
|
1870
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1871
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1872
|
+
|
|
1873
|
+
if self.Problem_Objective=="Classification":
|
|
1874
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1875
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1876
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1877
|
+
|
|
1878
|
+
model = load_object(file_path=model_path)
|
|
1879
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1880
|
+
print("Model Loaded Succesfully")
|
|
1881
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1882
|
+
data_scaled = preprocessor.transform(features)
|
|
1883
|
+
preds = model.predict(data_scaled)
|
|
1884
|
+
if self.Problem_Objective=="Classification":
|
|
1885
|
+
preds = preds.astype(int)
|
|
1886
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1887
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1888
|
+
|
|
1889
|
+
return preds
|
|
1890
|
+
|
|
1891
|
+
except Exception as e:
|
|
1892
|
+
raise CustomException(e, sys)
|
|
1893
|
+
|
|
1894
|
+
class CustomData:
|
|
1895
|
+
|
|
1896
|
+
"""
|
|
1897
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1898
|
+
It will take care of all the Features .
|
|
1899
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1900
|
+
providing flexibility in working with different datasets.
|
|
1901
|
+
"""
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
def __init__(self,features_cols, **kwargs):
|
|
1905
|
+
try:
|
|
1906
|
+
self.Features_Cols = features_cols
|
|
1907
|
+
for feature in self.Features_Cols:
|
|
1908
|
+
# print(feature)
|
|
1909
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1910
|
+
|
|
1911
|
+
except Exception as e:
|
|
1912
|
+
raise CustomException(e, sys)
|
|
1913
|
+
|
|
1914
|
+
def get_data_as_data_frame(self):
|
|
1915
|
+
|
|
1916
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1917
|
+
|
|
1918
|
+
try:
|
|
1919
|
+
custom_data_input_dict = {}
|
|
1920
|
+
for feature in self.Features_Cols:
|
|
1921
|
+
feature_value = getattr(self,feature)
|
|
1922
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
1923
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
1924
|
+
logging.info("Features Loaded Succesfully")
|
|
1925
|
+
#print(custom_data_input_dict)
|
|
1926
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
1927
|
+
|
|
1928
|
+
except Exception as e:
|
|
1929
|
+
raise CustomException(e, sys)
|
|
1930
|
+
class PredictPipeline:
|
|
1931
|
+
|
|
1932
|
+
""""
|
|
1933
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
1934
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
1935
|
+
|
|
1936
|
+
"""
|
|
1937
|
+
|
|
1938
|
+
def __init__(self, problem_objective):
|
|
1939
|
+
self.Problem_Objective = problem_objective
|
|
1940
|
+
|
|
1941
|
+
def predict(self, features):
|
|
1942
|
+
|
|
1943
|
+
"""
|
|
1944
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
1945
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
1946
|
+
|
|
1947
|
+
"""
|
|
1948
|
+
|
|
1949
|
+
try:
|
|
1950
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
1951
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
1952
|
+
|
|
1953
|
+
if self.Problem_Objective=="Classification":
|
|
1954
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
1955
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
1956
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
1957
|
+
|
|
1958
|
+
model = load_object(file_path=model_path)
|
|
1959
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
1960
|
+
print("Model Loaded Succesfully")
|
|
1961
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
1962
|
+
data_scaled = preprocessor.transform(features)
|
|
1963
|
+
preds = model.predict(data_scaled)
|
|
1964
|
+
if self.Problem_Objective=="Classification":
|
|
1965
|
+
preds = preds.astype(int)
|
|
1966
|
+
preds = label_encoder.inverse_transform(preds)
|
|
1967
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
1968
|
+
|
|
1969
|
+
return preds
|
|
1970
|
+
|
|
1971
|
+
except Exception as e:
|
|
1972
|
+
raise CustomException(e, sys)
|
|
1973
|
+
|
|
1974
|
+
class CustomData:
|
|
1975
|
+
|
|
1976
|
+
"""
|
|
1977
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
1978
|
+
It will take care of all the Features .
|
|
1979
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
1980
|
+
providing flexibility in working with different datasets.
|
|
1981
|
+
"""
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
def __init__(self,features_cols, **kwargs):
|
|
1985
|
+
try:
|
|
1986
|
+
self.Features_Cols = features_cols
|
|
1987
|
+
for feature in self.Features_Cols:
|
|
1988
|
+
# print(feature)
|
|
1989
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
1990
|
+
|
|
1991
|
+
except Exception as e:
|
|
1992
|
+
raise CustomException(e, sys)
|
|
1993
|
+
|
|
1994
|
+
def get_data_as_data_frame(self):
|
|
1995
|
+
|
|
1996
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
1997
|
+
|
|
1998
|
+
try:
|
|
1999
|
+
custom_data_input_dict = {}
|
|
2000
|
+
for feature in self.Features_Cols:
|
|
2001
|
+
feature_value = getattr(self,feature)
|
|
2002
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
2003
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
2004
|
+
logging.info("Features Loaded Succesfully")
|
|
2005
|
+
#print(custom_data_input_dict)
|
|
2006
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
2007
|
+
|
|
2008
|
+
except Exception as e:
|
|
2009
|
+
raise CustomException(e, sys)
|
|
2010
|
+
class PredictPipeline:
|
|
2011
|
+
|
|
2012
|
+
""""
|
|
2013
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
2014
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
2015
|
+
|
|
2016
|
+
"""
|
|
2017
|
+
|
|
2018
|
+
def __init__(self, problem_objective):
|
|
2019
|
+
self.Problem_Objective = problem_objective
|
|
2020
|
+
|
|
2021
|
+
def predict(self, features):
|
|
2022
|
+
|
|
2023
|
+
"""
|
|
2024
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
2025
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
2026
|
+
|
|
2027
|
+
"""
|
|
2028
|
+
|
|
2029
|
+
try:
|
|
2030
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
2031
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
2032
|
+
|
|
2033
|
+
if self.Problem_Objective=="Classification":
|
|
2034
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
2035
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
2036
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
2037
|
+
|
|
2038
|
+
model = load_object(file_path=model_path)
|
|
2039
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
2040
|
+
print("Model Loaded Succesfully")
|
|
2041
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
2042
|
+
data_scaled = preprocessor.transform(features)
|
|
2043
|
+
preds = model.predict(data_scaled)
|
|
2044
|
+
if self.Problem_Objective=="Classification":
|
|
2045
|
+
preds = preds.astype(int)
|
|
2046
|
+
preds = label_encoder.inverse_transform(preds)
|
|
2047
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
2048
|
+
|
|
2049
|
+
return preds
|
|
2050
|
+
|
|
2051
|
+
except Exception as e:
|
|
2052
|
+
raise CustomException(e, sys)
|
|
2053
|
+
|
|
2054
|
+
class CustomData:
|
|
2055
|
+
|
|
2056
|
+
"""
|
|
2057
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
2058
|
+
It will take care of all the Features .
|
|
2059
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
2060
|
+
providing flexibility in working with different datasets.
|
|
2061
|
+
"""
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
def __init__(self,features_cols, **kwargs):
|
|
2065
|
+
try:
|
|
2066
|
+
self.Features_Cols = features_cols
|
|
2067
|
+
for feature in self.Features_Cols:
|
|
2068
|
+
# print(feature)
|
|
2069
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
2070
|
+
|
|
2071
|
+
except Exception as e:
|
|
2072
|
+
raise CustomException(e, sys)
|
|
2073
|
+
|
|
2074
|
+
def get_data_as_data_frame(self):
|
|
2075
|
+
|
|
2076
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
2077
|
+
|
|
2078
|
+
try:
|
|
2079
|
+
custom_data_input_dict = {}
|
|
2080
|
+
for feature in self.Features_Cols:
|
|
2081
|
+
feature_value = getattr(self,feature)
|
|
2082
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
2083
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
2084
|
+
logging.info("Features Loaded Succesfully")
|
|
2085
|
+
#print(custom_data_input_dict)
|
|
2086
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
2087
|
+
|
|
2088
|
+
except Exception as e:
|
|
2089
|
+
raise CustomException(e, sys)
|
|
2090
|
+
class PredictPipeline:
|
|
2091
|
+
|
|
2092
|
+
""""
|
|
2093
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
2094
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
2095
|
+
|
|
2096
|
+
"""
|
|
2097
|
+
|
|
2098
|
+
def __init__(self, problem_objective):
|
|
2099
|
+
self.Problem_Objective = problem_objective
|
|
2100
|
+
|
|
2101
|
+
def predict(self, features):
|
|
2102
|
+
|
|
2103
|
+
"""
|
|
2104
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
2105
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
2106
|
+
|
|
2107
|
+
"""
|
|
2108
|
+
|
|
2109
|
+
try:
|
|
2110
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
2111
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
2112
|
+
|
|
2113
|
+
if self.Problem_Objective=="Classification":
|
|
2114
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
2115
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
2116
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
2117
|
+
|
|
2118
|
+
model = load_object(file_path=model_path)
|
|
2119
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
2120
|
+
print("Model Loaded Succesfully")
|
|
2121
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
2122
|
+
data_scaled = preprocessor.transform(features)
|
|
2123
|
+
preds = model.predict(data_scaled)
|
|
2124
|
+
if self.Problem_Objective=="Classification":
|
|
2125
|
+
preds = preds.astype(int)
|
|
2126
|
+
preds = label_encoder.inverse_transform(preds)
|
|
2127
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
2128
|
+
|
|
2129
|
+
return preds
|
|
2130
|
+
|
|
2131
|
+
except Exception as e:
|
|
2132
|
+
raise CustomException(e, sys)
|
|
2133
|
+
|
|
2134
|
+
class CustomData:
|
|
2135
|
+
|
|
2136
|
+
"""
|
|
2137
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
2138
|
+
It will take care of all the Features .
|
|
2139
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
2140
|
+
providing flexibility in working with different datasets.
|
|
2141
|
+
"""
|
|
2142
|
+
|
|
2143
|
+
|
|
2144
|
+
def __init__(self,features_cols, **kwargs):
|
|
2145
|
+
try:
|
|
2146
|
+
self.Features_Cols = features_cols
|
|
2147
|
+
for feature in self.Features_Cols:
|
|
2148
|
+
# print(feature)
|
|
2149
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
2150
|
+
|
|
2151
|
+
except Exception as e:
|
|
2152
|
+
raise CustomException(e, sys)
|
|
2153
|
+
|
|
2154
|
+
def get_data_as_data_frame(self):
|
|
2155
|
+
|
|
2156
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
2157
|
+
|
|
2158
|
+
try:
|
|
2159
|
+
custom_data_input_dict = {}
|
|
2160
|
+
for feature in self.Features_Cols:
|
|
2161
|
+
feature_value = getattr(self,feature)
|
|
2162
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
2163
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
2164
|
+
logging.info("Features Loaded Succesfully")
|
|
2165
|
+
#print(custom_data_input_dict)
|
|
2166
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
2167
|
+
|
|
2168
|
+
except Exception as e:
|
|
2169
|
+
raise CustomException(e, sys)
|
|
2170
|
+
class PredictPipeline:
|
|
2171
|
+
|
|
2172
|
+
""""
|
|
2173
|
+
Yes if train a model then we also need to use it and predict the values out of it.
|
|
2174
|
+
This will predict our Target Variable using Trained best Model and give outcomes.
|
|
2175
|
+
|
|
2176
|
+
"""
|
|
2177
|
+
|
|
2178
|
+
def __init__(self, problem_objective):
|
|
2179
|
+
self.Problem_Objective = problem_objective
|
|
2180
|
+
|
|
2181
|
+
def predict(self, features):
|
|
2182
|
+
|
|
2183
|
+
"""
|
|
2184
|
+
Given Features in the Predict Funciton it take our test file and output the prediction.
|
|
2185
|
+
If classification then it will handle label encoding (from the pkl file) and reverse it to the orignal values.
|
|
2186
|
+
|
|
2187
|
+
"""
|
|
2188
|
+
|
|
2189
|
+
try:
|
|
2190
|
+
model_path = os.path.join("artifact", "model.pkl")
|
|
2191
|
+
preprocessor_path = os.path.join('artifact', 'prerocessor.pkl')
|
|
2192
|
+
|
|
2193
|
+
if self.Problem_Objective=="Classification":
|
|
2194
|
+
label_encoder_path = os.path.join('artifact','Targetlabel.pkl')
|
|
2195
|
+
label_encoder = load_object(file_path=label_encoder_path)
|
|
2196
|
+
logging.info("Here Target_label is also loaded succesfully")
|
|
2197
|
+
|
|
2198
|
+
model = load_object(file_path=model_path)
|
|
2199
|
+
preprocessor = load_object(file_path=preprocessor_path)
|
|
2200
|
+
print("Model Loaded Succesfully")
|
|
2201
|
+
logging.info("Preprocessing and model Loading is Successful")
|
|
2202
|
+
data_scaled = preprocessor.transform(features)
|
|
2203
|
+
preds = model.predict(data_scaled)
|
|
2204
|
+
if self.Problem_Objective=="Classification":
|
|
2205
|
+
preds = preds.astype(int)
|
|
2206
|
+
preds = label_encoder.inverse_transform(preds)
|
|
2207
|
+
logging.info("Classification Done Succesfully and decoded the prediction to orignal Target Values")
|
|
2208
|
+
|
|
2209
|
+
return preds
|
|
2210
|
+
|
|
2211
|
+
except Exception as e:
|
|
2212
|
+
raise CustomException(e, sys)
|
|
2213
|
+
|
|
2214
|
+
class CustomData:
|
|
2215
|
+
|
|
2216
|
+
"""
|
|
2217
|
+
Our Program do not need to give Features and DF hard coded into this,
|
|
2218
|
+
It will take care of all the Features .
|
|
2219
|
+
CustomData class is designed to dynamically handle features and convert them into a DataFrame,
|
|
2220
|
+
providing flexibility in working with different datasets.
|
|
2221
|
+
"""
|
|
2222
|
+
|
|
2223
|
+
|
|
2224
|
+
def __init__(self,features_cols, **kwargs):
|
|
2225
|
+
try:
|
|
2226
|
+
self.Features_Cols = features_cols
|
|
2227
|
+
for feature in self.Features_Cols:
|
|
2228
|
+
# print(feature)
|
|
2229
|
+
setattr(self, feature, kwargs.get(feature, None))
|
|
2230
|
+
|
|
2231
|
+
except Exception as e:
|
|
2232
|
+
raise CustomException(e, sys)
|
|
2233
|
+
|
|
2234
|
+
def get_data_as_data_frame(self):
|
|
2235
|
+
|
|
2236
|
+
""" Here it will take our Custom data and convert it into Dataframe"""
|
|
2237
|
+
|
|
2238
|
+
try:
|
|
2239
|
+
custom_data_input_dict = {}
|
|
2240
|
+
for feature in self.Features_Cols:
|
|
2241
|
+
feature_value = getattr(self,feature)
|
|
2242
|
+
#print("Fearture: ",feature,"Value: ",type(list(feature_value)))
|
|
2243
|
+
custom_data_input_dict[feature] = list(feature_value)
|
|
2244
|
+
logging.info("Features Loaded Succesfully")
|
|
2245
|
+
#print(custom_data_input_dict)
|
|
2246
|
+
return pd.DataFrame(custom_data_input_dict)
|
|
2247
|
+
|
|
2248
|
+
except Exception as e:
|
|
2249
|
+
raise CustomException(e, sys)
|