{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" }, "accelerator": "GPU", "gpuClass": "standard" }, "cells": [ { "cell_type": "code", "source": [ "import numpy as np\n", "import pandas as pd" ], "metadata": { "id": "NAp7rXWXmczh" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "j1GEZsxkoTtb", "outputId": "bd50ee59-2c9a-4ce6-82cf-7d1c40e6cf51" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Mounted at /content/drive\n" ] } ] }, { "cell_type": "code", "source": [ "features = list()\n", "with open('/content/drive/MyDrive/UCI _HAR_Dataset/features.txt') as f:\n", " features = [line.split()[1] for line in f.readlines()]\n", "print('No of Features: {}'.format(len(features)))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "T7U-MTw1pk1q", "outputId": "cc0a5b3f-9499-4dee-e308-f2836f34eb69" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "No of Features: 561\n" ] } ] }, { "cell_type": "markdown", "source": [ "**Getting the train data**" ], "metadata": { "id": "UHv_sGqvqpkr" } }, { "cell_type": "code", "source": [ "# get the data from txt files to pandas dataffame\n", "X_train = pd.read_csv('/content/drive/MyDrive/UCI _HAR_Dataset/train/X_train.txt', delim_whitespace=True, header=None)\n", "X_train.columns = [features]\n", "# add subject column to the dataframe\n", "X_train['subject'] = pd.read_csv('/content/drive/MyDrive/UCI _HAR_Dataset/train/subject_train.txt', header=None, squeeze=True)\n", "\n", "y_train = pd.read_csv('/content/drive/MyDrive/UCI _HAR_Dataset/train/y_train.txt', names=['Activity'], squeeze=True)\n", "y_train_labels = y_train.map({1: 'WALKING', 2:'WALKING_UPSTAIRS',3:'WALKING_DOWNSTAIRS',\\\n", " 4:'SITTING', 5:'STANDING',6:'LAYING'})\n", "\n", "# put all columns in a single dataframe\n", "train = X_train\n", "train['Activity'] = y_train\n", "train['ActivityName'] = y_train_labels\n", "train.sample(2)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 223 }, "id": "qaWuiUpnmo15", "outputId": "6403786a-5094-40b0-eec6-656807f6fcc3" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z tBodyAcc-std()-X \\\n", "3199 0.258401 -0.039324 -0.164789 0.307451 \n", "4511 0.313266 -0.026318 -0.080982 0.074007 \n", "\n", " tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X tBodyAcc-mad()-Y \\\n", "3199 -0.026412 0.260639 0.276390 -0.076756 \n", "4511 0.279732 -0.092542 0.071571 0.233530 \n", "\n", " tBodyAcc-mad()-Z tBodyAcc-max()-X ... angle(tBodyAccMean,gravity) \\\n", "3199 0.212899 0.484626 ... 0.049062 \n", "4511 -0.076896 0.012170 ... -0.460265 \n", "\n", " angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", "3199 0.696670 0.980788 \n", "4511 -0.788172 -0.758045 \n", "\n", " angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", "3199 -0.756975 -0.785422 \n", "4511 0.025444 -0.705500 \n", "\n", " angle(Y,gravityMean) angle(Z,gravityMean) subject Activity \\\n", "3199 0.027284 0.156002 16 3 \n", "4511 0.301570 0.022229 22 2 \n", "\n", " ActivityName \n", "3199 WALKING_DOWNSTAIRS \n", "4511 WALKING_UPSTAIRS \n", "\n", "[2 rows x 564 columns]" ], "text/html": [ "\n", "
\n", " | tBodyAcc-mean()-X | \n", "tBodyAcc-mean()-Y | \n", "tBodyAcc-mean()-Z | \n", "tBodyAcc-std()-X | \n", "tBodyAcc-std()-Y | \n", "tBodyAcc-std()-Z | \n", "tBodyAcc-mad()-X | \n", "tBodyAcc-mad()-Y | \n", "tBodyAcc-mad()-Z | \n", "tBodyAcc-max()-X | \n", "... | \n", "angle(tBodyAccMean,gravity) | \n", "angle(tBodyAccJerkMean),gravityMean) | \n", "angle(tBodyGyroMean,gravityMean) | \n", "angle(tBodyGyroJerkMean,gravityMean) | \n", "angle(X,gravityMean) | \n", "angle(Y,gravityMean) | \n", "angle(Z,gravityMean) | \n", "subject | \n", "Activity | \n", "ActivityName | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3199 | \n", "0.258401 | \n", "-0.039324 | \n", "-0.164789 | \n", "0.307451 | \n", "-0.026412 | \n", "0.260639 | \n", "0.276390 | \n", "-0.076756 | \n", "0.212899 | \n", "0.484626 | \n", "... | \n", "0.049062 | \n", "0.696670 | \n", "0.980788 | \n", "-0.756975 | \n", "-0.785422 | \n", "0.027284 | \n", "0.156002 | \n", "16 | \n", "3 | \n", "WALKING_DOWNSTAIRS | \n", "
4511 | \n", "0.313266 | \n", "-0.026318 | \n", "-0.080982 | \n", "0.074007 | \n", "0.279732 | \n", "-0.092542 | \n", "0.071571 | \n", "0.233530 | \n", "-0.076896 | \n", "0.012170 | \n", "... | \n", "-0.460265 | \n", "-0.788172 | \n", "-0.758045 | \n", "0.025444 | \n", "-0.705500 | \n", "0.301570 | \n", "0.022229 | \n", "22 | \n", "2 | \n", "WALKING_UPSTAIRS | \n", "
2 rows × 564 columns
\n", "\n", " | tBodyAcc-mean()-X | \n", "tBodyAcc-mean()-Y | \n", "tBodyAcc-mean()-Z | \n", "tBodyAcc-std()-X | \n", "tBodyAcc-std()-Y | \n", "tBodyAcc-std()-Z | \n", "tBodyAcc-mad()-X | \n", "tBodyAcc-mad()-Y | \n", "tBodyAcc-mad()-Z | \n", "tBodyAcc-max()-X | \n", "... | \n", "angle(tBodyAccMean,gravity) | \n", "angle(tBodyAccJerkMean),gravityMean) | \n", "angle(tBodyGyroMean,gravityMean) | \n", "angle(tBodyGyroJerkMean,gravityMean) | \n", "angle(X,gravityMean) | \n", "angle(Y,gravityMean) | \n", "angle(Z,gravityMean) | \n", "subject | \n", "Activity | \n", "ActivityName | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1382 | \n", "0.276199 | \n", "-0.023761 | \n", "-0.110859 | \n", "-0.997157 | \n", "-0.964725 | \n", "-0.986654 | \n", "-0.997453 | \n", "-0.963536 | \n", "-0.984579 | \n", "-0.937842 | \n", "... | \n", "-0.061579 | \n", "-0.056830 | \n", "0.067044 | \n", "0.772829 | \n", "-0.809269 | \n", "0.229980 | \n", "0.016818 | \n", "12 | \n", "5 | \n", "STANDING | \n", "
938 | \n", "0.278533 | \n", "-0.016891 | \n", "-0.107312 | \n", "-0.997568 | \n", "-0.991948 | \n", "-0.997251 | \n", "-0.997766 | \n", "-0.991250 | \n", "-0.997033 | \n", "-0.943402 | \n", "... | \n", "-0.552650 | \n", "-0.204948 | \n", "0.128435 | \n", "-0.022742 | \n", "-0.346751 | \n", "-0.311439 | \n", "-0.163648 | \n", "10 | \n", "4 | \n", "SITTING | \n", "
2 rows × 564 columns
\n", "