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

626 lines
3.2 MiB
Plaintext
Raw Normal View History

2021-06-07 19:58:49 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "bc370b04",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import os\n",
"import pickle\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "a45e07cc",
"metadata": {},
"outputs": [],
"source": [
"delim = ';'\n",
"\n",
"user_count = 100\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": "a6f4d2c5",
"metadata": {},
"outputs": [],
"source": [
"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": 4,
"id": "56af52f4",
"metadata": {},
"outputs": [],
"source": [
"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))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "36efa957",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"id": "b7e14597",
"metadata": {},
"outputs": [],
"source": [
"def save_pickle():\n",
"# _p = open(np.asarray(data, dtype=pd.DataFrame), 'wb')\n",
" _p = open(Xpickle_file, 'wb')\n",
" pickle.dump(X, _p)\n",
" _p.close()\n",
"\n",
"# _p = open(np.asarray(label, dtype=str), 'wb')\n",
" _p = open(ypickle_file, 'wb')\n",
" pickle.dump(y, _p)\n",
" _p.close()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4dbdd4f9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(13102, 13102)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(X), len(y)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "98d3fe70",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 13102.000000\n",
"mean 208.304457\n",
"std 206.732342\n",
"min 42.000000\n",
"50% 185.000000\n",
"90% 270.000000\n",
"91% 276.000000\n",
"92% 286.000000\n",
"93% 299.000000\n",
"94% 312.000000\n",
"95% 333.000000\n",
"96% 355.000000\n",
"97% 388.000000\n",
"98% 456.980000\n",
"99% 701.940000\n",
"max 11073.000000\n",
"dtype: float64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAc20lEQVR4nO3deXRc9Znm8e+r0i7Lkm3Jq7yCV8AY0BgIwUCAtPEEmExIsNMZyIazMd3p5CQDoUNn6NM9k2QO6WSGDnEgoUPSECAkuIMJoWnCEjYLMF6xkVdJXiRLsmRblrXUO3/UtSnLMirbJd1ans85dXTr3p+rHsulx1e3bt2fuTsiIpL+csIOICIiyaFCFxHJECp0EZEMoUIXEckQKnQRkQyRG9YTV1RU+JQpU8J6ehGRtPTGG2/sdffK/raFVuhTp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9Bw7T3euUF+eFHUVEBpEKPQsc+TDR+ZNGhJxERAaTCj3DdXb3cvczmxhdWsA5VWVhxxGRQaSpajLcD57ZxKY9B/j5Z/4TBbmRsOOIyCDSHnoGa2zv5Od/3sbHL6jiipmamUgk06nQM9gDL2+jJxrl1g+dGXYUERkCKvQM9taOfcytKmfyqJKwo4jIEFChZ7h8nXsukjX0057Bdrd3UqZzz0Wyhgo9Q+09cJitew9ywWSdey6SLVToGeo3b9QDsGC6LpUrki1U6Bmos7uXn/15K5ecOUozE4lkERV6Bvr+0xvZ036YW6+YHnYUERlCCRW6mS00s41mVmtmt51gzCfMbL2ZrTOzf01uTEnUym0t3P/SVm66eDIXnzEq7DgiMoQG/Oi/mUWAe4CrgXpgpZk
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"X_len = np.asarray(list(map(len, X)))\n",
"l = []\n",
"sq_xlen = pd.Series(X_len)\n",
"ptiles = [x*0.01 for x in range(100)]\n",
"for i in ptiles:\n",
" l.append(sq_xlen.quantile(i))\n",
"plt.plot(l, ptiles)\n",
"sq_xlen.describe(percentiles=[x*0.01 for x in range(90,100)])"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "f687916d",
"metadata": {},
"outputs": [],
"source": [
"def fill(x, threshold):\n",
" fill = threshold - len(x)\n",
" xx = x\n",
" for i in range(fill):\n",
" xx = xx.append(pd.Series(0,index=x.columns,dtype='float64'), ignore_index=True)\n",
" return xx"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "fd5700dc",
"metadata": {},
"outputs": [],
"source": [
"threshold_p = 0.98\n",
"threshold = int(sq_xlen.quantile(threshold_p))\n",
"len_mask = np.where(X_len <= threshold)\n",
"\n",
"X_filter = X[len_mask]\n",
"y_filter = y[len_mask]"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "84081ad4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 41min 37s, sys: 1.15 s, total: 41min 38s\n",
"Wall time: 41min 59s\n"
]
}
],
"source": [
"%%time\n",
"X_filter = list(map(fill, X_filter, [threshold for i in range(len(X_filter))]))"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "d757bb26",
"metadata": {},
"outputs": [],
"source": [
"def plot_data(data):\n",
" fig, axs = plt.subplots(4, 3, figsize=(3*3, 3*4))\n",
" t = data['Millis']\n",
" axs[0][0].plot(t, data['Acc1 X'])\n",
" axs[0][1].plot(t, data['Acc1 Y'])\n",
" axs[0][2].plot(t, data['Acc1 Z'])\n",
" axs[1][0].plot(t, data['Acc2 X'])\n",
" axs[1][1].plot(t, data['Acc2 Y'])\n",
" axs[1][2].plot(t, data['Acc2 Z'])\n",
" axs[2][0].plot(t, data['Gyro X'])\n",
" axs[2][1].plot(t, data['Gyro Y'])\n",
" axs[2][2].plot(t, data['Gyro Z'])\n",
" axs[3][0].plot(t, data['Mag X'])\n",
" axs[3][1].plot(t, data['Mag Y'])\n",
" axs[3][2].plot(t, data['Mag Z'])\n",
"\n",
" for a in axs:\n",
" for b in a:\n",
" b.plot(t, data['Force'])\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "14fc3f15",
"metadata": {},
"outputs": [],
"source": [
"Xfiltered_pickle_file = './X_filter.pickle'\n",
"yfiltered_pickle_file = \"./y_filter.pickle\""
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "26261cc2",
"metadata": {},
"outputs": [],
"source": [
"def save_filtered():\n",
" _p = open(Xfiltered_pickle_file, 'wb')\n",
" pickle.dump(X_filter, _p)\n",
" _p.close()\n",
"\n",
" _p = open(yfiltered_pickle_file, 'wb')\n",
" pickle.dump(y_filter, _p)\n",
" _p.close()"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "a24e9dd2",
"metadata": {},
"outputs": [],
"source": [
"save_filtered()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b4710358",
"metadata": {},
"outputs": [],
"source": [
"def load_filtered_pickles():\n",
" _p = open(Xfiltered_pickle_file, 'rb')\n",
" X = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" _p = open(yfiltered_pickle_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": 10,
"id": "7a9b0d8b",
"metadata": {},
"outputs": [],
"source": [
"XX_filtered, yy_filtered = load_filtered_pickles()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6d04f333",
"metadata": {},
"outputs": [],
"source": [
"# FIRST CELL: set these variables to limit GPU usage.\n",
"import os\n",
"os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true' # this is required\n",
"os.environ['CUDA_VISIBLE_DEVICES'] = '2' # set to '0' for GPU0, '1' for GPU1 or '2' for GPU2. Check \"gpustat\" in a terminal."
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "096a2e4c",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"from sklearn.preprocessing import LabelEncoder, LabelBinarizer\n",
"import tensorflow as tf\n",
"\n",
"lb = LabelBinarizer()\n",
"\n",
"yyt_filtered = lb.fit_transform(yy_filtered)\n",
"XX_filtered = np.asarray(XX_filtered).astype('float64')\n",
"XXX_filtered = np.delete(XX_filtered, 0, 2)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "ec34736a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(10271, 456, 14)\n",
"(2568, 456, 14)\n",
"(10271, 26)\n",
"(2568, 26)\n"
]
}
],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(XXX_filtered, yyt_filtered, test_size=0.2, random_state=177013)\n",
"\n",
"print(X_train.shape)\n",
"print(X_test.shape)\n",
"print(y_train.shape)\n",
"print(y_test.shape)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "c467d4db",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Model: \"sequential_3\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"flatten_3 (Flatten) (None, 6384) 0 \n",
"_________________________________________________________________\n",
"dense_6 (Dense) (None, 456) 2911560 \n",
"_________________________________________________________________\n",
"dense_7 (Dense) (None, 26) 11882 \n",
"=================================================================\n",
"Total params: 2,923,442\n",
"Trainable params: 2,923,442\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
]
}
],
"source": [
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv1D, MaxPooling1D\n",
"\n",
"model = Sequential()\n",
"\n",
"# model.add(Conv1D(32, 3, input_shape = X_train.shape[1:]))\n",
"# model.add(Activation('relu'))\n",
"# model.add(MaxPooling1D(pool_size=3))\n",
"\n",
"# model.add(Conv1D(32, 3))\n",
"# model.add(Activation('relu'))\n",
"# model.add(MaxPooling1D(pool_size=3))\n",
"\n",
"model.add(Flatten(input_shape=(456,14)))\n",
"\n",
"model.add(Dense(456, 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",
"model.summary()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "ce568e2b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((10271, 456, 14), (10271, 26))"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X_train.shape, y_train.shape"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "b607aa96",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"161/161 [==============================] - 1s 2ms/step - loss: 8658.2280 - acc: 0.0409\n",
"Epoch 2/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 26.3454 - acc: 0.0447\n",
"Epoch 3/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 10.9452 - acc: 0.0422\n",
"Epoch 4/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.9099 - acc: 0.0437\n",
"Epoch 5/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.5461 - acc: 0.0474\n",
"Epoch 6/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 4.2588 - acc: 0.0423\n",
"Epoch 7/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.3213 - acc: 0.0414\n",
"Epoch 8/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.2681 - acc: 0.0451\n",
"Epoch 9/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.2482 - acc: 0.0422\n",
"Epoch 10/10\n",
"161/161 [==============================] - 0s 2ms/step - loss: 3.2693 - acc: 0.0435\n"
]
},
{
"data": {
"text/plain": [
"<tensorflow.python.keras.callbacks.History at 0x7f10928e4910>"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(X_train, y_train, \n",
" epochs=10,\n",
" batch_size=64,\n",
" shuffle=True,\n",
" verbose=1\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "eed818c0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Evaluate on test data\n",
"81/81 [==============================] - 0s 2ms/step - loss: 19.9920 - acc: 0.0331\n",
"test loss, test acc: [19.992048263549805, 0.033099688589572906]\n",
"Generate predictions for 3 samples\n",
"predictions shape: (3, 26)\n"
]
},
{
"data": {
"text/plain": [
"(array(['K', 'T', 'U'], dtype='<U1'), array(['T', 'T', 'T'], dtype='<U1'))"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Evaluate the model on the test data using `evaluate`\n",
"print(\"Evaluate on test data\")\n",
"results = model.evaluate(X_test, y_test, batch_size=32)\n",
"print(\"test loss, test acc:\", results)\n",
"\n",
"# Generate predictions (probabilities -- the output of the last layer)\n",
"# on new data using `predict`\n",
"print(\"Generate predictions for 3 samples\")\n",
"predictions = model.predict(X_test[:3])\n",
"print(\"predictions shape:\", predictions.shape)4\n",
"\n",
"lb.inverse_transform(y_test[:3]), lb.inverse_transform(predictions)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0c42dedf",
"metadata": {},
"outputs": [],
"source": [
"exit()"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "ec90274c",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABIoAAAzsCAYAAADcUyfVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOy9d5gkV3m2f58KnXu6J8/szOaVNigHlAAhBAgZGQSYaGwy+LPh54A/jI0TxulzIBljgok2QYAQIgtFUI6bc97JuXOqrqrz+6Oqe2Z2emZnk1arPfd17bXTlbq6p6fr1HOe93mFlBKFQqFQKBQKhUKhUCgUCoVCO9MnoFAoFAqFQqFQKBQKhUKheG6ghCKFQqFQKBQKhUKhUCgUCgWghCKFQqFQKBQKhUKhUCgUCoWPEooUCoVCoVAoFAqFQqFQKBSAEooUCoVCoVAoFAqFQqFQKBQ+SihSKBQKhUKhUCgUCoVCoVAASihSKBQKhUKhUCgUCoVCoVD4KKFIoVA8ZxBC/EoIkRJCBM/0uSgUCoVCoVA83xFCHBZClIQQeX8M9jMhxNIzfV4KheLMooQihULxnEAIsQJ4MSCB15zZs1EoFAqFQqE4Z3i1lDIGdAOjwGfP8PkoFIozjBKKFArFc4W3A48DXwfecWZPRaFQKBQKheLcQkpZBm4HNpzpc1EoFGcW40yfgEKhUPi8Hfgk8ATwuBCiU0o5eobPSaFQKBQKheKcQA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38FaPWXfwj4cwAp5Q7ge8BO4C7gA6rjmeLZYGx
"text/plain": [
"<Figure size 1440x4320 with 26 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig, axs = plt.subplots(13,2,figsize=(20, 60), sharey=True)\n",
"for i,j in zip(XXX_filtered, yy_filtered):\n",
" num = ord(j) - 64\n",
" f = i.T[12]\n",
" r = int((num-1)/2)%13\n",
" c = (num-1)%2\n",
" axs[r][c].title.set_text(f'{j}')\n",
" axs[r][c].plot(f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0e1cee4",
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}