Skip to content

Commit

Permalink
feat: i don't even remember what i've added
Browse files Browse the repository at this point in the history
  • Loading branch information
marcpinet committed Apr 24, 2024
1 parent d1918a8 commit 3c1dd20
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 265 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Dist generator
dist_gen.bat

# Datasets formats
*.csv
*.npz
Expand Down
52 changes: 26 additions & 26 deletions examples/classification-regression/mnist_loading_saved_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:21.706906Z",
"start_time": "2024-04-21T12:52:18.726598200Z"
"end_time": "2024-04-23T23:32:44.879695500Z",
"start_time": "2024-04-23T23:32:41.806868Z"
}
},
"outputs": [],
Expand All @@ -47,8 +47,8 @@
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:21.915810200Z",
"start_time": "2024-04-21T12:52:21.706906Z"
"end_time": "2024-04-23T23:32:45.056739600Z",
"start_time": "2024-04-23T23:32:44.879695500Z"
}
},
"outputs": [],
Expand All @@ -68,8 +68,8 @@
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:22.072282500Z",
"start_time": "2024-04-21T12:52:21.916810900Z"
"end_time": "2024-04-23T23:32:45.166846Z",
"start_time": "2024-04-23T23:32:45.059739600Z"
}
},
"outputs": [],
Expand All @@ -92,8 +92,8 @@
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:22.233389700Z",
"start_time": "2024-04-21T12:52:22.073284800Z"
"end_time": "2024-04-23T23:32:45.285935300Z",
"start_time": "2024-04-23T23:32:45.167845600Z"
}
},
"outputs": [],
Expand All @@ -113,8 +113,8 @@
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:22.258467800Z",
"start_time": "2024-04-21T12:52:22.234388100Z"
"end_time": "2024-04-23T23:32:45.329886Z",
"start_time": "2024-04-23T23:32:45.288843800Z"
}
},
"outputs": [],
Expand All @@ -134,16 +134,16 @@
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:22.323518700Z",
"start_time": "2024-04-21T12:52:22.257467100Z"
"end_time": "2024-04-23T23:32:45.374527900Z",
"start_time": "2024-04-23T23:32:45.314964200Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Validation Accuracy: 0.899\n"
"Validation Accuracy: 0.9738333333333333\n"
]
}
],
Expand All @@ -165,27 +165,27 @@
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T12:52:22.393768500Z",
"start_time": "2024-04-21T12:52:22.318518600Z"
"end_time": "2024-04-23T23:32:45.444303500Z",
"start_time": "2024-04-23T23:32:45.375529400Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test Accuracy: 0.8863\n",
"Test Accuracy: 0.9549\n",
"Confusion Matrix:\n",
"[[ 937 0 0 1 11 7 2 18 1 3]\n",
" [ 0 1097 3 4 0 3 2 4 19 3]\n",
" [ 13 9 858 36 26 1 23 38 16 12]\n",
" [ 8 6 18 899 2 33 2 16 12 14]\n",
" [ 1 0 1 0 944 0 7 2 1 26]\n",
" [ 19 0 0 82 30 701 12 5 23 20]\n",
" [ 18 2 0 0 70 15 849 1 2 1]\n",
" [ 0 9 10 5 15 0 0 945 4 40]\n",
" [ 6 22 3 3 37 26 9 2 803 63]\n",
" [ 3 2 1 11 137 2 0 15 8 830]]\n"
"[[ 958 0 3 0 0 3 7 2 4 3]\n",
" [ 0 1117 1 6 0 1 1 2 6 1]\n",
" [ 5 1 983 11 3 0 4 16 9 0]\n",
" [ 2 0 10 959 0 13 1 7 8 10]\n",
" [ 2 1 6 0 909 0 6 0 0 58]\n",
" [ 9 1 0 20 0 838 8 2 3 11]\n",
" [ 10 4 4 1 5 6 917 0 10 1]\n",
" [ 1 8 10 6 0 0 0 982 0 21]\n",
" [ 5 3 9 7 4 6 5 7 917 11]\n",
" [ 3 5 3 5 10 4 2 7 1 969]]\n"
]
}
],
Expand Down
139 changes: 38 additions & 101 deletions examples/classification-regression/simple_cancer_binary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.026361300Z",
"start_time": "2024-04-21T13:22:52.339942200Z"
"end_time": "2024-04-23T22:56:24.052135200Z",
"start_time": "2024-04-23T22:56:22.927958200Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -51,8 +51,8 @@
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.040903100Z",
"start_time": "2024-04-21T13:22:53.026361300Z"
"end_time": "2024-04-23T22:56:24.066137600Z",
"start_time": "2024-04-23T22:56:24.046136900Z"
}
},
"outputs": [],
Expand All @@ -73,8 +73,8 @@
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.054442700Z",
"start_time": "2024-04-21T13:22:53.042408400Z"
"end_time": "2024-04-23T22:56:24.079136500Z",
"start_time": "2024-04-23T22:56:24.063137500Z"
}
},
"outputs": [],
Expand All @@ -99,11 +99,24 @@
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.059957800Z",
"start_time": "2024-04-21T13:22:53.048922300Z"
"end_time": "2024-04-23T22:56:24.340700300Z",
"start_time": "2024-04-23T22:56:24.073137200Z"
}
},
"outputs": [],
"outputs": [
{
"ename": "ValueError",
"evalue": "The first layer must be an Input layer.",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mValueError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[4], line 8\u001B[0m\n\u001B[0;32m 6\u001B[0m model \u001B[38;5;241m=\u001B[39m Model()\n\u001B[0;32m 7\u001B[0m model\u001B[38;5;241m.\u001B[39madd(Input(input_neurons))\n\u001B[1;32m----> 8\u001B[0m \u001B[43mmodel\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43madd\u001B[49m\u001B[43m(\u001B[49m\u001B[43mDense\u001B[49m\u001B[43m(\u001B[49m\u001B[43mhidden_neurons\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mweights_init\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mhe\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mrandom_state\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;241;43m42\u001B[39;49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 9\u001B[0m model\u001B[38;5;241m.\u001B[39madd(Activation(ReLU()))\n\u001B[0;32m 11\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m _ \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mrange\u001B[39m(num_hidden_layers \u001B[38;5;241m-\u001B[39m \u001B[38;5;241m1\u001B[39m):\n",
"File \u001B[1;32m~\\Documents\\Programming\\Python\\Handmade NeuralNetwork\\neuralnetlib\\model.py:38\u001B[0m, in \u001B[0;36mModel.add\u001B[1;34m(self, layer)\u001B[0m\n\u001B[0;32m 36\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mlayers:\n\u001B[0;32m 37\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(layer, Input):\n\u001B[1;32m---> 38\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe first layer must be an Input layer.\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m 39\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m 40\u001B[0m previous_layer \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mlayers[\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m1\u001B[39m]\n",
"\u001B[1;31mValueError\u001B[0m: The first layer must be an Input layer."
]
}
],
"source": [
"input_neurons = x_train.shape[1:][0] # Cancer dataset has 30 features\n",
"num_hidden_layers = 5 # Number of hidden layers\n",
Expand Down Expand Up @@ -132,40 +145,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.085516700Z",
"start_time": "2024-04-21T13:22:53.058950900Z"
"end_time": "2024-04-23T22:56:24.356216400Z",
"start_time": "2024-04-23T22:56:24.343207100Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model\n",
"-------------------------------------------------\n",
"Layer 1: Input(input_shape=(30,))\n",
"Layer 2: Dense(units=100)\n",
"Layer 3: Activation(ReLU)\n",
"Layer 4: Dense(units=100)\n",
"Layer 5: Activation(ReLU)\n",
"Layer 6: Dense(units=100)\n",
"Layer 7: Activation(ReLU)\n",
"Layer 8: Dense(units=100)\n",
"Layer 9: Activation(ReLU)\n",
"Layer 10: Dense(units=100)\n",
"Layer 11: Activation(ReLU)\n",
"Layer 12: Dense(units=1)\n",
"Layer 13: Activation(Sigmoid)\n",
"-------------------------------------------------\n",
"Loss function: BinaryCrossentropy\n",
"Optimizer: Adam(learning_rate=0.0001, beta_1=0.9, beta_2=0.999, epsilon=1e-08)\n",
"-------------------------------------------------\n"
]
}
],
"outputs": [],
"source": [
"model.compile(loss_function=BinaryCrossentropy(), optimizer=Adam(learning_rate=0.0001))\n",
"\n",
Expand All @@ -181,43 +168,15 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.842873Z",
"start_time": "2024-04-21T13:22:53.081003300Z"
"start_time": "2024-04-23T22:56:24.345216800Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[==============================] 100% Epoch 1/20 - loss: 0.6860 - accuracy_score: 0.6308 - 0.04s\n",
"[==============================] 100% Epoch 2/20 - loss: 0.6677 - accuracy_score: 0.7055 - 0.03s\n",
"[==============================] 100% Epoch 3/20 - loss: 0.6323 - accuracy_score: 0.8066 - 0.04s\n",
"[==============================] 100% Epoch 4/20 - loss: 0.5702 - accuracy_score: 0.8901 - 0.05s\n",
"[==============================] 100% Epoch 5/20 - loss: 0.4731 - accuracy_score: 0.9143 - 0.05s\n",
"[==============================] 100% Epoch 6/20 - loss: 0.3540 - accuracy_score: 0.9297 - 0.04s\n",
"[==============================] 100% Epoch 7/20 - loss: 0.2499 - accuracy_score: 0.9429 - 0.04s\n",
"[==============================] 100% Epoch 8/20 - loss: 0.1816 - accuracy_score: 0.9473 - 0.04s\n",
"[==============================] 100% Epoch 9/20 - loss: 0.1418 - accuracy_score: 0.9648 - 0.05s\n",
"[==============================] 100% Epoch 10/20 - loss: 0.1182 - accuracy_score: 0.9714 - 0.04s\n",
"[==============================] 100% Epoch 11/20 - loss: 0.1034 - accuracy_score: 0.9758 - 0.03s\n",
"[==============================] 100% Epoch 12/20 - loss: 0.0927 - accuracy_score: 0.9758 - 0.03s\n",
"[==============================] 100% Epoch 13/20 - loss: 0.0844 - accuracy_score: 0.9802 - 0.03s\n",
"[==============================] 100% Epoch 14/20 - loss: 0.0777 - accuracy_score: 0.9802 - 0.03s\n",
"[==============================] 100% Epoch 15/20 - loss: 0.0722 - accuracy_score: 0.9824 - 0.03s\n",
"[==============================] 100% Epoch 16/20 - loss: 0.0675 - accuracy_score: 0.9846 - 0.03s\n",
"[==============================] 100% Epoch 17/20 - loss: 0.0635 - accuracy_score: 0.9890 - 0.03s\n",
"[==============================] 100% Epoch 18/20 - loss: 0.0600 - accuracy_score: 0.9890 - 0.03s\n",
"[==============================] 100% Epoch 19/20 - loss: 0.0569 - accuracy_score: 0.9890 - 0.04s\n",
"[==============================] 100% Epoch 20/20 - loss: 0.0542 - accuracy_score: 0.9912 - 0.03s\n"
]
}
],
"outputs": [],
"source": [
"model.train(x_train, y_train, epochs=20, batch_size=48, metrics=[accuracy_score], random_state=42)"
"model.fit(x_train, y_train, epochs=20, batch_size=48, metrics=[accuracy_score], random_state=42)"
]
},
{
Expand All @@ -229,22 +188,13 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.857412200Z",
"start_time": "2024-04-21T13:22:53.843829400Z"
"start_time": "2024-04-23T22:56:24.347215800Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Test loss: 0.06351246680217817\n"
]
}
],
"outputs": [],
"source": [
"loss = model.evaluate(x_test, y_test)\n",
"print(f'Test loss: {loss}')"
Expand All @@ -259,11 +209,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.863439400Z",
"start_time": "2024-04-21T13:22:53.852402800Z"
"start_time": "2024-04-23T22:56:24.348216100Z"
}
},
"outputs": [],
Expand All @@ -280,25 +229,13 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2024-04-21T13:22:53.873465Z",
"start_time": "2024-04-21T13:22:53.859930800Z"
"start_time": "2024-04-23T22:56:24.350216700Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.9736842105263158\n",
"Precision: 0.9741062479117941\n",
"Recall: 0.9692460317460317\n",
"F1 Score: 0.9716700622635057\n"
]
}
],
"outputs": [],
"source": [
"accuracy = accuracy_score(y_pred, y_test)\n",
"precision = precision_score(y_pred, y_test)\n",
Expand Down
Loading

0 comments on commit 3c1dd20

Please sign in to comment.