JustDataML 0.0.26__tar.gz

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.
@@ -0,0 +1,153 @@
1
+ #python3
2
+
3
+ import os
4
+ import sys
5
+ import pandas as pd
6
+ import argparse
7
+
8
+
9
+
10
+ from .source.Exception import CustomException
11
+ from .source.Pipeline import Train_Pipeline
12
+ from .source.Pipeline.Predict_Pipeline import PredictPipeline,CustomData
13
+ from .source.Logger import logging
14
+ from .source.Configuration import DataProcessor
15
+
16
+
17
+ class Just_Data_ML:
18
+
19
+ """
20
+ Just_Data_ML is a class to train and predict our Values
21
+ """
22
+
23
+ def __init__(self,args):
24
+ self.args = args
25
+ #self.data_processor = DataProcessor(os.path.join("Data", "Data_Config.csv"))
26
+ self.data_processor = DataProcessor(args.Config)
27
+ self.data_processor.load_config()
28
+ self.data_processor.read_data()
29
+ self.Data_df = self.data_processor.Data_df
30
+ self.Features_Cols = self.data_processor.Features_Cols
31
+ self.Target_Col = self.data_processor.Target_Col
32
+ self.Models = self.data_processor.Models
33
+ self.HyperParamter_Yes_or_No = self.data_processor.HyperParamter_Yes_or_No
34
+ self.Problem_Objective = self.data_processor.Problem_Objective
35
+ self.Normalization_tech = self.data_processor.scaler
36
+
37
+ def Data_Train(self):
38
+
39
+ """
40
+ Here we are calling Train_pipeline and Training our models and saving it to the files we can use for Prediction.
41
+ """
42
+
43
+ try:
44
+ os.makedirs("Output",exist_ok=True)
45
+ train_ourconfig_model = Train_Pipeline.TrainingPipeline(self.Features_Cols, self.Data_df, self.Target_Col, self.Models, self.HyperParamter_Yes_or_No, self.Problem_Objective,self.Normalization_tech)
46
+ train_ourconfig_model.Train_Model()
47
+
48
+ except Exception as e:
49
+ raise CustomException(e,sys)
50
+
51
+
52
+ def Predict_test(self):
53
+
54
+ """
55
+ Here we are Doing prediction base on our trianed model using in pervious function and importing Predict_pipeline
56
+ it will take Dataframe and as input (you can use csv file and pass it to the function)
57
+ """
58
+
59
+ try:
60
+ predict_val = PredictPipeline(self.Problem_Objective)
61
+ data = pd.read_csv(self.args.Predict)
62
+ input_features = data.columns
63
+
64
+ custom_data = CustomData(self.Features_Cols,**dict.fromkeys(input_features))
65
+
66
+ for feature in input_features:
67
+ custom_data.__dict__[feature] = data[feature]
68
+
69
+ data_frame = custom_data.get_data_as_data_frame()
70
+
71
+ final_pred = predict_val.predict(data_frame)
72
+ data["Target_Out"] = final_pred
73
+ if self.args.Output:
74
+ out_path = os.path.join('Output',f'{self.args.Output}.csv')
75
+ print(f"Predicted file is saved in {out_path}")
76
+ logging.info(f"Predicted file is saved in {out_path}")
77
+ else:
78
+ out_path = os.path.join('Output','Target_outFile.csv')
79
+ print(f"Predicted file is saved in {out_path} : Note --Output was not given")
80
+ logging.info(f"Predicted file is saved in {out_path} : Note --Output was not given")
81
+ data.to_csv(out_path,index=False)
82
+ logging.info("Your Model Has Given Prediction Congratulations !!! Your Prediction Files ready in Output Folder")
83
+ except Exception as e:
84
+ raise CustomException(e,sys)
85
+
86
+
87
+
88
+
89
+ def MLtool():
90
+ parser = argparse.ArgumentParser(
91
+ prog="JDML",
92
+ formatter_class=argparse.RawDescriptionHelpFormatter,
93
+ description="""\
94
+ Tool : JustData_ML (JDML)
95
+ Author: Jaideepsinh Dabhi
96
+ emailID: jaideep.dabhi7603@gmail.com
97
+ Usage : JDML.py -C <Data_Config.csv>-T -P <test.csv> -O <Output Folder>
98
+
99
+ * This Tool is Design to Train Machine Learning models and give prediction to help non coder or non tech students to do ML.
100
+ * This Tool will Train models with various paramters and give output.
101
+
102
+ *****************\n
103
+ ARUGMENTS
104
+ -C, --Config [Compulsory] You need to provide a configuration file to obtain all the necessary arguments for ML models to operate.
105
+ Make Sure you give Proper Argument mentioned in the Document.
106
+ -T, --Train [Optional] If you give this function it will start training your model based on your data_config file.
107
+ Make Sure you have Data in "Data" Folder.
108
+ -P, --Predict [Optional] If you give this function it will do prediction based on your trained model.
109
+ Make Sure you don't delete or modify artifact folder to get better results.
110
+ -O, --Output [Please give with --Predict ]Name of Output csv file (if not given it will store data in Target_outFile csv file)
111
+ It will store you input test file to output folder with 'Target_Out' Col containing Predictions based on your model.
112
+
113
+ """,
114
+ epilog=" Contact jaideep.dabhi7603@gmail.com for any help or suggestion."
115
+ )
116
+
117
+ parser.add_argument('-C', '--Config', type = str, help=" Give a Config file to Application to get details about your task ")
118
+ parser.add_argument('-T', '--Train', action="store_true", default=False, help=" Give a Train argument to Train Data and create a Model")
119
+ parser.add_argument('-P', '--Predict', type=str, help=" Give a Test Data to Predict the Values from the Model")
120
+ parser.add_argument('-O', '--Output', type=str, help=" Give a Output name to Predicted Data Frame from Test Data")
121
+
122
+ args, _ = parser.parse_known_args()
123
+
124
+ if not any(vars(args).values()): # Check if no arguments were provided
125
+ parser.print_usage()
126
+ else:
127
+ jdml_instance = Just_Data_ML(args)
128
+
129
+ if args.Train and not args.Predict:
130
+ jdml_instance.Data_Train()
131
+ print("Training of Data is Done please Do prediction using model in artifact folder")
132
+
133
+
134
+ elif args.Train and args.Predict:
135
+ jdml_instance.Data_Train()
136
+ jdml_instance.Predict_test()
137
+ print("Training and Prediction Done for given Data")
138
+
139
+ elif args.Predict and not args.Train:
140
+ jdml_instance.Predict_test()
141
+ print("Model as predicted Values Based on Periously Trained Data in artifact folder")
142
+
143
+ elif args.Output and not args.Predict:
144
+
145
+ print("NO INPUT DATA PLEASE PROVIDE INPUT DATA (-P or --Predict Argument) to Predict Data")
146
+
147
+ else:
148
+ print("Some Problem with Arguments")
149
+ parser.print_help()
150
+
151
+
152
+ if __name__ == "__main__":
153
+ MLtool()
@@ -0,0 +1 @@
1
+ #Python
@@ -0,0 +1,64 @@
1
+ import pandas as pd
2
+ import os
3
+ import sys
4
+
5
+ from ..source.Utils import ReadConfig , regressor_models, classfication_models,Normalization_method
6
+ from ..source.Exception import CustomException
7
+
8
+
9
+
10
+
11
+ class DataProcessor:
12
+ def __init__(self, config_file):
13
+ self.config_file = config_file
14
+
15
+ def load_config(self):
16
+ self.DataConfig = ReadConfig(self.config_file)
17
+
18
+ def read_data(self):
19
+ try:
20
+ self.Data_df = pd.read_csv(os.path.join("Data", self.DataConfig['Data_Name'][0]))
21
+ self.Features_Cols = self.DataConfig["Features_Cols"]
22
+ self.Target_Col = self.DataConfig["Target_Col"]
23
+ self.Normalization_tech = self.DataConfig["Normalization_tech"][0]
24
+ self.Model_to_include = self.DataConfig["Model_to_include"]
25
+ self.Problem_Objective = self.DataConfig["Problem_Objective"][0]
26
+ if self.Problem_Objective == "Regression":
27
+ if self.Model_to_include[0] == "ALL":
28
+ self.Models = regressor_models
29
+ else:
30
+ self.Models = {key: value for key, value in regressor_models.items() if key in self.Model_to_include}
31
+ elif self.Problem_Objective == "Classification":
32
+ if self.Model_to_include[0] == "ALL":
33
+ self.Models = classfication_models
34
+ else:
35
+ self.Models = {key: value for key, value in classfication_models.items() if key in self.Model_to_include}
36
+ else:
37
+ print(f"Problem obj is '{self.Problem_Objective}' this is not properly define please add Proper problem objective i.e 'Regression' or 'Classification'")
38
+
39
+ if self.Normalization_tech in Normalization_method:
40
+ self.scaler = Normalization_method[self.Normalization_tech]
41
+ else:
42
+ print(f"{self.Normalization_tech} is not a valid normalization method.")
43
+
44
+
45
+ self.HyperParamter_Yes_or_No = self.DataConfig["HyperParamter_Yes_or_No"][0]
46
+ except Exception as e:
47
+ raise CustomException(e,sys)
48
+
49
+
50
+
51
+ #Example usage:
52
+ # ConfigFile = os.path.join("Data","Data_Config.csv")
53
+ # data_processor = DataProcessor(ConfigFile)
54
+ # data_processor.load_config()
55
+ # data_processor.read_data()
56
+ # Data_df = data_processor.Data_df
57
+ # Features_Cols = data_processor.Features_Cols
58
+ # Target_Col = data_processor.Target_Col
59
+ # Normalization_tech = data_processor.Normalization_tech
60
+ # Problem_Objective = data_processor.Problem_Objective
61
+ # Models = data_processor.Models
62
+ # HyperParamter_Yes_or_No = data_processor.HyperParamter_Yes_or_No
63
+
64
+
@@ -0,0 +1,21 @@
1
+ import sys
2
+
3
+
4
+
5
+
6
+ def error_message_detail(error,error_details:sys):
7
+ _,_,exc_tb = error_details.exc_info()
8
+ file_name = exc_tb.tb_frame.f_code.co_filename
9
+ error_message = "Error Occured in Python Script Name : [{0}] \n , Line Number [{1}] \n error message [{2}] ".format(
10
+ file_name,exc_tb.tb_lineno,str(error))
11
+ return error_message
12
+
13
+
14
+ class CustomException(Exception):
15
+ def __init__(self,error_message,error_details:sys):
16
+ super().__init__(error_message)
17
+ self.error_message=error_message_detail(error_message,error_details=error_details)
18
+
19
+
20
+ def __str__(self):
21
+ return self.error_message
@@ -0,0 +1,16 @@
1
+ import logging
2
+ import os
3
+ from datetime import datetime
4
+
5
+ LOG_FILE =f"{datetime.now().strftime('%d_%m_%Y_%H_%M_%S')}.log"
6
+ logs_path = os.path.join(os.getcwd(),"logs",f"{datetime.now().strftime('%d_%m_%Y')}-logs")
7
+ os.makedirs(logs_path,exist_ok=True)
8
+
9
+ LOG_FILE_PATH = os.path.join(logs_path,LOG_FILE)
10
+
11
+ logging.basicConfig(
12
+ filename=LOG_FILE_PATH,
13
+ format="[ %(asctime)s ] - %(filename)s - %(lineno)d %(name)s - %(levelname)s - %(message)s",
14
+ level=logging.INFO
15
+
16
+ )