|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 2, |
| 6 | + "id": "8a21c3b6", |
| 7 | + "metadata": { |
| 8 | + "scrolled": true |
| 9 | + }, |
| 10 | + "outputs": [ |
| 11 | + { |
| 12 | + "ename": "ImportError", |
| 13 | + "evalue": "cannot import name 'config'", |
| 14 | + "output_type": "error", |
| 15 | + "traceback": [ |
| 16 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 17 | + "\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)", |
| 18 | + "\u001b[0;32m<ipython-input-2-ac36e1922f39>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msql\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msqlio\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpsycopg2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mconfig\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mconfig\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", |
| 19 | + "\u001b[0;31mImportError\u001b[0m: cannot import name 'config'" |
| 20 | + ] |
| 21 | + } |
| 22 | + ], |
| 23 | + "source": [ |
| 24 | + "#Import libraries \n", |
| 25 | + "import numpy as np\n", |
| 26 | + "import numpy as np\n", |
| 27 | + "import pandas as pd \n", |
| 28 | + "import numpy as np\n", |
| 29 | + "from sklearn.preprocessing import QuantileTransformer\n", |
| 30 | + "from sklearn.metrics import roc_auc_score\n", |
| 31 | + "from sklearn.metrics import roc_curve\n", |
| 32 | + "from sklearn.datasets import load_breast_cancer\n", |
| 33 | + "from numpy import int64\n", |
| 34 | + "from sklearn import svm\n", |
| 35 | + "from sklearn.svm import SVC \n", |
| 36 | + "import matplotlib.pyplot as plt\n", |
| 37 | + "from matplotlib import rcParams\n", |
| 38 | + "from sklearn.preprocessing import StandardScaler\n", |
| 39 | + "from sklearn.model_selection import train_test_split\n", |
| 40 | + "import seaborn as sns\n", |
| 41 | + "import matplotlib.pyplot as plt\n", |
| 42 | + "from xgboost import XGBClassifier\n", |
| 43 | + "import xgboost\n", |
| 44 | + "from sklearn.naive_bayes import GaussianNB\n", |
| 45 | + "from sklearn.neighbors import KNeighborsClassifier\n", |
| 46 | + "from sklearn.model_selection import train_test_split\n", |
| 47 | + "from sklearn.datasets import load_iris\n", |
| 48 | + "from sklearn.metrics import classification_report, accuracy_score \n", |
| 49 | + "from sklearn.metrics import precision_score, recall_score \n", |
| 50 | + "from sklearn.metrics import f1_score, matthews_corrcoef \n", |
| 51 | + "from sklearn.metrics import confusion_matrix \n", |
| 52 | + "\n", |
| 53 | + "import pandas as pd\n", |
| 54 | + "from scipy import stats\n", |
| 55 | + "from sklearn.utils import resample\n", |
| 56 | + "import numpy as np\n", |
| 57 | + "import pandas as pd\n", |
| 58 | + "from mpl_toolkits.mplot3d import Axes3D\n", |
| 59 | + "from sklearn.preprocessing import StandardScaler\n", |
| 60 | + "import matplotlib.pyplot as plt # plotting\n", |
| 61 | + "import numpy as np # linear algebra\n", |
| 62 | + "import os # accessing directory structure\n", |
| 63 | + "import pandas as pd # data processing\n", |
| 64 | + "from pandas.plotting import scatter_matrix\n", |
| 65 | + "#import library psycopyg2\n", |
| 66 | + "import psycopg2\n", |
| 67 | + "#import library pandas\n", |
| 68 | + "import pandas as pd\n", |
| 69 | + "#import library sqlio\n", |
| 70 | + "import pandas.io.sql as sqlio\n", |
| 71 | + "import psycopg2\n", |
| 72 | + "\n", |
| 73 | + " " |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": null, |
| 79 | + "id": "0b9bcdfb", |
| 80 | + "metadata": {}, |
| 81 | + "outputs": [], |
| 82 | + "source": [ |
| 83 | + "# get the final results\n", |
| 84 | + "RandomForest_Model_Prediction" |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "execution_count": null, |
| 90 | + "id": "28700cbc", |
| 91 | + "metadata": {}, |
| 92 | + "outputs": [], |
| 93 | + "source": [ |
| 94 | + "# Delete the existing table in SQL DB\n", |
| 95 | + "import psycopg2\n", |
| 96 | + "from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT\n", |
| 97 | + "psqlCon = psycopg2.connect(\"dbname=rawData user=data_user password=kgtopg8932\");\n", |
| 98 | + "psqlCon.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT);\n", |
| 99 | + "psqlCursor = psqlCon.cursor();\n", |
| 100 | + "tableName = \"ml_prediction\";\n", |
| 101 | + "dropTableStmt = \"DROP TABLE %s;\"%tableName;\n", |
| 102 | + "psqlCursor.execute(dropTableStmt);" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "id": "e0a7bff7", |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "#upload new table in to SQL DB\n", |
| 113 | + "from sqlalchemy import create_engine\n", |
| 114 | + "engine = create_engine('postgresql://data_user:kgtopg8932@localhost:5432/rawData')\n", |
| 115 | + "RandomForest_Model_Prediction.to_sql('ml_prediction', engine)" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "code", |
| 120 | + "execution_count": null, |
| 121 | + "id": "2e57cd92", |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "# CHECK THE TABLE \n", |
| 126 | + "query1 = \"select * from ml_prediction\" \n", |
| 127 | + "dataset = sqlio.read_sql_query(query1,conn)\n", |
| 128 | + "dataset" |
| 129 | + ] |
| 130 | + }, |
| 131 | + { |
| 132 | + "cell_type": "code", |
| 133 | + "execution_count": null, |
| 134 | + "id": "9e21a631", |
| 135 | + "metadata": {}, |
| 136 | + "outputs": [], |
| 137 | + "source": [ |
| 138 | + "# CHECK THE TABLE \n", |
| 139 | + "query1 = \"select * from ml_prediction\" " |
| 140 | + ] |
| 141 | + }, |
| 142 | + { |
| 143 | + "cell_type": "code", |
| 144 | + "execution_count": null, |
| 145 | + "id": "232768fa", |
| 146 | + "metadata": {}, |
| 147 | + "outputs": [], |
| 148 | + "source": [ |
| 149 | + "dataset = sqlio.read_sql_query(query1,conn)\n", |
| 150 | + "dataset\n" |
| 151 | + ] |
| 152 | + } |
| 153 | + ], |
| 154 | + "metadata": { |
| 155 | + "kernelspec": { |
| 156 | + "display_name": "Python 3", |
| 157 | + "language": "python", |
| 158 | + "name": "python3" |
| 159 | + }, |
| 160 | + "language_info": { |
| 161 | + "codemirror_mode": { |
| 162 | + "name": "ipython", |
| 163 | + "version": 3 |
| 164 | + }, |
| 165 | + "file_extension": ".py", |
| 166 | + "mimetype": "text/x-python", |
| 167 | + "name": "python", |
| 168 | + "nbconvert_exporter": "python", |
| 169 | + "pygments_lexer": "ipython3", |
| 170 | + "version": "3.6.8" |
| 171 | + } |
| 172 | + }, |
| 173 | + "nbformat": 4, |
| 174 | + "nbformat_minor": 5 |
| 175 | +} |
0 commit comments