diff --git a/Visulization/Statistical Test.ipynb b/Visulization/Statistical Test.ipynb new file mode 100644 index 0000000..48b139d --- /dev/null +++ b/Visulization/Statistical Test.ipynb @@ -0,0 +1,296 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "from statsmodels.stats.proportion import proportions_ztest\n", + "pd.set_option('mode.chained_assignment', None)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# data import\n", + "train = pd.read_csv('Training_Dataset.csv')\n", + "train_labels = pd.read_csv(\"Labels_Train.csv\")\n", + "test = pd.read_csv(\"Repackaged_Benign_Testset.csv\")\n", + "test_labels = pd.read_csv(\"Labels_Repackaged_Benign_Test.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "train['label'] = train_labels['label']\n", + "test['label'] = test_labels['label']\n", + "data = pd.concat([train, test])" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of benign apps: 4862\n", + "Number of malicious apps: 9142\n" + ] + } + ], + "source": [ + "print(\"Number of benign apps:\", data[data['label']==0].shape[0])\n", + "print(\"Number of malicious apps:\", data[data['label']==1].shape[0])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "sensor_types = data.iloc[:, -30:-1].columns" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# get number of sensors used\n", + "data['num_sensors'] = data[sensor_types].sum(axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "count 14004.000000\n", + "mean 0.384462\n", + "std 1.569956\n", + "min 0.000000\n", + "25% 0.000000\n", + "50% 0.000000\n", + "75% 0.000000\n", + "max 29.000000\n", + "Name: num_sensors, dtype: float64" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data['num_sensors'].describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Text(0.5, 1.0, 'Distribution of number of sensors used (Malicious apps)')" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEICAYAAAC3Y/QeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaIUlEQVR4nO3debxdVX338c/XhBkCCQQMSSAMqSWkjyIp4lClxZYw1NABjVUSeHgasThg6SODKKKNohW0PBWepqIJg9IUrEQRhcai8ioFAoIQAhIZkpCYXOaEUiDh1z/WurrvyRlvLvfm3PV9v173dc9Ze1prr72/Z++1T24UEZiZWVleM9QVMDOzwefwNzMrkMPfzKxADn8zswI5/M3MCuTwNzMr0LAIf0n/X9InB2hd+0jaIGlEfn+zpP8zEOvO67tB0uyBWl8H2/1bSU9I+tVgb7umHkdIWjWE2/8TSStzHx8yVPUYDiRNkhSSRjaZ5/OSTh/g7X5a0pX5dZ/ztckyvyfpwYGsx9ZI0kWSTm1n3q0+/CU9KukFSeslPSPpPySdKunXdY+IUyPis22u653N5omIFRGxc0RsGoC6//ograz/6IhYsKXr7rAeE4EzgCkR8drB3PZW6EvAh3If/2yoKzOcSRoLzAL+Mb8/In9YfLtmvtfn8ps73Ua752tE/DQiXtfp+rvQ3wGfkLRtqxm3+vDP/jgidgH2BS4AzgQuG+iNNLuC6XL7Ak9GxLqhrshA6md/7QssHei6vNq69Ng8Cfh+RLxQKesB3iJp90rZbOAXg1mx4Soi1gAPAO9qNW+3hD8AEfFs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6QV20KSHgWmRUTX/uMUSW8HNgCXR8TUXPZF4KmIuCB/UI+OiDOHsp7tatCeTwMbIuJLQ1m3/pA0DhgXEXdJ2gW4EzgeOInu7aNGbXo3XdhPkgTsFBEbJG0D3AJ8FPhTOuyj4Xjl7z8hsZWKiJ8AT9UUzwAW5NcLSCdmV2jQnq4VEWsi4q78ej2wjPSv8ru5jxq1qStFsiG/3Sb/BP3oo+EY/vX+hETXdnZFADdKujP/+YvhYq+IWAPpRAX2HOL6DIQPSfp5HhbqmiGSKkmTgEOA2xgmfVTTJujSfpI0QtLdwDrgpojoVx8Nx/Bv609IdKG3RsQbSX8R9bQ85GBbn0uBA4A3AGuAC4e0Nv0gaWfgWuD0iHhuqOszEOq0qWv7KSI2RcQbSH8h4TBJU/uznuEY/sPyT0hExOr8ex3wr6ThreFgbR6X7R2fXTfE9dkiEbE2n5yvAP9El/VTHke+FrgqIr6di7u6j+q1qdv7CSAingFuBqbTjz4ajuE/7P6EhKSd8sMqJO0E/BFwX/OlusYiYHZ+PRu4bgjrssV6T8DsT+iifsoPEy8DlkXERZVJXdtHjdrUrf0kaayk3fLrHYB3Ag/Qjz4adt/2Achf2/oKv/kTEnOHtkZbRtL+pKt9SH+S45vd2CZJ3wKOIP352bXAecB3gIXAPsAK4ISI6IqHqA3acwRpKCGAR4EP9I7Fbu0kvQ34KXAv8EouPoc0Rt6tfdSoTe+lC/tJ0v8iPdAdQbp4XxgRn5G0Ox320bAMfzMza244DvuYmVkLDn8zswI5/M3MCuTwNzMrkMPfzKxADn8zswI5/M3MCvQ/3zYqt5o6Ps4AAAAASUVORK5CYII=\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(data[data['label']==1]['num_sensors'])\n", + "plt.title(\"Distribution of number of sensors used (Malicious apps)\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Text(0.5, 1.0, 'Distribution of number of sensors used (Benign apps)')" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEICAYAAAC3Y/QeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAZ6UlEQVR4nO3ce5hdVX3/8feHJEAIBBITMCSBAYyVkFqUiGnRmgItKWpDL2ioQrD0F7lYodWWQPURrCloq/LQn1BRfEhESVOhElF+mkYi+isFEorGEJAUYhIScuFiEopIwrd/rDVk5+ScmTOXzGTO+rye5zxz9tp7r73Wvnxmn3X2jCICMzMry3793QAzM+t7Dn8zswI5/M3MCuTwNzMrkMPfzKxADn8zswK1fPhL+mdJH++luo6StF3SoDy9RNKf90bdub67Jc3srfq6sN1PSdoi6em+3nZNO6ZKWteP2/9DSWvzMX5Tf7WjFUhqkxSSBnewzDWSLuuj9myXdGxfbGtvk/QHkub3tJ4BHf6SVkt6UdI2Sc9L+g9JF0p6tV8RcWFE/F2TdZ3e0TIRsSYiDo6Inb3Q9qsk3VpT/+9HxNye1t3FdowHPgJMjIjX9uW290H/CHwoH+P/6u/GtDJJo4HzgC/m6amSXskhvV3SU5Ku7q3t5WP6RG/V158iYiEwSdIbe1LPgA7/7N0RcQhwNHAtcDlwc29vpKM7mAHuaOCZiNjU3w3pTd08XkcDK3q7LXvbAD03zwe+ExEvVsrW55A+GHgbcIGks/qjcQPAbcCsHtUQEQP2BawGTq8pOxl4BZiUp28BPpXfjwLuAp4HngV+SPoF+NW8zovAduBvgDYggAuANcC9lbLBub4lwDXAA8AvgDuBkXneVGBdvfYC04BfAS/n7f24Ut+f5/f7AR8Dfg5sAuYBh+Z57e2Ymdu2BfjbDvbToXn9zbm+j+X6T899fiW345Y6604F1pE+HWwCNgAfqMx/tc15+nzgR5XpAC4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olIh4M+k/ol6Shxxs33MjcBxwIrAB+Gy/tqYbJB0M3A5cFhFb+7s9vaFOnwbscYqInRFxIuk/JJwsaVJ36mnF8G/JfyEREevzz03Av5GGt1rBxjwu2z4+u6mf29MjEbExX5yvAF9igB2nPI58O/C1iLgjFw/oY1SvTwP9OAFExPPAEmAa3ThGrRj+LfcvJCQNy19WIWkY8HvATztea8BYCMzM72cCd/ZjW3qs/QLM/pABdJzyl4k3Aysj4nOVWQP2GDXq00A9TpJGSzosvx8KnA48SjeOUcs97QOQH9u6jl3/QmJO/7aoZyQdS7rbh/QvOb4+EPsk6TZgKunfz24EPgF8E1gAHAWsAc6OiAHxJWqD/kwlDSUEsBr4YPtY7L5O0tuAHwLLgVdy8ZWkMfKBeowa9ekcBuBxkvRG0he6g0g37wsi4pOSXkMXj1FLhr+ZmXWsFYd9zMysEw5/M7MCOfzNzArk8DczK5DD38ysQA5/M7MCOfzNzAr0v71I+3pG9UiwAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(data[data['label']==0]['num_sensors'])\n", + "plt.title(\"Distribution of number of sensors used (Benign apps)\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# whether an app uses any sensors\n", + "data['use_sensors'] = data['num_sensors']>0" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "label\n", + "0 0.137392\n", + "1 0.186721\n", + "Name: use_sensors, dtype: float64" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.groupby('label')['use_sensors'].mean()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let $p$ be the proportion of apps that use at least one sensor.\n", + "\n", + "$$H_0: p_1 = p_2 $$\n", + "\n", + "$$H_a: p_1 > p_2 $$\n", + "\n", + "$p_1$: malicious apps\n", + "\n", + "$p_2$: benign apps" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "z_stat: 7.405, p_value: 0.000\n", + "Reject the null hypothesis. Proportion of malicious apps using sensors is higher.\n" + ] + } + ], + "source": [ + "significance = 0.01\n", + "\n", + "sample_success_a, sample_size_a = (data[data['label']==1]['use_sensors'].value_counts().values[1], \n", + " data[data['label']==1]['use_sensors'].shape[0])\n", + "sample_success_b, sample_size_b = (data[data['label']==0]['use_sensors'].value_counts().values[1], \n", + " data[data['label']==0]['use_sensors'].shape[0])\n", + "\n", + "successes = np.array([sample_success_a, sample_success_b])\n", + "samples = np.array([sample_size_a, sample_size_b])\n", + "\n", + "stat, p_value = proportions_ztest(count = successes, nobs = samples, \n", + " alternative = 'larger')\n", + "\n", + "print('z_stat: %0.3f, p_value: %0.3f' % (stat, p_value))\n", + "if p_value > significance:\n", + " print(\"Fail to reject the null hypothesis\")\n", + "else:\n", + " print(\"Reject the null hypothesis. Proportion of malicious apps using sensors is higher.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "p1: 0.187\n", + "p2: 0.137\n" + ] + } + ], + "source": [ + "print('p1: %0.3f' % (sample_success_a / sample_size_a))\n", + "print('p2: %0.3f' % (sample_success_b / sample_size_b))" + ] + } + ], + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}