<jupyter_start><jupyter_text>0.2 Parameters<jupyter_code># Sample data set parameters
num_clients = 100
timeframe = '2016-01-01', '2019-01-01'
num_products = 3
num_transactions = 100
avg_sale = 1000 # USD

# RFM analysis
alpha = [0.3,0.3,0.2,0.2]
n_groups = 5<jupyter_output><empty_output><jupyter_text>1. Data creation This section simulates a sample data set<jupyter_code>data = create_random_data_set(timeframe, num_clients, num_transactions, num_products, avg_sale)
data.head()<jupyter_output><empty_output><jupyter_text>2. Performing RFM analysis<jupyter_code>scores = create_scores(data,n_groups,alpha)
scores.head()
scores = assign_segment(scores)
scores.head()
other_vars = create_other_vars(data)
other_vars.head()<jupyter_output><empty_output><jupyter_text>50. All in one run<jupyter_code>out_table = run_RFM_analysis(data,n_groups,alpha)
out_table.head()
out_table[['score','client_id','tenure','last_purchase','months_since_last','sales','segment']].head()<jupyter_output><empty_output><jupyter_text>80. For Dash<jupyter_code>table_3 = scores.groupby('segment').median()[['recency_value','frequency_value','monetary_value']].reset_index()
table_3
data = dict(
    [
        ("Date", ["2015-01-01", "2015-10-24", "2016-05-10", "2017-01-10", "2018-05-10", "2018-08-15"]),
        ("Region", ["Montreal", "Toronto", "New York City", "Miami", "San Francisco", "London"]),
        ("Temperature", [1, -20, 3.512, 4, 10423, -441.2]),
        ("Humidity", [10, 20, 30, 40, 50, 60]),
        ("Pressure", [2, 10924, 3912, -10, 3591.2, 15]),
    ]
)

df = pd.DataFrame(data)
out_table.head()
df<jupyter_output><empty_output><jupyter_text>99. TODO<jupyter_code># remainig to cut extreme values<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1698550724637681, 'fraction_numerical': 0.08347826086956522, 'mean_word_length': 6.705357142857143, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '325095', 'license': 'MIT', 'n_tokens_mistral': 767, 'n_tokens_neox': 663, 'n_words': 111, 'path': 'apps/dash-sales/notebooks/.ipynb_checkpoints/prototype-checkpoint.ipynb', 'repo_name': 'Torroledo/platform-apps', 'size': '1725'}