iui-group-l-name-zensiert/1-first-project/tdt/Hyperparameter.ipynb

791 lines
28 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "eceea5a5",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e6920b4c",
"metadata": {},
"outputs": [],
"source": [
"delim = ';'\n",
"\n",
"base_path = '/opt/iui-datarelease1-sose2021/'\n",
"\n",
"Xpickle_file = './X.pickle'\n",
"\n",
"ypickle_file = './y.pickle'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1fa38921",
"metadata": {},
"outputs": [],
"source": [
"THRESH = [70]\n",
"LEEWAY = [0]\n",
"EPOCH = [20, 30, 50]\n",
"\n",
"DENSE_COUNT = range(1,4)\n",
"DENSE_NEURONS = range(600, 2401, 600)\n",
"\n",
"DENSE2_COUNT = range(1,4)\n",
"DENSE2_NEURONS = range(600, 2401, 600)\n",
"\n",
"AVG_FROM = 30\n",
"\n",
"threshold_p = 0.99"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1a78b0d9",
"metadata": {},
"outputs": [],
"source": [
"import pickle\n",
"\n",
"def load_pickles():\n",
" _p = open(Xpickle_file, 'rb')\n",
" X = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" _p = open(ypickle_file, 'rb')\n",
" y = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" return (np.asarray(X, dtype=pd.DataFrame), np.asarray(y, dtype=str))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c2e37354",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"def load_data():\n",
" if os.path.isfile(Xpickle_file) and os.path.isfile(ypickle_file):\n",
" return load_pickles()\n",
" data = []\n",
" label = []\n",
" for user in range(0, user_count):\n",
" user_path = base_path + str(user) + '/split_letters_csv/'\n",
" for file in os.listdir(user_path):\n",
" file_name = user_path + file\n",
" letter = ''.join(filter(lambda x: x.isalpha(), file))[0]\n",
" data.append(pd.read_csv(file_name, delim))\n",
" label.append(letter)\n",
" return (np.asarray(data, dtype=pd.DataFrame), np.asarray(label, dtype=str), np.asarray(file_name))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0e84c763",
"metadata": {},
"outputs": [],
"source": [
"def shorten(npList, thresh, leeway):\n",
" temp = npList['Force']\n",
" \n",
" temps_over_T = np.where(temp > thresh)[0]\n",
" return npList[max(temps_over_T[0]-leeway,0):temps_over_T[-1]+leeway]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "5af35831",
"metadata": {},
"outputs": [],
"source": [
"from tensorflow.keras.preprocessing.sequence import pad_sequences\n",
"\n",
"def preproc(data, label, thresh, leeway):\n",
" #shorten\n",
" XX = np.array(list(map(shorten, data, [thresh for _ in range(len(data))], [leeway for _ in range(len(data))])),dtype=object)\n",
"\n",
" #filter\n",
" len_mask = np.where(np.asarray(list(map(len, XX))) <= int(pd.Series(np.asarray(list(map(len, XX)))).quantile(threshold_p)))\n",
" X_filter = XX[len_mask] \n",
" y_filter = label[len_mask]\n",
" \n",
" #drop millis\n",
" [x.drop(labels='Millis', axis=1) for x in X_filter]\n",
"\n",
" #pad\n",
" X_filter = pad_sequences(X_filter, dtype=float, padding='post')\n",
" \n",
" return (X_filter, y_filter)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "e28e7ed0",
"metadata": {},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, Flatten, BatchNormalization\n",
"\n",
"def build_model(dcount, dnons, dcount2, dnons2, X_shape):\n",
" model = Sequential()\n",
"\n",
" model.add(BatchNormalization(input_shape=X_shape))\n",
" \n",
" model.add(Flatten())\n",
"\n",
" for i in range(dcount):\n",
" model.add(Dense(dnons, activation='relu'))\n",
" \n",
" for i in range(dcount2):\n",
" model.add(Dense(dnons2, activation='relu'))\n",
" \n",
" model.add(Dense(26, activation='softmax'))\n",
"\n",
" model.compile(\n",
" optimizer=tf.keras.optimizers.Adam(0.001),\n",
" loss=\"categorical_crossentropy\", \n",
" metrics=[\"acc\"],\n",
" )\n",
"\n",
" return model\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8b2b53e9",
"metadata": {},
"outputs": [],
"source": [
"def get_avg_acc(X_train, y_train, X_test, y_test, epoch, dcount, dnons, dcount2, dnons2):\n",
" accs = []\n",
" for i in range(AVG_FROM):\n",
" model = build_model(dcount, dnons, dcount2, dnons2, X_train[0].shape)\n",
" model.fit(X_train, y_train, \n",
" epochs=epoch,\n",
" batch_size=128,\n",
" shuffle=True,\n",
" validation_data=(X_test, y_test),\n",
" verbose=0,\n",
" )\n",
" results = model.evaluate(X_test, y_test, batch_size=128, verbose=0)\n",
" accs.append((model,results[1]))\n",
" return np.mean(np.delete(accs,0,1).astype('float64'))\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "378b11e8",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import LabelEncoder, LabelBinarizer\n",
"import tensorflow as tf\n",
"X, y = load_data()\n",
"result = pd.DataFrame({'Threshold': pd.Series([], dtype='int'),\n",
" 'Leeway': pd.Series([], dtype='int'),\n",
" 'Epoch': pd.Series([], dtype='int'),\n",
" 'DENSE_COUNT1': pd.Series([], dtype='int'),\n",
" 'DENSE_NEURON1': pd.Series([], dtype='int'),\n",
" 'DENSE_COUNT2': pd.Series([], dtype='int'),\n",
" 'DENSE_NEURON2': pd.Series([], dtype='int'),\n",
" 'Accuracy': pd.Series([], dtype='float')})"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "40913d3c",
"metadata": {},
"outputs": [],
"source": [
"# FIRST CELL: set these variables to limit GPU usage.\n",
"os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' # this is required\n",
"os.environ['CUDA_VISIBLE_DEVICES'] = '1' # set to '0' for GPU0, '1' for GPU1 or '2' for GPU2. Check \"gpustat\" in a terminal."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "13e7debb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 600\n",
"Accuracy: 76.83\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 77.67\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.85\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.80\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.19\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 77.89\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.72\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.04\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.24\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.49\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.35\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.62\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.26\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.00\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.84\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.82\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.73\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.04\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.02\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.30\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.06\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.31\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.44\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1200\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.24\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.21\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 77.88\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.46\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.99\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.13\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.58\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.19\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.35\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.37\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.53\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.48\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 1800\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.07\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 600\n",
"Accuracy: 76.76\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 77.73\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.93\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.75\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.17\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.36\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.51\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.98\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 600\n",
"Accuracy: 78.27\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.48\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 78.62\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 1\n",
" Dense Neurons 1: 2400\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.13\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.97\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 77.89\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.77\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 1\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 77.82\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.92\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.13\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 1800\n",
"Accuracy: 77.94\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 2\n",
" Dense Neurons 2: 2400\n",
"Accuracy: 78.08\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 600\n",
"Accuracy: 77.92\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1200\n",
"Accuracy: 78.00\n",
"Testing with: Threshold: 70\n",
" Leeway: 0\n",
" Epoch: 20\n",
" Dense Count 1: 2\n",
" Dense Neurons 1: 600\n",
" Dense Count 2: 3\n",
" Dense Neurons 2: 1800\n"
]
}
],
"source": [
"%%time\n",
"\n",
"for t in THRESH:\n",
" for l in LEEWAY:\n",
" for e in EPOCH:\n",
" for dc in DENSE_COUNT:\n",
" for dn in DENSE_NEURONS:\n",
" for dc2 in DENSE2_COUNT:\n",
" for dn2 in DENSE2_NEURONS:\n",
" print(f\"Testing with: Threshold: {t}\")\n",
" print(f\" Leeway: {l}\")\n",
" print(f\" Epoch: {e}\")\n",
" print(f\" Dense Count 1: {dc}\")\n",
" print(f\" Dense Neurons 1: {dn}\")\n",
" print(f\" Dense Count 2: {dc2}\")\n",
" print(f\" Dense Neurons 2: {dn2}\")\n",
" Xp, yp = preproc(X, y, t, l)\n",
" lb = LabelBinarizer()\n",
"\n",
" ypt = lb.fit_transform(yp)\n",
" X_train, X_test, y_train, y_test = train_test_split(Xp, ypt, test_size=0.2, random_state=177013)\n",
" acc = get_avg_acc(X_train,y_train,X_test, y_test, e, dc,dn,dc2,dn2)\n",
" result = result.append({'Threshold': t,\n",
" 'Leeway': l,\n",
" 'Epoch': e,\n",
" 'DENSE_COUNT1': dc,\n",
" 'DENSE_NEURON1': dn,\n",
" 'DENSE_COUNT2': dc2,\n",
" 'DENSE_NEURON2': dn2,\n",
" 'Accuracy': acc}, ignore_index=True)\n",
" print(f\"Accuracy: {acc*100:.2f}\\n\\n\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c7e0937",
"metadata": {},
"outputs": [],
"source": [
"result.to_csv('./results.csv')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74dbfa20",
"metadata": {},
"outputs": [],
"source": [
"exit()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}