<jupyter_start><jupyter_text>Segmentez des clients d'un site de e-commerce==========================================![logo](https://olist.com/wp-content/uploads/2018/04/Logo-01.png)<jupyter_code>import os
from pathlib import Path
from datetime import datetime

import matplotlib
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from ipywidgets import widgets, interact
from IPython.display import display

from src.features.build_features import load_data, make_dataset
from src.visualization.visualize import piechart, distplot

sns.set(font_scale=1.5)<jupyter_output><empty_output><jupyter_text>Chargement des données<jupyter_code># Use personal function from src
data = load_data(Path('../data/raw').resolve())
# Load all data
customers = make_dataset(data, '1970-01-01', '2020-01-01')<jupyter_output><empty_output><jupyter_text>Analyse des données<jupyter_code>customers.describe()<jupyter_output><empty_output><jupyter_text>Fréquence<jupyter_code>piechart(customers['frequency'].apply(
    lambda x: 'unique' if x == 1 else 'régulier'))<jupyter_output><empty_output><jupyter_text>Nombre d'articles par panier<jupyter_code>piechart(customers['item_per_c'].apply(lambda x: 1 if x == 1 else '1+'))<jupyter_output><empty_output><jupyter_text>Récence<jupyter_code>distplot(customers['recency'], kde=False, norm_hist=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Monetary<jupyter_code>distplot(customers['monetary'], kde=False, norm_hist=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Review score<jupyter_code>f, ax = plt.subplots(1, figsize=(8, 6))
ax.hist(customers['review_score'], range=(0, 5), bins=5)
ax.set_xticks([x for x in range(1, 6)])
plt.xlim(1, 5)
plt.show()<jupyter_output><empty_output><jupyter_text>Catégories<jupyter_code>categs = ['clothing', 'hobbies', 'high-tech', 'home', 'other']
cat_count = customers[categs].astype(bool).sum()
_, ax = plt.subplots(1, figsize=(8, 8))
ax.pie(cat_count.values, labels=cat_count.index, autopct='%1.1f%%')
plt.show()
cat_count.sort_values(inplace=True)
plt.barh(y=cat_count.index, width=cat_count.values)
revenues_repartition = customers[categs].sum()
_, ax = plt.subplots(1, figsize=(8, 8))
ax.pie(revenues_repartition.values,
       labels=revenues_repartition.index, autopct='%1.1f%%')
plt.show()<jupyter_output><empty_output><jupyter_text>Dataset pour segmentation<jupyter_code>customers = make_dataset(data, '2017-01-01', '2018-01-01')
customers.to_csv('../data/processed/dataset.csv', index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16266246553761324, 'fraction_numerical': 0.02599448601811737, 'mean_word_length': 9.452674897119342, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '42546', 'license': 'MIT', 'n_tokens_mistral': 1010, 'n_tokens_neox': 954, 'n_words': 145, 'path': 'notebooks/1.0-tg-initial-data-explo.py.ipynb', 'repo_name': 'tgrandjean/OC-Olist', 'size': '2539'}