MediaMixOptimization / constants.py
samkeet's picture
Upload 40 files
00b00eb verified
###########################################################################################################
# Default
###########################################################################################################
import pandas as pd
from collections import OrderedDict
# default_dct
default_dct = {
"data_import": {
"gold_layer_df": pd.DataFrame(),
"granularity_selection": "daily",
"dashboard_df": None,
"tool_df": None,
"unique_panels": [],
"imputation_df": None,
"imputed_tool_df": None,
"group_dict": {},
"category_dict": {},
},
"data_validation": {
"target_column": 0,
"selected_panels": None,
"selected_feature": 0,
"validated_variables": [],
"Non_media_variables": 0,
"correlation": [],
},
"transformations": {
"final_df": None,
"summary_string": None,
"Media": {},
"Exogenous": {},
"Internal": {},
"Specific": {},
"correlation_plot_selection": [],
},
"model_build": {
"sel_target_col": None,
"all_iters_check": False,
"iterations": 0,
"build_button": False,
"show_results_check": False,
"session_state_saved": {},
},
"model_tuning": {
"sel_target_col": None,
"sel_model": {},
"flag_expander": False,
"start_date_default": None,
"end_date_default": None,
"repeat_default": "No",
"flags": {},
"select_all_flags_check": {},
"selected_flags": {},
"trend_check": False,
"week_num_check": False,
"sine_cosine_check": False,
"session_state_saved": {},
},
"saved_model_results": {
"selected_options": None,
"model_grid_sel": [1],
},
"current_media_performance": {
"model_outputs": {},
},
"media_performance": {"start_date": None, "end_date": None},
"response_curves": {
"original_metadata_file": None,
"modified_metadata_file": None,
},
"scenario_planner": {
"original_metadata_file": None,
"modified_metadata_file": None,
},
"saved_scenarios": {"saved_scenarios_dict": OrderedDict()},
"optimized_result_analysis": {
"selected_scenario_selectbox_visualize": 0,
"metric_selectbox_visualize": 0,
},
}
###########################################################################################################
# Data Import
###########################################################################################################
# Constants Data Import
upload_rows_limit = 1000000 # Maximum number of rows allowed for upload
upload_column_limit = 1000 # Maximum number of columns allowed for upload
word_length_limit_lower = 2 # Minimum allowed length for words
word_length_limit_upper = 100 # Maximum allowed length for words
minimum_percent_overlap = (
1 # Minimum required percentage of overlap with the reference data
)
minimum_row_req = 30 # Minimum number of rows required
percent_drop_col_threshold = 50 # Percentage threshold above which columns are automatically categorized for drop imputation
###########################################################################################################
# Transfromations
###########################################################################################################
# Constants Transformations
predefined_defaults = {
"Lag": (1, 2),
"Lead": (1, 2),
"Moving Average": (1, 2),
"Saturation": (10, 20),
"Power": (2, 4),
"Adstock": (0.5, 0.7),
} # Pre-defined default values of every transformation
# Transfromations min, max and step
lead_min_value = 1
lead_max_value = 10
lead_step = 1
lag_min_value = 1
lag_max_value = 10
lag_step = 1
moving_average_min_value = 1
moving_average_max_value = 10
moving_average_step = 1
saturation_min_value = 0
saturation_max_value = 100
saturation_step = 1
power_min_value = 1
power_max_value = 5
power_step = 1
adstock_min_value = 0.0
adstock_max_value = 1.0
adstock_step = 0.05
display_max_col = 500 # Maximum columns to display
###########################################################################################################
# Model Build
###########################################################################################################
MAX_COMBINATIONS = 50000 # Max number of model combinations possible
MIN_MODEL_NAME_LENGTH = 0 # model can only be saved if len(model_name) is greater than this value
MIN_P_VALUE_THRESHOLD = 0.06 # coefficients with p values less than this value are considered valid
MODEL_POS_COEFF_RATIO_THRESHOLD = 0 # ratio of positive coefficients/total coefficients for model validity
MODEL_P_VALUE_RATIO_THRESHOLD = 0 # ratio of coefficients with p value/total coefficients for model validity
MAX_TOP_FEATURES = 5 # max number of top features selected per variable
MAX_NUM_FILTERS = 10 # maximum number of filters allowed
DEFAULT_FILTER_VALUE = 0.0 # default value of a new filter
VIF_LOW_THRESHOLD = 3 # Threshold for VIF to be colored green
VIF_HIGH_THRESHOLD = 10 # Threshold for VIF to be colored red
DEFAULT_TRAIN_RATIO = 3/4 # default train set ratio (75%)
###########################################################################################################
# Model Tuning
###########################################################################################################
import numpy as np
NUM_FLAG_COLS_TO_DISPLAY = 4 # Number of columns to be created on UI to display flags
HALF_YEAR_THRESHOLD = 6 # Threshold of months to create quarter frequency sine-cosine waves
FULL_YEAR_THRESHOLD = 12 # Threshold of months to create quarter annual sine-cosine waves
TREND_MIN = 5 # Starting value of trend line
ANNUAL_FREQUENCY = 2 * np.pi / 365 # annual frequency
QTR_FREQUENCY_FACTOR = 4 # multiplication factor to get quarterly frequency
HALF_YEARLY_FREQUENCY_FACTOR = 2 # multiplication factor to get semi-annual frequency
###########################################################################################################
# Scenario Planner
###########################################################################################################
# Constants Scenario Planner
xtol_tolerance_per = 1 # Percenatge of tolerance
mroi_threshold = 0.05 # mROI threshold
word_length_limit_lower = 2 # Minimum allowed length for words
word_length_limit_upper = 100 # Maximum allowed length for words
###########################################################################################################
# PPT utils
###########################################################################################################
TITLE_FONT_SIZE = 20
AXIS_LABEL_FONT_SIZE = 8
CHART_TITLE_FONT_SIZE = 14
AXIS_TITLE_FONT_SIZE = 12
DATA_LABEL_FONT_SIZE = 8
LEGEND_FONT_SIZE = 10
PIE_LEGEND_FONT_SIZE = 7
###########################################################################################################
# Page Name
###########################################################################################################