<jupyter_start><jupyter_text>IMPORT DATA<jupyter_code>df_wne = pd.read_csv(os.path.join("Data", "wne_test_train.csv"))
df_wne["FAT_CARB"] = df_wne["FAT"] / df_wne["CARBS"]
df_wne["FAT_PRO"] = df_wne["FAT"] / df_wne["PROTEIN"]
df_wne["PROTEIN_NEW"] = df_wne["PROTEIN_main"] * df_wne["PROTEIN"]
df_wne.head(10)
df_wne_holdout = pd.read_csv(os.path.join("Data", "wn_hldot.csv"))
df_wne_holdout["FAT_CARB"] = df_wne_holdout["FAT"] / df_wne_holdout["CARBS"]
df_wne_holdout["FAT_PRO"] = df_wne_holdout["FAT"] / df_wne_holdout["PROTEIN"]
df_wne_holdout["PROTEIN_NEW"] = (
    df_wne_holdout["PROTEIN_main"] * df_wne_holdout["PROTEIN"]
)
df_wne_holdout
X = df_wne[
    ["WINE_CLASS", "PROTEIN", "PROTEIN_main", "CALORIES", "SODIUM", "FAT_PRO"]
].values
# X = x.astype(int)
y = df_wne["WINE"].values
# y = Y.astype(int)<jupyter_output><empty_output><jupyter_text>TEST TRAIN SPLIT<jupyter_code>kf = KFold(n_splits=20, shuffle=True, random_state=1234)
kf.get_n_splits(X)

print(kf)

for train_index, test_index in kf.split(X):
    print("TRAIN:", train_index, "TEST:", test_index)
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]

# X_train, X_test, y_train, y_test = train_test_split(
#     X, y, test_size=0.175, random_state=7456
# )<jupyter_output>KFold(n_splits=20, random_state=1234, shuffle=True)
TRAIN: [  0   1   2   3   4   5   7   8   9  10  11  12  13  14  15  16  17  18
  19  20  21  22  23  24  25  26  28  30  31  32  33  34  35  36  37  38
  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56
  58  59  60  61  62  64  65  66  67  68  69  70  71  72  73  74  75  76
  77  78  79  80  81  82  83  84  85  86  87  88  89  90  92  93  94  95
  96  97  98  99 100 101 102 103 104 105 106 107 108 110 111 112 113 114
 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
 133 134 135 136 137 138 139 140 141 142 143 145 146 147 148 149 150 151] TEST: [  6  27  29  57  63  91 109 144]
TRAIN: [  0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17
  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35
  36  37  38  39  41  42  43  44  45  46  47  49  50  52  53  54  55  56
  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74
  75  76  78  80 [...]<jupyter_text>Random forest, GaussianNB, Linear Regression, Weighted RF, NN<jupyter_code># clf = MLPClassifier(
#     solver="sgd", alpha=1e-2, max_iter=500, hidden_layer_sizes=(175,), random_state=1
# )
# clf.fit(X_train, y_train)
# y_pred = clf.predict(X_test)
# print(classification_report(y_test, y_pred))

# lrr = Ridge()
# lrr.fit(X_train, y_train)
# y_pred = lrr.predict(X_test)
# print(r2_score(y_test, y_pred))

# lr_wne = LinearRegression()
# lr_wne.fit(X_train, y_train)
# y_pred = lr_wne.predict(X_test)
# print(r2_score(y_test, y_pred))

# lar_wne = Lars()
# lar_wne.fit(X_train, y_train)
# y_pred = lar_wne.predict(X_test)
# print(r2_score(y_test, y_pred))

# nbm_wne = MultinomialNB()
# nbm_wne.fit(X_train, y_train)
# y_pred = nbm_wne.predict(X_test)
# print(classification_report(y_test, y_pred))

# nb_wne = GaussianNB()
# nb_wne.fit(X_train, y_train)
# y_pred = nb_wne.predict(X_test)
# print(classification_report(y_test, y_pred))

wrf_wne = RandomForestClassifier(class_weight="balanced")
wrf_wne.fit(X_train, y_train)
y_pred = wrf_wne.predict(X_test)
print(classification_report(y_test, y_pred, zero_division="warn"))

# rf_wne = RandomForestClassifier()
# rf_wne.fit(X_train, y_train)
# y_pred = rf_wne.predict(X_test)
# print(classification_report(y_test, y_pred))
# dump(lrr, "lrr.joblib")

# dump(lr_wne, "lr_wne.joblib")

# dump(lar_wne, "lar_wne.joblib")

# dump(nb_wne, "nb_wne.joblib")

# dump(nbm_wne, "nbm_wne.joblib")

dump(wrf_wne, "wrf_wne.joblib")

# dump(rf_wne, "rf_wne.joblib")<jupyter_output><empty_output><jupyter_text>Run Model<jupyter_code>X = df_wne_holdout[
    ["WINE_CLASS", "PROTEIN", "PROTEIN_main", "CALORIES", "SODIUM", "FAT_PRO"]
].values
Y = df_wne_holdout["WINE"].values
y = Y.astype(int)
# reg = load("nb_wne.joblib")

# reg = load("nb.joblib")

# reg = load("rf_wne.joblib")

reg = load("wrf_wne.joblib")
prediction = reg.predict(X)
print(prediction)
# df_pred = pd.DataFrame(prediction)

# df_pred.head(15)
# df_pred.rename(columns={0: "Predicted Bo_Ft"})
df_wne_holdout["WINE_PRED"] = prediction.astype(int)
df_wne_holdout[["WINE", "WINE_PRED"]]
ax1 = df_wne_holdout.plot.scatter(x="WINE", y="WINE_PRED", c="DarkBlue")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13667628134013757, 'fraction_numerical': 0.11670734413135123, 'mean_word_length': 4.2602100350058345, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '496738', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2094, 'n_words': 439, 'path': '.ipynb_checkpoints/wne_pred-checkpoint.ipynb', 'repo_name': 'ssimmons9212/new_frontend', 'size': '4507'}