<jupyter_start><jupyter_text>Load data<jupyter_code>df_train = pd.read_csv("data/train.csv", sep=";")
df_test = pd.read_csv("data/test.csv", sep=";")
print(df_train.shape)
print(df_test.shape)
df_train.dtypes
df_train.head()
df_train.isna().sum()
df_train = df_train.dropna()
df_train.isna().sum()<jupyter_output><empty_output><jupyter_text>Transform features One-hot-encoding:<jupyter_code>df_train = pd.get_dummies(df_train, columns = ["customerType"])
df_train.head()<jupyter_output><empty_output><jupyter_text>Basket transformation:<jupyter_code>df_train['c_0'] = df_train.basket.map(lambda x: x.count("0"))
df_train['c_1'] = df_train.basket.map(lambda x: x.count("1"))
df_train['c_2'] = df_train.basket.map(lambda x: x.count("2"))
df_train['c_3'] = df_train.basket.map(lambda x: x.count("3"))
df_train['c_4'] = df_train.basket.map(lambda x: x.count("4"))
df_train['c_5'] = df_train.basket.map(lambda x: x.count("5"))
df_train.head(3)
X_train = df_train[["totalAmount","customerType_existing", "customerType_new", "c_0","c_1","c_2","c_3","c_4","c_5"]]
y_train = df_train["returnLabel"]<jupyter_output><empty_output><jupyter_text>Model training<jupyter_code>gbt = GradientBoostingClassifier(random_state=0)
gbt.fit(X_train, y_train)
logReg = LogisticRegression(max_iter=1000, solver="liblinear")
logReg.fit(X_train, y_train)
rf = RandomForestClassifier(random_state=0)
rf.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>6. Evaluation<jupyter_code>df_test = df_test.dropna()
df_test = pd.get_dummies(df_test, columns=["customerType"])
df_test['c_0'] = df_test.basket.map(lambda x: x.count("0"))
df_test['c_1'] = df_test.basket.map(lambda x: x.count("1"))
df_test['c_2'] = df_test.basket.map(lambda x: x.count("2"))
df_test['c_3'] = df_test.basket.map(lambda x: x.count("3"))
df_test['c_4'] = df_test.basket.map(lambda x: x.count("4"))
df_test['c_5'] = df_test.basket.map(lambda x: x.count("5"))
df_test.head(3)
X_test = df_test[["totalAmount","customerType_existing", "customerType_new", "c_0","c_1","c_2","c_3","c_4","c_5"]]
y_test = df_test["returnLabel"]
def evaluate(model, X, y):
    predictions = model.predict(X)
    print(f" == Performance {model} == ")
    print("Accuracy score is:" + str(accuracy_score(y, predictions)))
    print("Recall is:"+ str(recall_score(y, predictions)))
    print("Precision is:" + str(precision_score(y, predictions)))
    print("\n")
evaluate(logReg, X_test, y_test)
evaluate(gbt, X_test, y_test)
evaluate(rf, X_test, y_test)
evaluate(logReg, X_train, y_train)
evaluate(gbt, X_train, y_train)
evaluate(rf, X_train, y_train)<jupyter_output>== Performance LogisticRegression(max_iter=1000, solver='liblinear') == 
Accuracy score is:0.8791883842144452
Recall is:0.7560632138945392
Precision is:0.8233089112284887


 == Performance GradientBoostingClassifier(random_state=0) == 
Accuracy score is:0.8832836932241251
Recall is:0.7768737286809576
Precision is:0.8210682983297503


 == Performance RandomForestClassifier(random_state=0) == 
Accuracy score is:0.9631887565152644
Recall is:0.9244249726177437
Precision is:0.9504504504504504
{'fraction_non_alphanumeric': 0.1728714794431855, 'fraction_numerical': 0.0660407898996439, 'mean_word_length': 8.840764331210192, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '285290', 'license': 'MIT', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1255, 'n_words': 170, 'path': 'Day_3_AppliedML/Solution_Coding_Task.ipynb', 'repo_name': 'keuperj/ki-sommer', 'size': '3089'}