Skip to content

Commit a4875db

Browse files
authored
personal use
personal use
0 parents  commit a4875db

37 files changed

+64352
-0
lines changed
+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
}

Create table in python to sql db.py

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# In[2]:
5+
6+
7+
#Import libraries
8+
import numpy as np
9+
import numpy as np
10+
import pandas as pd
11+
import numpy as np
12+
from sklearn.preprocessing import QuantileTransformer
13+
from sklearn.metrics import roc_auc_score
14+
from sklearn.metrics import roc_curve
15+
from sklearn.datasets import load_breast_cancer
16+
from numpy import int64
17+
from sklearn import svm
18+
from sklearn.svm import SVC
19+
import matplotlib.pyplot as plt
20+
from matplotlib import rcParams
21+
from sklearn.preprocessing import StandardScaler
22+
from sklearn.model_selection import train_test_split
23+
import seaborn as sns
24+
import matplotlib.pyplot as plt
25+
from xgboost import XGBClassifier
26+
import xgboost
27+
from sklearn.naive_bayes import GaussianNB
28+
from sklearn.neighbors import KNeighborsClassifier
29+
from sklearn.model_selection import train_test_split
30+
from sklearn.datasets import load_iris
31+
from sklearn.metrics import classification_report, accuracy_score
32+
from sklearn.metrics import precision_score, recall_score
33+
from sklearn.metrics import f1_score, matthews_corrcoef
34+
from sklearn.metrics import confusion_matrix
35+
36+
import pandas as pd
37+
from scipy import stats
38+
from sklearn.utils import resample
39+
import numpy as np
40+
import pandas as pd
41+
from mpl_toolkits.mplot3d import Axes3D
42+
from sklearn.preprocessing import StandardScaler
43+
import matplotlib.pyplot as plt # plotting
44+
import numpy as np # linear algebra
45+
import os # accessing directory structure
46+
import pandas as pd # data processing
47+
from pandas.plotting import scatter_matrix
48+
#import library psycopyg2
49+
import psycopg2
50+
#import library pandas
51+
import pandas as pd
52+
#import library sqlio
53+
import pandas.io.sql as sqlio
54+
import psycopg2
55+
56+
57+
58+
59+
# In[ ]:
60+
61+
62+
# get the final results
63+
RandomForest_Model_Prediction
64+
65+
66+
# In[ ]:
67+
68+
69+
# Delete the existing table in SQL DB
70+
import psycopg2
71+
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
72+
psqlCon = psycopg2.connect("dbname=rawData user=data_user password=kgtopg8932");
73+
psqlCon.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT);
74+
psqlCursor = psqlCon.cursor();
75+
tableName = "ml_prediction";
76+
dropTableStmt = "DROP TABLE %s;"%tableName;
77+
psqlCursor.execute(dropTableStmt);
78+
79+
80+
# In[ ]:
81+
82+
83+
#upload new table in to SQL DB
84+
from sqlalchemy import create_engine
85+
engine = create_engine('postgresql://data_user:kgtopg8932@localhost:5432/rawData')
86+
RandomForest_Model_Prediction.to_sql('ml_prediction', engine)
87+
88+
89+
# In[ ]:
90+
91+
92+
# CHECK THE TABLE
93+
query1 = "select * from ml_prediction"
94+
dataset = sqlio.read_sql_query(query1,conn)
95+
dataset
96+
97+
98+
# In[ ]:
99+
100+
101+
# CHECK THE TABLE
102+
query1 = "select * from ml_prediction"
103+
104+
105+
# In[ ]:
106+
107+
108+
dataset = sqlio.read_sql_query(query1,conn)
109+
dataset
110+

0 commit comments

Comments
 (0)