{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "# Automatic Differentiation\n", "\n", "### Neural Network\n", "\n", "Loss function: softmax layer in $\\mathbb{R}^3$\n", "\n", "Architecture: FC/ReLU 4-5-7-3" ], "id": "c897654e0a140cbd" }, { "metadata": { "ExecuteTime": { "end_time": "2025-03-24T15:16:27.015669Z", "start_time": "2025-03-24T15:16:23.856887Z" } }, "cell_type": "code", "source": [ "import numpy as np\n", "from sklearn.neural_network import MLPClassifier\n", "from sklearn.datasets import make_classification\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.metrics import accuracy_score\n", "\n", "accuracies = []\n", "\n", "for _ in range(10):\n", " X, y = make_classification(n_samples=1000, n_features=4, n_classes=3, n_clusters_per_class=1)\n", "\n", " X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n", " model = MLPClassifier(hidden_layer_sizes=(5, 7), activation='relu', max_iter=10000, solver='adam')\n", " model.fit(X_train, y_train)\n", "\n", " y_pred = model.predict(X_test)\n", " accuracies.append(accuracy_score(y_test, y_pred))\n", "\n", "print(f'Mean Accuracy: {np.mean(accuracies) * 100:.0f}%')\n", "print(f'STD Accuracy: {np.std(accuracies) * 100:.0f}%')\n", "print(f\"Max accuracy: {np.max(accuracies) * 100:.0f}%\")\n", "print(f\"Min accuracy: {np.min(accuracies) * 100:.0f}%\")" ], "id": "70a4eb1d928b10d0", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mean Accuracy: 94%\n", "STD Accuracy: 3%\n", "Max accuracy: 100%\n", "Min accuracy: 88%\n" ] } ], "execution_count": 33 }, { "metadata": { "ExecuteTime": { "end_time": "2025-03-24T14:37:53.507776Z", "start_time": "2025-03-24T14:37:53.505376Z" } }, "cell_type": "code", "source": "", "id": "96b6d46883ed5570", "outputs": [], "execution_count": null } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }