<jupyter_start><jupyter_text>Our first goal is formattting the data as events.It's already listed by date, but we need to add binary indicators for the person and the product.<jupyter_code>df = pd.get_dummies(df)
df.shape<jupyter_output><empty_output><jupyter_text>Now, let's see if that fits into a SageMaker model right awayOnce we know we have the mechanics working, we can iterate on putting new sets of features and hyperparameters into the model to find the best one SageMaker's built-in recommender handles only binary classification and regression tasks. Which means that we'll need to either create a binary classifier for each class, or will need to convert the product indicators to a continuous outcome, and then map the continuous outcome to a discrete product.This isn't exactly ideal; what we'd like is a multi-class classifier. Start with this approach for Factorization Machines, because it does so well with sparse datasets at scale. Eventually move into exploring XGBoost and Linear Learner, treating the problem as a multi-class classification problem.If you really want to challenge yourself, you can select another open source recommender algorithm, and load it into a Docker container for training. Using a scikit learn estimator should be somewhat easier, because you can just use the AWS-managed container rather than building your own.  Convert product bins into continuous numbers to see the task as regression Let's give each product a 10-digit space, so the space between them is large enough for the model to capture. First we'll need to get a list of all 23 products.<jupyter_code>headers = list(df)
products = [h for h in headers if "_ult1" in h]
print (len(products))
products
product_dict = {}

for idx, product in enumerate(products):
    value = idx * 10
    product_dict[product] = value
product_dict
def grab_row_header(idx, start, headers):
    return headers[idx+start]

headers = list(df)

df["outcome"] = [0.0 for i in range(df.shape[0])]

for i in df.index:
    
    start = 9
    
    end = start + 24
    
    row = df.loc[i][start:end]
    
    for idx, each in enumerate(row):
        if each == 1.0:
            
            # grab the row header
            h = grab_row_header(idx, start, headers)
            
            # grab the discrete value
            val = product_dict[h]
            
            # set the discrete value in the dataframe 
            df.set_value(i, "outcome", val)

df["outcome"].value_counts()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06070287539936102, 'fraction_numerical': 0.0059904153354632585, 'mean_word_length': 3.596330275229358, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '170248', 'license': 'MIT', 'n_tokens_mistral': 691, 'n_tokens_neox': 655, 'n_words': 326, 'path': 'Starter-Code/.ipynb_checkpoints/Santander Recommender Starter Notebook-checkpoint.ipynb', 'repo_name': 'mahoneyxp/amazon-sagemaker-architecting-for-ml', 'size': '2504'}