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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from src.data_reader import DataReader
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from src.feature_handler import FeatureHandler
|
| 5 |
+
from src.model_trainer import ModelTrainer
|
| 6 |
+
from src.evaluator import Evaluator
|
| 7 |
+
from src.config import *
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import json
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def extract_column_info(df):
|
| 13 |
+
column_info = {}
|
| 14 |
+
for column in df.columns:
|
| 15 |
+
column_info[column] = {
|
| 16 |
+
"feature_name": column,
|
| 17 |
+
"is_selected": True,
|
| 18 |
+
"feature_variable_type": str(df[column].dtype),
|
| 19 |
+
"feature_details": {
|
| 20 |
+
"numerical_handling": None,
|
| 21 |
+
"rescaling": False,
|
| 22 |
+
"scaling_type": None,
|
| 23 |
+
"make_derived_feats": False,
|
| 24 |
+
"missing_values": "Impute",
|
| 25 |
+
"impute_with": None
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
return column_info
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def extract_algorithms_info(algo_list):
|
| 32 |
+
algo_info = {}
|
| 33 |
+
for algo in algo_list:
|
| 34 |
+
algo_info[algo] = {
|
| 35 |
+
"model_name" : algo,
|
| 36 |
+
"is_selected" : False,
|
| 37 |
+
"random_state" : [42]
|
| 38 |
+
}
|
| 39 |
+
return algo_info
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def generate_json(session_name, dataset_name, target, train, feature_handling, algorithms):
|
| 43 |
+
json_data = {
|
| 44 |
+
"session_name": session_name,
|
| 45 |
+
"session_description": session_name,
|
| 46 |
+
"design_state_data": {
|
| 47 |
+
"session_info": {
|
| 48 |
+
"dataset": dataset_name,
|
| 49 |
+
"session_name": session_name,
|
| 50 |
+
"session_description": session_name
|
| 51 |
+
},
|
| 52 |
+
"target": target,
|
| 53 |
+
"train": train,
|
| 54 |
+
"feature_handling": feature_handling,
|
| 55 |
+
"algorithms": algorithms
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
return json_data
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def train_models(save_file_path, json_file):
|
| 63 |
+
if json_file is not None:
|
| 64 |
+
with st.spinner('Hang On, Training Models For You...'):
|
| 65 |
+
# Read the RTF file and parse the JSON content
|
| 66 |
+
data_reader = DataReader(rtf_file_path=save_file_path)
|
| 67 |
+
json_content = data_reader.rtf_to_json_parser()
|
| 68 |
+
|
| 69 |
+
# Extract dataset information from JSON
|
| 70 |
+
problem_type, target_variable = data_reader.get_problem_type_and_target_variable()
|
| 71 |
+
|
| 72 |
+
# Extract feature names and target variable from JSON content
|
| 73 |
+
selected_features, feature_details = data_reader.get_selected_features_and_details()
|
| 74 |
+
|
| 75 |
+
# Transform features
|
| 76 |
+
feature_handler = FeatureHandler(json_content)
|
| 77 |
+
X_train, X_test, y_train, y_test = feature_handler.get_split_dataset(selected_features)
|
| 78 |
+
|
| 79 |
+
X_train_transformed , X_test_transformed = feature_handler.transform_X_features(X_train, X_test, feature_details)
|
| 80 |
+
y_train_transformed , y_test_transformed = feature_handler.transform_y_features(y_train, y_test, feature_details, target_variable)
|
| 81 |
+
|
| 82 |
+
# Model building and hyperparameter tuning
|
| 83 |
+
selected_models, model_parameters = data_reader.get_selected_models()
|
| 84 |
+
model_trainer = ModelTrainer(json_content)
|
| 85 |
+
trained_models = model_trainer.build_and_tune_model(X_train_transformed, y_train_transformed,
|
| 86 |
+
problem_type, selected_models, model_parameters)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
# Evaluate the model
|
| 90 |
+
evaluator = Evaluator(json_content, problem_type, target_variable)
|
| 91 |
+
evaluation_results = evaluator.evaluate_model(trained_models, X_test_transformed, y_test_transformed)
|
| 92 |
+
# display bar chart of evaluation results
|
| 93 |
+
st.subheader("Different Model Comparison")
|
| 94 |
+
evaluator.display_metrics(evaluation_results)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
else:
|
| 99 |
+
st.error("Please upload a JSON file first.")
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def create_json_and_train():
|
| 103 |
+
|
| 104 |
+
st.write("### Upload Dataset: ")
|
| 105 |
+
uploaded_file = st.file_uploader("Upload Dataset CSV", type=['csv'])
|
| 106 |
+
|
| 107 |
+
if uploaded_file is not None:
|
| 108 |
+
df = pd.read_csv(uploaded_file)
|
| 109 |
+
st.write("### Sample Data:")
|
| 110 |
+
st.write(df.head())
|
| 111 |
+
|
| 112 |
+
# Extract column information
|
| 113 |
+
column_info = extract_column_info(df)
|
| 114 |
+
|
| 115 |
+
# take input for prediction_type
|
| 116 |
+
st.write("### Select Prediction Parameters:")
|
| 117 |
+
prediction_type = st.selectbox("Prediction Type", ["Regression", "Classification"], key="prediction_selectbox")
|
| 118 |
+
|
| 119 |
+
# Checkbox for selecting target columns and feature details
|
| 120 |
+
target_variable = st.selectbox("Target Variable", df.columns, key="target_selectbox")
|
| 121 |
+
|
| 122 |
+
# add option to let user select how to encode target variable
|
| 123 |
+
|
| 124 |
+
column_info[target_variable]["feature_details"] = {}
|
| 125 |
+
# if target_variable is of category type, add option to label encode
|
| 126 |
+
if column_info[target_variable]["feature_variable_type"] == "object":
|
| 127 |
+
column_info[target_variable]["feature_details"]["text_handling"] = st.selectbox("Text Handling", ["Tokenize and hash", "Label Encoding"], key="text_handling_selectbox", index=0)
|
| 128 |
+
|
| 129 |
+
train = {}
|
| 130 |
+
train["k_fold"] = st.number_input("K-Fold", min_value=2, value=5, step=1, key="kfold")
|
| 131 |
+
train["train_ratio"] = st.number_input("Train Ratio", min_value=0.0, max_value=1.0, value=0.8, step=0.1, key="train_ratio")
|
| 132 |
+
train["random_seed"] = st.number_input("Random Seed", min_value=0, value=42, step=1, key="random_seed")
|
| 133 |
+
|
| 134 |
+
target = {"prediction_type": prediction_type,
|
| 135 |
+
"target": target_variable,
|
| 136 |
+
"type": prediction_type,
|
| 137 |
+
"partitioning": True}
|
| 138 |
+
|
| 139 |
+
st.write("### Select Columns to Include:")
|
| 140 |
+
for column in column_info:
|
| 141 |
+
if column != target_variable:
|
| 142 |
+
column_info[column]["is_selected"] = st.checkbox(column, key=f"{column}_checkbox", value=False)
|
| 143 |
+
if column_info[column]["is_selected"]:
|
| 144 |
+
with st.expander(f"{column} Feature Handling", expanded=False):
|
| 145 |
+
column_info[column]["feature_details"]["rescaling"] = st.checkbox("Rescaling", key=f"{column}_scaling_checkbox")
|
| 146 |
+
if column_info[column]["feature_details"]["rescaling"] and column_info[column]["feature_variable_type"] != "object":
|
| 147 |
+
column_info[column]["feature_details"]["scaling_type"] = st.selectbox("Scaling Type", ["MinMaxScaler", "StandardScaler"], key=f"{column}_scaling_type_select")
|
| 148 |
+
column_info[column]["feature_details"]["missing_values"] = st.checkbox("Imputation", key=f"{column}_imputation_checkbox")
|
| 149 |
+
if column_info[column]["feature_details"]["missing_values"]:
|
| 150 |
+
column_info[column]["feature_details"]["impute_with"] = st.selectbox("Imputation With", ["Mean", "Median", "Mode", "Custom"], key=f"{column}_imputation_type_select")
|
| 151 |
+
if column_info[column]["feature_details"]["impute_with"] == "Custom":
|
| 152 |
+
column_info[column]["feature_details"]["custom_impute_value"] = st.text_input(f"Custom Impute Value", key=f"{column}_imputation_value_input")
|
| 153 |
+
if column_info[column]["feature_variable_type"] == "object":
|
| 154 |
+
column_info[column]["feature_details"]["encoding"] = st.selectbox("Encode Categorical Feature with", ["OridnalEncoder", "OneHotEncoder"], key = f"{column}_encoding_type")
|
| 155 |
+
# Checkbox for selecting columns
|
| 156 |
+
st.write(f"### Select {prediction_type} Algorithms:")
|
| 157 |
+
if prediction_type == "Regression":
|
| 158 |
+
algorithms_list = ["RandomForestRegressor", "LinearRegression", "RidgeRegression", "LassoRegression",
|
| 159 |
+
"ElasticNetRegression","xg_boost", "DecisionTreeRegressor", "SVM", "KNN", "neural_network"]
|
| 160 |
+
else:
|
| 161 |
+
algorithms_list = ["RandomForestClassifier", "LogisticRegression", "xg_boost",
|
| 162 |
+
"DecisionTreeClassifier", "SVM", "KNN", "neural_network"]
|
| 163 |
+
|
| 164 |
+
algo_info = extract_algorithms_info(algorithms_list)
|
| 165 |
+
for algo in algo_info:
|
| 166 |
+
algo_info[algo]["is_selected"] = st.checkbox(algo, key=f"{algo}_checkbox")
|
| 167 |
+
if algo_info[algo]["is_selected"]:
|
| 168 |
+
with st.expander(f"{algo} HyperParameters", expanded=False):
|
| 169 |
+
if algo == "RandomForestClassifier" or algo == "RandomForestRegressor":
|
| 170 |
+
algo_info[algo]["min_trees"] = st.number_input("Minimum Trees", min_value=1, max_value=100, value=10, step=1, key=f"{algo}_min_trees")
|
| 171 |
+
algo_info[algo]["max_trees"] = st.number_input("Maximum Trees", min_value=1, max_value=100, value=30, step=1, key=f"{algo}_max_trees")
|
| 172 |
+
algo_info[algo]["min_depth"] = st.number_input("Minimum Depth", min_value=1, max_value=100, value=20, step=1, key=f"{algo}_min_depth")
|
| 173 |
+
algo_info[algo]["max_depth"] = st.number_input("Maximum Depth", min_value=1, max_value=100, value=30, step=1, key=f"{algo}_max_depth")
|
| 174 |
+
algo_info[algo]["min_samples_per_leaf_min_value"] = st.number_input("Minimum Samples Per Leaf", min_value=1, max_value=100, value=5, step=1, key=f"{algo}_min_samples_per_leaf")
|
| 175 |
+
algo_info[algo]["min_samples_per_leaf_max_value"] = st.number_input("Maximum Samples Per Leaf", min_value=1, max_value=100, value=50, step=1, key=f"{algo}_max_samples_per_leaf")
|
| 176 |
+
|
| 177 |
+
elif algo == "LinearRegression" or algo == "LogisticRegression" or algo == "ElasticNetRegression":
|
| 178 |
+
algo_info[algo]["min_iter"] = st.number_input("Minimum Iterations", min_value=1, max_value=100, value=30, step=1, key=f"{algo}_min_iter")
|
| 179 |
+
algo_info[algo]["max_iter"] = st.number_input("Maximum Iterations", min_value=1, max_value=100, value=50, step=1, key=f"{algo}_max_iter")
|
| 180 |
+
algo_info[algo]["min_regparam"] = st.number_input("Minimum Regularization Parameter", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key=f"{algo}_min_regparam")
|
| 181 |
+
algo_info[algo]["max_regparam"] = st.number_input("Maximum Regularization Parameter", min_value=0.0, max_value=1.0, value=0.8, step=0.1, key=f"{algo}_max_regparam")
|
| 182 |
+
algo_info[algo]["min_elasticnet"] = st.number_input("Minimum Elasticnet", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key=f"{algo}_min_elasticnet")
|
| 183 |
+
algo_info[algo]["max_elasticnet"] = st.number_input("Maximum Elasticnet", min_value=0.0, max_value=1.0, value=0.8, step=0.1, key=f"{algo}_max_elasticnet")
|
| 184 |
+
|
| 185 |
+
elif algo == "RidgeRegression" or algo == "LassoRegression":
|
| 186 |
+
algo_info[algo]["min_iter"] = st.number_input("Minimum Iterations", min_value=1, max_value=100, value=30, step=1, key=f"{algo}_min_iter")
|
| 187 |
+
algo_info[algo]["max_iter"] = st.number_input("Maximum Iterations", min_value=1, max_value=100, value=50, step=1, key=f"{algo}_max_iter")
|
| 188 |
+
algo_info[algo]["min_regparam"] = st.number_input("Minimum Regularization Parameter", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key=f"{algo}_min_regparam")
|
| 189 |
+
algo_info[algo]["max_regparam"] = st.number_input("Maximum Regularization Parameter", min_value=0.0, max_value=1.0, value=0.8, step=0.1, key=f"{algo}_max_regparam")
|
| 190 |
+
|
| 191 |
+
elif algo == "DecisionTreeClassifier" or algo == "DecisionTreeRegressor":
|
| 192 |
+
algo_info[algo]["min_depth"] = st.number_input("Minimum Depth", min_value=1, max_value=100, value=4, step=1, key=f"{algo}_min_depth")
|
| 193 |
+
algo_info[algo]["max_depth"] = st.number_input("Maximum Depth", min_value=1, max_value=100, value=7, step=1, key=f"{algo}_max_depth")
|
| 194 |
+
algo_info[algo]["use_gini"] = st.checkbox("Use Gini Index", value=False, key=f"{algo}_use_gini")
|
| 195 |
+
algo_info[algo]["use_entropy"] = st.checkbox("Use Entropy", value=True, key=f"{algo}_use_entropy")
|
| 196 |
+
algo_info[algo]["min_samples_per_leaf"] = st.text_input("Minimum Samples Per Leaf", placeholder="Enter comma separated list of values for min_samples_per_leaf",
|
| 197 |
+
key=f"{algo}_min_samples_per_leaf")
|
| 198 |
+
# check if min_samples_per_leaf is there
|
| 199 |
+
if algo_info[algo]["min_samples_per_leaf"]:
|
| 200 |
+
algo_info[algo]["min_samples_per_leaf"] = [int(x) for x in algo_info[algo]["min_samples_per_leaf"].split(",")]
|
| 201 |
+
else:
|
| 202 |
+
algo_info[algo]["min_samples_per_leaf"] = [12, 6]
|
| 203 |
+
algo_info[algo]["use_best"] = st.checkbox("Use Best", value=True, key=f"{algo}_use_best")
|
| 204 |
+
algo_info[algo]["use_random"] = st.checkbox("Use Random", value=True, key=f"{algo}_use_random")
|
| 205 |
+
|
| 206 |
+
elif algo == "SVM":
|
| 207 |
+
algo_info[algo]["linear_kernel"] = st.checkbox("Linear Kernel", value=True, key=f"{algo}_linear_kernel")
|
| 208 |
+
algo_info[algo]["rep_kernel"] = st.checkbox("Rep Kernel", value=True, key=f"{algo}_rep_kernel")
|
| 209 |
+
algo_info[algo]["polynomial_kernel"] = st.checkbox("Polynomial Kernel", value=True, key=f"{algo}_polynomial_kernel")
|
| 210 |
+
algo_info[algo]["sigmoid_kernel"] = st.checkbox("Sigmoid Kernel", value=True, key=f"{algo}_sigmoid_kernel")
|
| 211 |
+
algo_info[algo]["c_value"] = st.text_input("C Value", placeholder="Enter comma separated list of values for C Value", key=f"{algo}_c_value")
|
| 212 |
+
# convert c values into list of integers
|
| 213 |
+
if algo_info[algo]["c_value"]:
|
| 214 |
+
algo_info[algo]["c_value"] = [int(x) for x in algo_info[algo]["c_value"].split(",")]
|
| 215 |
+
else:
|
| 216 |
+
algo_info[algo]["c_value"] = [566, 79]
|
| 217 |
+
algo_info[algo]["auto"] = st.checkbox("Auto", value=True, key=f"{algo}_auto")
|
| 218 |
+
algo_info[algo]["scale"] = st.checkbox("Scale", value=True, key=f"{algo}_scale")
|
| 219 |
+
algo_info[algo]["custom_gamma_values"] = st.checkbox("Custom Gamma Values", value=True, key=f"{algo}_custom_gamma_values")
|
| 220 |
+
algo_info[algo]["tolerance"] = [st.number_input("Tolerance", min_value=0.0, max_value=1.0, value=0.001, step=0.001, key=f"{algo}_tolerance")]
|
| 221 |
+
algo_info[algo]["max_iterations"] = st.number_input("Maximum Iterations", min_value=1, max_value=100, value=10, step=1, key=f"{algo}_max_iterations")
|
| 222 |
+
if algo_info[algo]["max_iterations"]:
|
| 223 |
+
algo_info[algo]["max_iterations"] = [algo_info[algo]["max_iterations"]]
|
| 224 |
+
|
| 225 |
+
elif algo == "KNN":
|
| 226 |
+
algo_info[algo]["k_value"] = st.text_input("K Value", placeholder="Enter comma separated list of values for K Value", key=f"{algo}_k_value")
|
| 227 |
+
if algo_info[algo]["k_value"]:
|
| 228 |
+
algo_info[algo]["k_value"] = [int(x) for x in algo_info[algo]["k_value"].split(",")]
|
| 229 |
+
else:
|
| 230 |
+
algo_info[algo]["k_value"] = [78]
|
| 231 |
+
algo_info[algo]["distance_weighting"] = [st.checkbox("Distance Weighting", value=True, key=f"{algo}_distance_weighting")]
|
| 232 |
+
algo_info[algo]["neighbour_finding_algorithm"] = st.selectbox("Neighbour Finding Algorithm", ["auto", "ball_tree", "kd_tree", "brute"], key=f"{algo}_neighbour_finding_algorithm", index=0)
|
| 233 |
+
algo_info[algo]["p_value"] = st.number_input("P Value", min_value=1, max_value=2, value=1, step=1, key=f"{algo}_p_value")
|
| 234 |
+
|
| 235 |
+
elif algo == "neural_network":
|
| 236 |
+
algo_info[algo]["hidden_layer_sizes"] = st.text_input("Hidden Layer Sizes", placeholder="Enter comma separated list of values for Hidden Layer Sizes", key=f"{algo}_hidden_layer_sizes")
|
| 237 |
+
if algo_info[algo]["hidden_layer_sizes"]:
|
| 238 |
+
algo_info[algo]["hidden_layer_sizes"] = [int(x) for x in algo_info[algo]["hidden_layer_sizes"].split(",")]
|
| 239 |
+
else:
|
| 240 |
+
algo_info[algo]["hidden_layer_sizes"] = [67, 89]
|
| 241 |
+
algo_info[algo]["activation"] = ""
|
| 242 |
+
algo_info[algo]["alpha_value"] = [st.number_input("Alpha Value", min_value=0.0, max_value=1.0, value=0.01, step=0.0001, key=f"{algo}_alpha_value")]
|
| 243 |
+
algo_info[algo]["max_iterations"] = [st.number_input("Max Iterations", min_value=0, max_value=1000, value=10, step=100, key=f"{algo}_max_iterations")]
|
| 244 |
+
algo_info[algo]["convergence_tolerance"] = [st.number_input("Convergence Tolerance", min_value=0.0, max_value=1.0, value=0.1, step=0.0001, key=f"{algo}_convergence_tolerance")]
|
| 245 |
+
algo_info[algo]["early_stopping"] = [st.checkbox("Early Stopping", value=True, key=f"{algo}_early_stopping")]
|
| 246 |
+
algo_info[algo]["solver"] = [st.selectbox("Solver", ["lbfgs", "sgd", "adam"], key=f"{algo}_solver", index=2)]
|
| 247 |
+
algo_info[algo]["shuffle_data"] = [st.checkbox("Shuffle Data", value=True, key=f"{algo}_shuffle_data")]
|
| 248 |
+
algo_info[algo]["initial_learning_rate"] = [st.number_input("Initial Learning Rate", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_initial_learning_rate")]
|
| 249 |
+
algo_info[algo]["automatic_batching"] = [st.checkbox("Automatic Batching", value=True, key=f"{algo}_automatic_batching")]
|
| 250 |
+
algo_info[algo]["beta_1"] = [st.number_input("Beta 1", min_value=0.0, max_value=1.0, value=0.1, step=0.1, key=f"{algo}_beta_1")]
|
| 251 |
+
algo_info[algo]["beta_2"] = [st.number_input("Beta 2", min_value=0.0, max_value=1.0, value=0.1, step=0.1, key=f"{algo}_beta_2")]
|
| 252 |
+
algo_info[algo]["epsilon"] = [st.number_input("Epsilon", min_value=0.0, max_value=1.0, value=0.1, step=0.1, key=f"{algo}_epsilon")]
|
| 253 |
+
algo_info[algo]["power_t"] = [st.number_input("Power T", min_value=0.0, max_value=1.0, value=0.1, step=0.1, key=f"{algo}_power_t")]
|
| 254 |
+
algo_info[algo]["momentum"] = [st.number_input("Momentum", min_value=0.0, max_value=1.0, value=0.1, step=0.1, key=f"{algo}_momentum")]
|
| 255 |
+
algo_info[algo]["use_nesterov_momentum"] = [st.checkbox("Use Nesterov Momentum", value=False, key=f"{algo}_use_nesterov_momentum")]
|
| 256 |
+
|
| 257 |
+
elif algo == "xg_boost":
|
| 258 |
+
algo_info[algo]["use_gradient_boosted_tree"] = st.checkbox("Use Gradient Boosted Tree", value=True, key=f"{algo}_use_gradient_boosted_tree")
|
| 259 |
+
algo_info[algo]["dart"] = st.checkbox("DART", value=True, key=f"{algo}_dart")
|
| 260 |
+
algo_info[algo]["tree_method"] = [st.selectbox("Tree Method", ["exact", "approx", "hist"], key=f"{algo}_tree_method", index=1)]
|
| 261 |
+
algo_info[algo]["max_num_of_trees"] = [st.number_input("Max Number of Trees", min_value=0, max_value=1000, value=10, step=100, key=f"{algo}_max_num_of_trees")]
|
| 262 |
+
algo_info[algo]["early_stopping"] = st.checkbox("Early Stopping", value=True, key=f"{algo}_early_stopping")
|
| 263 |
+
if algo_info[algo]["early_stopping"]:
|
| 264 |
+
algo_info[algo]["early_stopping_rounds"] = [st.number_input("Early Stopping Rounds", min_value=0, max_value=1000, value=2, step=100, key=f"{algo}_early_stopping_rounds")]
|
| 265 |
+
algo_info[algo]["max_depth_of_tree"] = [st.number_input("Max Depth of Tree", min_value=0, max_value=1000, value=10, step=100, key=f"{algo}_max_depth_of_tree")]
|
| 266 |
+
algo_info[algo]["learningRate"] = [st.number_input("Learning Rate", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_learningRate")]
|
| 267 |
+
algo_info[algo]["l1_regularization"] = [st.number_input("L1 Regularization", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_l1_regularization")]
|
| 268 |
+
algo_info[algo]["l2_regularization"] = [st.number_input("L2 Regularization", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_l2_regularization")]
|
| 269 |
+
algo_info[algo]["gamma"] = [st.number_input("Gamma", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_gamma")]
|
| 270 |
+
algo_info[algo]["min_child_weight"] = [st.number_input("Min Child Weight", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_min_child_weight")]
|
| 271 |
+
algo_info[algo]["sub_sample"] = [st.number_input("Sub Sample", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_sub_sample")]
|
| 272 |
+
algo_info[algo]["col_sample_by_tree"] = [st.number_input("Column Sample By Tree", min_value=0.0, max_value=1.0, value=0.1, step=0.001, key=f"{algo}_col_sample_by_tree")]
|
| 273 |
+
algo_info[algo]["replace_missing_values"] = st.checkbox("Replace Missing Values", value=True, key=f"{algo}_replace_missing_values")
|
| 274 |
+
|
| 275 |
+
# Generate JSON
|
| 276 |
+
if st.button("Generate JSON and train models"):
|
| 277 |
+
session_name = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 278 |
+
json_data = generate_json(session_name, uploaded_file.name, target, train, column_info, algo_info)
|
| 279 |
+
# save json to file
|
| 280 |
+
if json_data is not None:
|
| 281 |
+
current_time = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 282 |
+
extension = "json"
|
| 283 |
+
file_name = f"uploaded_{current_time}.{extension}"
|
| 284 |
+
save_file_path = 'data/'+file_name
|
| 285 |
+
|
| 286 |
+
with open(save_file_path, 'w') as file:
|
| 287 |
+
# file.write(json_data.read())
|
| 288 |
+
json.dump(json_data, file)
|
| 289 |
+
st.success("JSON file generated successfully, models are being trained!")
|
| 290 |
+
|
| 291 |
+
train_models(save_file_path, json_data)
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def upload_json_and_train():
|
| 295 |
+
|
| 296 |
+
st.write("### Upload JSON File")
|
| 297 |
+
json_file = st.file_uploader("Upload RTF/JSON/TXT file", type=["rtf", "json", "txt"])
|
| 298 |
+
|
| 299 |
+
if json_file is not None:
|
| 300 |
+
current_time = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 301 |
+
extension = json_file.name.split('.')[-1]
|
| 302 |
+
file_name = f"{json_file.name.split('.')[0]}_{current_time}.{extension}"
|
| 303 |
+
save_file_path = 'data/'+file_name
|
| 304 |
+
|
| 305 |
+
with open(save_file_path, 'wb') as file:
|
| 306 |
+
file.write(json_file.read())
|
| 307 |
+
|
| 308 |
+
st.success("File uploaded successfully, mdoels are ready to be trained!")
|
| 309 |
+
|
| 310 |
+
# create button to train models
|
| 311 |
+
if st.button("Train Models"):
|
| 312 |
+
if json_file is not None:
|
| 313 |
+
train_models(save_file_path, json_file)
|
| 314 |
+
else:
|
| 315 |
+
st.warning("Please upload a JSON file")
|
| 316 |
+
|
| 317 |
+
def main():
|
| 318 |
+
|
| 319 |
+
#
|
| 320 |
+
main_heading = "<h1 style='text-align: center; color: #cce7ff; margin-bottom: 0; margin-top:-50px'>DataFlow Pro</h1>"
|
| 321 |
+
tagline = "<h4 style='text-align: center; color: #cce7ff; margin-top: -25px;'>Automating ML Workflow with Ease</h4>"
|
| 322 |
+
header_content = main_heading + tagline
|
| 323 |
+
st.markdown(header_content, unsafe_allow_html=True)
|
| 324 |
+
st.markdown("---")
|
| 325 |
+
|
| 326 |
+
st.subheader("Navigation")
|
| 327 |
+
st.write("If you want to create a JSON and train a model, please click on the <u><b>Create Json and Train Model</b></u> button.", unsafe_allow_html=True)
|
| 328 |
+
st.write("If you have an RTF/JSON/TXT file, please upload it and click on the <u><b>Upload Json and train model</b></u> button.", unsafe_allow_html=True)
|
| 329 |
+
page = st.radio(" ", ("Create Json and Train Model", "Upload Json and train model"), index= None)
|
| 330 |
+
|
| 331 |
+
if page == "Create Json and Train Model":
|
| 332 |
+
create_json_and_train()
|
| 333 |
+
elif page == "Upload Json and train model":
|
| 334 |
+
upload_json_and_train()
|
| 335 |
+
st.markdown("""
|
| 336 |
+
<style>
|
| 337 |
+
.footer {
|
| 338 |
+
position: fixed;
|
| 339 |
+
bottom: 0;
|
| 340 |
+
left: 0;
|
| 341 |
+
width: 100%;
|
| 342 |
+
background-color: #000000;
|
| 343 |
+
text-align: center;
|
| 344 |
+
padding: 10px 0;
|
| 345 |
+
}
|
| 346 |
+
</style>
|
| 347 |
+
<div class="footer">
|
| 348 |
+
<p>Made with ❤️ by Rupanshu Kapoor.</p>
|
| 349 |
+
</div>
|
| 350 |
+
""", unsafe_allow_html=True)
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
if __name__ == '__main__':
|
| 354 |
+
main()
|
src/__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (30.1 kB). View file
|
|
|
src/__pycache__/feature_handler.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/feature_handler.cpython-311.pyc and b/src/__pycache__/feature_handler.cpython-311.pyc differ
|
|
|
src/__pycache__/model_trainer.cpython-311.pyc
CHANGED
|
Binary files a/src/__pycache__/model_trainer.cpython-311.pyc and b/src/__pycache__/model_trainer.cpython-311.pyc differ
|
|
|
src/feature_handler.py
CHANGED
|
@@ -158,7 +158,7 @@ class FeatureHandler:
|
|
| 158 |
train_ratio = train_info["train_ratio"]
|
| 159 |
random_seed = train_info["random_seed"]
|
| 160 |
|
| 161 |
-
DATASET_PATH = "
|
| 162 |
df = pd.read_csv(DATASET_PATH)
|
| 163 |
X = df[selected_features]
|
| 164 |
Y = df[target_variable]
|
|
|
|
| 158 |
train_ratio = train_info["train_ratio"]
|
| 159 |
random_seed = train_info["random_seed"]
|
| 160 |
|
| 161 |
+
DATASET_PATH = "data/"+dataset
|
| 162 |
df = pd.read_csv(DATASET_PATH)
|
| 163 |
X = df[selected_features]
|
| 164 |
Y = df[target_variable]
|
src/model_trainer.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
import numpy as np
|
| 5 |
from sklearn.model_selection import GridSearchCV
|
| 6 |
from joblib import dump # For saving models
|
| 7 |
-
from config import model_dict
|
| 8 |
import streamlit as st
|
| 9 |
class ModelTrainer:
|
| 10 |
def __init__(self, json_content: dict):
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
from sklearn.model_selection import GridSearchCV
|
| 6 |
from joblib import dump # For saving models
|
| 7 |
+
from src.config import model_dict
|
| 8 |
import streamlit as st
|
| 9 |
class ModelTrainer:
|
| 10 |
def __init__(self, json_content: dict):
|