harshiv commited on
Commit
4b45c49
·
1 Parent(s): e3a4d46

Upload Untitled2.ipynb

Browse files
Files changed (1) hide show
  1. Untitled2.ipynb +57 -3
Untitled2.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 2,
6
  "id": "2a0f61a3",
7
  "metadata": {},
8
  "outputs": [
@@ -10,12 +10,43 @@
10
  "name": "stdout",
11
  "output_type": "stream",
12
  "text": [
13
- "Accuracy: 0.8417508417508418\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ]
15
  }
16
  ],
17
  "source": [
18
  "import pandas as pd\n",
 
 
19
  "from sklearn.compose import ColumnTransformer\n",
20
  "from sklearn.ensemble import RandomForestClassifier\n",
21
  "from sklearn.impute import SimpleImputer\n",
@@ -60,7 +91,30 @@
60
  "\n",
61
  "# Evaluate the model\n",
62
  "accuracy = pipeline.score(X_test, y_test)\n",
63
- "print('Accuracy:', accuracy)\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  ]
65
  },
66
  {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": 3,
6
  "id": "2a0f61a3",
7
  "metadata": {},
8
  "outputs": [
 
10
  "name": "stdout",
11
  "output_type": "stream",
12
  "text": [
13
+ "Accuracy: 0.8417508417508418\n",
14
+ " * Serving Flask app \"__main__\" (lazy loading)\n",
15
+ " * Environment: production\n",
16
+ "\u001b[31m WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
17
+ "\u001b[2m Use a production WSGI server instead.\u001b[0m\n",
18
+ " * Debug mode: on\n"
19
+ ]
20
+ },
21
+ {
22
+ "name": "stderr",
23
+ "output_type": "stream",
24
+ "text": [
25
+ " * Restarting with watchdog (windowsapi)\n"
26
+ ]
27
+ },
28
+ {
29
+ "ename": "SystemExit",
30
+ "evalue": "1",
31
+ "output_type": "error",
32
+ "traceback": [
33
+ "An exception has occurred, use %tb to see the full traceback.\n",
34
+ "\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 1\n"
35
+ ]
36
+ },
37
+ {
38
+ "name": "stderr",
39
+ "output_type": "stream",
40
+ "text": [
41
+ "C:\\Users\\91958\\anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3377: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
42
+ " warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
43
  ]
44
  }
45
  ],
46
  "source": [
47
  "import pandas as pd\n",
48
+ "from flask import Flask, request, jsonify\n",
49
+ "\n",
50
  "from sklearn.compose import ColumnTransformer\n",
51
  "from sklearn.ensemble import RandomForestClassifier\n",
52
  "from sklearn.impute import SimpleImputer\n",
 
91
  "\n",
92
  "# Evaluate the model\n",
93
  "accuracy = pipeline.score(X_test, y_test)\n",
94
+ "print('Accuracy:', accuracy)\n",
95
+ "\n",
96
+ "# Create Flask app\n",
97
+ "app = Flask(__name__)\n",
98
+ "\n",
99
+ "# Define API route for making predictions\n",
100
+ "@app.route('/predict', methods=['POST'])\n",
101
+ "def predict():\n",
102
+ " # Get input data from request\n",
103
+ " data = request.get_json()\n",
104
+ "\n",
105
+ " # Convert input data to dataframe\n",
106
+ " input_data = pd.DataFrame(data, index=[0])\n",
107
+ "\n",
108
+ " # Make predictions using the trained pipeline\n",
109
+ " predictions = pipeline.predict(input_data)\n",
110
+ "\n",
111
+ " # Prepare response\n",
112
+ " response = {'prediction': predictions[0]}\n",
113
+ " return jsonify(response)\n",
114
+ "\n",
115
+ "# Run the Flask app\n",
116
+ "if __name__ == '__main__':\n",
117
+ " app.run(debug=True)\n"
118
  ]
119
  },
120
  {