<jupyter_start><jupyter_text>Import Data modified from source: https://www.kaggle.com/uciml/pima-indians-diabetes-database<jupyter_code>df = pd.read_csv("data/diabetes.csv")
df.head()
plot_missing_value(df)
df.Outcome.value_counts()<jupyter_output><empty_output><jupyter_text>Dataset Splitting<jupyter_code>X = df.drop(columns="Outcome")
y = df.Outcome

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
X_train.shape, X_test.shape, y_train.shape, y_test.shape<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>df.head()
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import GridSearchCV
from jcopml.tuning import grid_search_params as gsp
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(), ["Pregnancies", "Glucose", "BloodPressure", "SkinThickness", 
                             "Insulin", "BMI", "DiabetesPedigreeFunction", "Age"])
])

pipeline = Pipeline([
    ('prep', preprocessor),
    ('mlp', MLPClassifier(random_state=42))
])

parameter = {
    "mlp__alpha": [0.0001, 0.0003, 0.001, 0.003],
    "mlp__hidden_layer_sizes": [(16,), (32, 16), (32, 16, 8)],
    "mlp__learning_rate_init": [0.001, 0.005, 0.01],
    "mlp__activation": ["relu", "logistic", "tanh"]
}

model = GridSearchCV(pipeline, parameter, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))<jupyter_output>Fitting 3 folds for each of 108 candidates, totalling 324 fits<jupyter_text>Feature Importance<jupyter_code>df_imp = mean_score_decrease(X_train, y_train, model, plot=True)
preprocessor = ColumnTransformer([
    ('numeric', num_pipe(poly=2, transform='box-cox'), ["Glucose", "BMI", "SkinThickness"])
])

pipeline = Pipeline([
    ('prep', preprocessor),
    ('mlp', MLPClassifier(random_state=42))
])

parameter = {
    "mlp__alpha": [0.0001, 0.0003, 0.001, 0.003],
    "mlp__hidden_layer_sizes": [(16,), (32, 16), (32, 16, 8)],
    "mlp__learning_rate_init": [0.001, 0.005, 0.01],
    "mlp__activation": ["relu", "logistic", "tanh"]
}

model = GridSearchCV(pipeline, parameter, cv=3, n_jobs=-1, verbose=1)
model.fit(X_train, y_train)

print(model.best_params_)
print(model.score(X_train, y_train), model.best_score_, model.score(X_test, y_test))<jupyter_output>Fitting 3 folds for each of 108 candidates, totalling 324 fits
{'fraction_non_alphanumeric': 0.15871710526315788, 'fraction_numerical': 0.04481907894736842, 'mean_word_length': 6.2195845697329375, 'pattern_counts': {'":': 8, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '362291', 'license': 'MIT', 'n_tokens_mistral': 1027, 'n_tokens_neox': 926, 'n_words': 168, 'path': '13 - Neural Network/Part 2 - (Opsional) Neural Network with Scikit-learn.ipynb', 'repo_name': 'WiraDKP/deep_learning', 'size': '2432'}