Skip to content

Commit 795700a

Browse files
committed
update
1 parent 889646a commit 795700a

File tree

8 files changed

+838
-0
lines changed

8 files changed

+838
-0
lines changed
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"import numpy as np\n",
12+
"import pandas as pd\n",
13+
"from sklearn.linear_model import LogisticRegression\n",
14+
"from sklearn.model_selection import train_test_split\n",
15+
"\n",
16+
"import pickle\n",
17+
"import warnings\n",
18+
"warnings.filterwarnings(\"ignore\")"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {},
25+
"outputs": [],
26+
"source": [
27+
"data = pd.read_csv(\"Forest_fire.csv\")\n",
28+
"data = np.array(data)\n",
29+
"print(data[:5])"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {},
36+
"outputs": [],
37+
"source": [
38+
"X = data[1:, 1:-1]\n",
39+
"y = data[1:, -1]\n",
40+
"y = y.astype('int')\n",
41+
"X = X.astype('int')\n",
42+
"print(len(X))\n",
43+
"print(X[:5],y[:5])\n"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)\n",
53+
"print(len(X_train) , len(X_test))\n",
54+
"print(len(y_train) , len(y_test))"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": null,
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"log_reg = LogisticRegression()\n",
64+
"\n",
65+
"log_reg.fit(X_train, y_train)"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"inputt=[int(x) for x in \"45 32 60\".split(' ')]\n",
75+
"final=[np.array(inputt)]\n",
76+
"print(final)\n",
77+
"b = log_reg.predict_proba(final)\n",
78+
"print(b)\n",
79+
"\n",
80+
"pickle.dump(log_reg,open('model.pkl','wb'))\n",
81+
"model=pickle.load(open('model.pkl','rb'))"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"#inputt=[int(x) for x in \"45 32 60\".split(' ')]\n",
91+
"#final=[np.array(inputt)]\n",
92+
"#print(final)\n",
93+
"b = log_reg.predict([[45,32,60]])\n",
94+
"print(b)"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"## use the model and display in Flask"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {},
108+
"outputs": [
109+
{
110+
"name": "stderr",
111+
"output_type": "stream",
112+
"text": [
113+
" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
114+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
115+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
116+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
117+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n",
118+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
119+
"127.0.0.1 - - [27/Aug/2020 16:20:42] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n",
120+
"127.0.0.1 - - [27/Aug/2020 16:20:50] \"\u001b[37mPOST /predict HTTP/1.1\u001b[0m\" 200 -\n",
121+
"127.0.0.1 - - [27/Aug/2020 16:20:50] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n",
122+
"127.0.0.1 - - [27/Aug/2020 16:20:50] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
123+
"127.0.0.1 - - [27/Aug/2020 16:20:50] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
124+
"127.0.0.1 - - [27/Aug/2020 16:20:50] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n"
125+
]
126+
},
127+
{
128+
"name": "stdout",
129+
"output_type": "stream",
130+
"text": [
131+
"[40, 40, 60]\n",
132+
"[array([40, 40, 60])]\n"
133+
]
134+
},
135+
{
136+
"name": "stderr",
137+
"output_type": "stream",
138+
"text": [
139+
"[2020-08-27 16:21:02,633] ERROR in app: Exception on /predict [POST]\n",
140+
"Traceback (most recent call last):\n",
141+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\app.py\", line 1982, in wsgi_app\n",
142+
" response = self.full_dispatch_request()\n",
143+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\app.py\", line 1614, in full_dispatch_request\n",
144+
" rv = self.handle_user_exception(e)\n",
145+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\app.py\", line 1517, in handle_user_exception\n",
146+
" reraise(exc_type, exc_value, tb)\n",
147+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\_compat.py\", line 33, in reraise\n",
148+
" raise value\n",
149+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\app.py\", line 1612, in full_dispatch_request\n",
150+
" rv = self.dispatch_request()\n",
151+
" File \"C:\\ProgramData\\Anaconda3\\lib\\site-packages\\flask\\app.py\", line 1598, in dispatch_request\n",
152+
" return self.view_functions[rule.endpoint](**req.view_args)\n",
153+
" File \"<ipython-input-1-60d99ab23a5c>\", line 15, in predict\n",
154+
" int_features=[int(x) for x in request.form.values()]\n",
155+
" File \"<ipython-input-1-60d99ab23a5c>\", line 15, in <listcomp>\n",
156+
" int_features=[int(x) for x in request.form.values()]\n",
157+
"ValueError: invalid literal for int() with base 10: ''\n",
158+
"127.0.0.1 - - [27/Aug/2020 16:21:02] \"\u001b[1m\u001b[35mPOST /predict HTTP/1.1\u001b[0m\" 500 -\n",
159+
"127.0.0.1 - - [27/Aug/2020 16:21:09] \"\u001b[37mPOST /predict HTTP/1.1\u001b[0m\" 200 -\n",
160+
"127.0.0.1 - - [27/Aug/2020 16:21:09] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
161+
"127.0.0.1 - - [27/Aug/2020 16:21:09] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n",
162+
"127.0.0.1 - - [27/Aug/2020 16:21:10] \"\u001b[33mGET /.js/materialize.js HTTP/1.1\u001b[0m\" 404 -\n",
163+
"127.0.0.1 - - [27/Aug/2020 16:21:10] \"\u001b[33mGET /js/init.js HTTP/1.1\u001b[0m\" 404 -\n"
164+
]
165+
},
166+
{
167+
"name": "stdout",
168+
"output_type": "stream",
169+
"text": [
170+
"[10, 10, 10]\n",
171+
"[array([10, 10, 10])]\n"
172+
]
173+
}
174+
],
175+
"source": [
176+
"from flask import Flask,request, url_for, redirect, render_template\n",
177+
"import pickle\n",
178+
"import numpy as np\n",
179+
"\n",
180+
"app = Flask(__name__)\n",
181+
"model=pickle.load(open('model.pkl','rb'))\n",
182+
"\n",
183+
"@app.route('/')\n",
184+
"def hello_world():\n",
185+
" return render_template(\"forest_fire1.html\")\n",
186+
"\n",
187+
"@app.route('/predict',methods=['POST','GET'])\n",
188+
"def predict():\n",
189+
" # receive the values send by user in three text boxes thru request object -> requesst.form.values()\n",
190+
" int_features=[int(x) for x in request.form.values()]\n",
191+
" final=[np.array(int_features)]\n",
192+
" print(int_features)\n",
193+
" print(final)\n",
194+
" prediction=model.predict_proba(final)\n",
195+
" output='{0:.{1}f}'.format(prediction[0][1], 2)\n",
196+
"\n",
197+
" if output>str(0.5):\n",
198+
" return render_template('forest_fire1.html',pred='Your Forest is in Danger.\\nProbability of fire occuring is {}'.format(output))\n",
199+
" else:\n",
200+
" return render_template('forest_fire1.html',pred='Your Forest is safe.\\n Probability of fire occuring is {}'.format(output))\n",
201+
"\n",
202+
"if __name__ == '__main__':\n",
203+
" app.run(debug=False)\n"
204+
]
205+
},
206+
{
207+
"cell_type": "code",
208+
"execution_count": null,
209+
"metadata": {
210+
"collapsed": true
211+
},
212+
"outputs": [],
213+
"source": [
214+
" \n",
215+
" \n"
216+
]
217+
},
218+
{
219+
"cell_type": "code",
220+
"execution_count": null,
221+
"metadata": {
222+
"collapsed": true
223+
},
224+
"outputs": [],
225+
"source": []
226+
},
227+
{
228+
"cell_type": "code",
229+
"execution_count": null,
230+
"metadata": {
231+
"collapsed": true
232+
},
233+
"outputs": [],
234+
"source": []
235+
}
236+
],
237+
"metadata": {
238+
"kernelspec": {
239+
"display_name": "Python 3",
240+
"language": "python",
241+
"name": "python3"
242+
},
243+
"language_info": {
244+
"codemirror_mode": {
245+
"name": "ipython",
246+
"version": 3
247+
},
248+
"file_extension": ".py",
249+
"mimetype": "text/x-python",
250+
"name": "python",
251+
"nbconvert_exporter": "python",
252+
"pygments_lexer": "ipython3",
253+
"version": "3.6.3"
254+
}
255+
},
256+
"nbformat": 4,
257+
"nbformat_minor": 2
258+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Area,Oxygen,Temperature,Humidity,Fire Occurrence
2+
Jharkand,40,45,20,1
3+
Bangalore,50,30,10,1
4+
punjan,10,20,70,0
5+
chandigarh,60,45,70,1
6+
delhi,30,48,10,1
7+
Bangalore,50,15,30,0
8+
Jharkand,5,35,35,0
9+
Bangalore,5,20,70,0
10+
Jharkand,60,32,19,1
11+
Bangalore,30,50,45,1
12+
Jharkand,40,55,80,1
13+
Bangalore,30,39,100,0
14+
Jharkand,10,12,12,0
15+
Bangalore,20,23,23,0
16+
Ecuador,60,34,15,1
17+
canada,80,4,68,0
18+
c,25,56,79,1
19+
c,12,45,90,0
20+
asd,28,43,15,1
21+
asd,26,0,32,0
22+
ad,32,37,21,1
23+
sasd,45,48,12,1
24+
asd,56,15,65,0
25+
asdas,67,45,33,1
26+
das,78,49,8,1
27+
das,89,45,18,1
28+
ads,21,12,44,0
29+
ads,11,20,59,0
30+
asd,1,32,70,0
31+
,5,20,45,0
32+
,42,43,20,1
33+
,32,60,30,1
34+
,5,15,5,0
35+
,20,30,5,0
36+
,30,51,2,1
37+
,60,60,10,1
38+
,10,10,60,0
39+
,0,30,0,0
40+
,45,45,15,1
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from flask import Flask\n",
10+
"\n",
11+
"#instantiate the object of Flask - app\n",
12+
"app = Flask(__name__)\n",
13+
"\n",
14+
"#the object app will handle incoming request from the web/browser\n",
15+
"# the method inside app object is route ( parameter is the path)\n",
16+
"# and define the method attached with that - in our example we have home()\n",
17+
"@app.route('/')\n",
18+
"def home() : \n",
19+
" return \"<h1> Welcome Flask </h1><br> Thank you <a href=/page2> Go to Page2 </a> \"\n",
20+
"\n",
21+
"@app.route('/page2')\n",
22+
"def showpage2() : \n",
23+
" return \"<h1> Welcome to Page2 of Website </h1><br> Deep Learning Champs \"\n",
24+
"\n",
25+
"# the default module/program name is __main__\n",
26+
"if __name__ == '__main__':\n",
27+
" app.run(debug=False)\n",
28+
" "
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {},
35+
"outputs": [
36+
{
37+
"name": "stderr",
38+
"output_type": "stream",
39+
"text": [
40+
" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n",
41+
"127.0.0.1 - - [27/Aug/2020 12:20:21] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"#opening html page in flask\n",
47+
"\n",
48+
"from flask import Flask, render_template\n",
49+
"\n",
50+
"app = Flask(__name__)\n",
51+
"\n",
52+
"@app.route('/')\n",
53+
"def index():\n",
54+
" return render_template('first.html')\n",
55+
"\n",
56+
"if __name__ == '__main__':\n",
57+
" app.run()"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
62+
"execution_count": null,
63+
"metadata": {
64+
"collapsed": true
65+
},
66+
"outputs": [],
67+
"source": []
68+
}
69+
],
70+
"metadata": {
71+
"kernelspec": {
72+
"display_name": "Python 3",
73+
"language": "python",
74+
"name": "python3"
75+
},
76+
"language_info": {
77+
"codemirror_mode": {
78+
"name": "ipython",
79+
"version": 3
80+
},
81+
"file_extension": ".py",
82+
"mimetype": "text/x-python",
83+
"name": "python",
84+
"nbconvert_exporter": "python",
85+
"pygments_lexer": "ipython3",
86+
"version": "3.6.3"
87+
}
88+
},
89+
"nbformat": 4,
90+
"nbformat_minor": 2
91+
}

0 commit comments

Comments
 (0)