{ "metadata": { "kernelspec": { "name": "python", "display_name": "Python (Pyodide)", "language": "python" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8" } }, "nbformat_minor": 5, "nbformat": 4, "cells": [ { "id": "d4cec5b7-5725-44d3-bfb7-04278fdf9bb4", "cell_type": "code", "source": "import pandas as pd\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.metrics import accuracy_score, confusion_matrix", "metadata": { "trusted": true }, "outputs": [], "execution_count": 2 }, { "id": "0e3d0d27-300b-4152-96e0-70ff1fbab83a", "cell_type": "code", "source": "data = pd.read_csv(\"Churn_Modelling.csv\")", "metadata": { "trusted": true }, "outputs": [], "execution_count": 3 }, { "id": "06fd9a81-ed4d-4796-bc38-e0c68fe1dc3e", "cell_type": "code", "source": "X = data.iloc[:, 3:13] # Features from CreditScore to EstimatedSalary\ny = data.iloc[:, 13] ", "metadata": { "trusted": true }, "outputs": [], "execution_count": 4 }, { "id": "90c9c5aa-0b8a-424b-a625-ff4fc2d73380", "cell_type": "code", "source": "le = LabelEncoder()\nX[\"Gender\"] = le.fit_transform(X[\"Gender\"])\nX = pd.get_dummies(X, columns=[\"Geography\"], drop_first=True)", "metadata": { "trusted": true }, "outputs": [], "execution_count": 5 }, { "id": "4b0ecfe6-7245-4866-a842-e422c5658928", "cell_type": "code", "source": "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)", "metadata": { "trusted": true }, "outputs": [], "execution_count": 6 }, { "id": "55cd9306-83f0-4ea6-8399-278444f3e839", "cell_type": "code", "source": "scaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)", "metadata": { "trusted": true }, "outputs": [], "execution_count": 7 }, { "id": "60cdf8fb-c656-4a24-a120-de0c4c9abf94", "cell_type": "code", "source": "model = MLPClassifier(hidden_layer_sizes=(10, 10), # two hidden layers\n activation='relu',\n solver='adam',\n max_iter=300,\n random_state=42)", "metadata": { "trusted": true }, "outputs": [], "execution_count": 8 }, { "id": "566bf1ad-0836-4ba4-9a48-68554a7b9bf7", "cell_type": "code", "source": "model.fit(X_train, y_train)", "metadata": { "trusted": true }, "outputs": [ { "execution_count": 9, "output_type": "execute_result", "data": { "text/plain": "MLPClassifier(hidden_layer_sizes=(10, 10), max_iter=300, random_state=42)", "text/html": "
MLPClassifier(hidden_layer_sizes=(10, 10), max_iter=300, random_state=42)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" }, "metadata": {} } ], "execution_count": 9 }, { "id": "5bfab65c-8310-4e57-b129-cc46f5f875c0", "cell_type": "code", "source": "y_pred = model.predict(X_test)", "metadata": { "trusted": true }, "outputs": [], "execution_count": 10 }, { "id": "fb318e31-6e59-4fc2-af8f-1de050e4d64c", "cell_type": "code", "source": "accuracy = accuracy_score(y_test, y_pred)\nconf_matrix = confusion_matrix(y_test, y_pred)\nprint(\"Accuracy:\", round(accuracy * 100, 2), \"%\")\nprint(\"Confusion Matrix:\\n\", conf_matrix)", "metadata": { "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": "Accuracy: 86.45 %\nConfusion Matrix:\n [[1543 64]\n [ 207 186]]\n" } ], "execution_count": 11 }, { "id": "89d3749a-40be-4fba-a5b3-f19b15b20ccc", "cell_type": "code", "source": "", "metadata": { "trusted": true }, "outputs": [], "execution_count": null } ] }