{ "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": "markdown", "source": [ "# Applying Machine Learning Models" ], "metadata": { "id": "sQGcMFmd1LwL" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "drl_NkpR1AUz" }, "outputs": [], "source": [ "#importing required libraries \n", "import numpy as np\n", "import pandas as pd\n", "import itertools\n", "import matplotlib.pyplot as plt\n", "from sklearn.metrics import confusion_matrix\n", "from datetime import datetime\n", "\n", "from sklearn import linear_model\n", "from sklearn import metrics\n", "\n", "from sklearn.model_selection import GridSearchCV\n", "from sklearn.svm import LinearSVC\n", "from sklearn.svm import SVC\n", "from sklearn.tree import DecisionTreeClassifier\n", "from sklearn.ensemble import RandomForestClassifier\n", "from sklearn.ensemble import GradientBoostingClassifier" ] }, { "cell_type": "markdown", "source": [ "Loading Data form File" ], "metadata": { "id": "Lm6VtVdM1bCS" } }, { "cell_type": "code", "source": [ "train = pd.read_csv('/content/drive/MyDrive/UCI_HAR_Dataset/csv_files/train.csv')\n", "test = pd.read_csv('/content/drive/MyDrive/UCI_HAR_Dataset/csv_files/test.csv')\n", "print(train.shape, test.shape)" ], "metadata": { "id": "2T3Z0hWP1aK4", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "2caee9cb-bbd7-4d4d-8e28-d2209b176a29" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "(7352, 564) (2947, 564)\n" ] } ] }, { "cell_type": "code", "source": [ "train.head(2)" ], "metadata": { "id": "C9HrxSH97urK", "colab": { "base_uri": "https://localhost:8080/", "height": 222 }, "outputId": "1064d9e7-2505-4979-ae84-bf57d41e29f4" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " tBodyAcc-mean()-X tBodyAcc-mean()-Y tBodyAcc-mean()-Z tBodyAcc-std()-X \\\n", "0 0.288585 -0.020294 -0.132905 -0.995279 \n", "1 0.278419 -0.016411 -0.123520 -0.998245 \n", "\n", " tBodyAcc-std()-Y tBodyAcc-std()-Z tBodyAcc-mad()-X tBodyAcc-mad()-Y \\\n", "0 -0.983111 -0.913526 -0.995112 -0.983185 \n", "1 -0.975300 -0.960322 -0.998807 -0.974914 \n", "\n", " tBodyAcc-mad()-Z tBodyAcc-max()-X ... angle(tBodyAccMean,gravity) \\\n", "0 -0.923527 -0.934724 ... -0.112754 \n", "1 -0.957686 -0.943068 ... 0.053477 \n", "\n", " angle(tBodyAccJerkMean),gravityMean) angle(tBodyGyroMean,gravityMean) \\\n", "0 0.030400 -0.464761 \n", "1 -0.007435 -0.732626 \n", "\n", " angle(tBodyGyroJerkMean,gravityMean) angle(X,gravityMean) \\\n", "0 -0.018446 -0.841247 \n", "1 0.703511 -0.844788 \n", "\n", " angle(Y,gravityMean) angle(Z,gravityMean) subject Activity ActivityName \n", "0 0.179941 -0.058627 1 5 STANDING \n", "1 0.180289 -0.054317 1 5 STANDING \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", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0.288585 | \n", "-0.020294 | \n", "-0.132905 | \n", "-0.995279 | \n", "-0.983111 | \n", "-0.913526 | \n", "-0.995112 | \n", "-0.983185 | \n", "-0.923527 | \n", "-0.934724 | \n", "... | \n", "-0.112754 | \n", "0.030400 | \n", "-0.464761 | \n", "-0.018446 | \n", "-0.841247 | \n", "0.179941 | \n", "-0.058627 | \n", "1 | \n", "5 | \n", "STANDING | \n", "
1 | \n", "0.278419 | \n", "-0.016411 | \n", "-0.123520 | \n", "-0.998245 | \n", "-0.975300 | \n", "-0.960322 | \n", "-0.998807 | \n", "-0.974914 | \n", "-0.957686 | \n", "-0.943068 | \n", "... | \n", "0.053477 | \n", "-0.007435 | \n", "-0.732626 | \n", "0.703511 | \n", "-0.844788 | \n", "0.180289 | \n", "-0.054317 | \n", "1 | \n", "5 | \n", "STANDING | \n", "
2 rows × 564 columns
\n", "