├── .gitignore ├── MainActivity.java ├── Procfile ├── README.md ├── activity_main.xml ├── app.py ├── model.pkl ├── requirements.txt ├── student-placement-predictor.ipynb └── students_placement.csv /.gitignore: -------------------------------------------------------------------------------- 1 | venv -------------------------------------------------------------------------------- /MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.mywbut.studentapp; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | import android.widget.EditText; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import com.android.volley.Request; 13 | import com.android.volley.RequestQueue; 14 | import com.android.volley.Response; 15 | import com.android.volley.VolleyError; 16 | import com.android.volley.toolbox.StringRequest; 17 | import com.android.volley.toolbox.Volley; 18 | 19 | import org.json.JSONException; 20 | import org.json.JSONObject; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | public class MainActivity extends AppCompatActivity { 26 | 27 | EditText cgpa,iq,profile_score; 28 | Button predict; 29 | TextView result; 30 | String url = "https://campusx-student-app.herokuapp.com/predict"; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | 37 | cgpa = findViewById(R.id.cgpa); 38 | iq = findViewById(R.id.iq); 39 | profile_score = findViewById(R.id.profile_score); 40 | predict = findViewById(R.id.predict); 41 | result = findViewById(R.id.result); 42 | 43 | predict.setOnClickListener(new View.OnClickListener() { 44 | @Override 45 | public void onClick(View view) { 46 | // hit the API -> Volley 47 | StringRequest stringRequest = new StringRequest(Request.Method.POST, url, 48 | new Response.Listener() { 49 | @Override 50 | public void onResponse(String response) { 51 | 52 | try { 53 | JSONObject jsonObject = new JSONObject(response); 54 | String data = jsonObject.getString("placement"); 55 | if(data.equals("1")){ 56 | result.setText("Placement Hoga"); 57 | }else{ 58 | result.setText("Placement Nahi Hoga"); 59 | } 60 | } catch (JSONException e) { 61 | e.printStackTrace(); 62 | } 63 | 64 | } 65 | }, 66 | new Response.ErrorListener() { 67 | @Override 68 | public void onErrorResponse(VolleyError error) { 69 | Toast.makeText(MainActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show(); 70 | } 71 | }){ 72 | 73 | @Override 74 | protected Map getParams(){ 75 | Map params = new HashMap(); 76 | params.put("cgpa",cgpa.getText().toString()); 77 | params.put("iq",iq.getText().toString()); 78 | params.put("profile_score",profile_score.getText().toString()); 79 | 80 | return params; 81 | } 82 | 83 | }; 84 | RequestQueue queue = Volley.newRequestQueue(MainActivity.this); 85 | queue.add(stringRequest); 86 | } 87 | }); 88 | } 89 | } -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deploy-ml-model-as-android-app 2 | Code to deploy ML model as an Android App 3 | -------------------------------------------------------------------------------- /activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 17 | 18 | 25 | 32 | 39 | 45 | 53 | 54 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask,request,jsonify 2 | import numpy as np 3 | import pickle 4 | 5 | model = pickle.load(open('model.pkl','rb')) 6 | 7 | app = Flask(__name__) 8 | 9 | @app.route('/') 10 | def index(): 11 | return "Hello world" 12 | 13 | @app.route('/predict',methods=['POST']) 14 | def predict(): 15 | cgpa = request.form.get('cgpa') 16 | iq = request.form.get('iq') 17 | profile_score = request.form.get('profile_score') 18 | 19 | input_query = np.array([[cgpa,iq,profile_score]]) 20 | 21 | result = model.predict(input_query)[0] 22 | 23 | return jsonify({'placement':str(result)}) 24 | 25 | if __name__ == '__main__': 26 | app.run(debug=True) -------------------------------------------------------------------------------- /model.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/campusx-official/deploy-ml-model-as-android-app/ef8e2164e9ead7316bf97643591fd319f3da27e8/model.pkl -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | numpy 3 | sklearn 4 | gunicorn -------------------------------------------------------------------------------- /student-placement-predictor.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "a69b3232", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np\n", 11 | "import pandas as pd" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 2, 17 | "id": "39097193", 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "df = pd.read_csv('students_placement.csv')" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 3, 27 | "id": "44ecb891", 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "(300, 4)" 34 | ] 35 | }, 36 | "execution_count": 3, 37 | "metadata": {}, 38 | "output_type": "execute_result" 39 | } 40 | ], 41 | "source": [ 42 | "df.shape" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 4, 48 | "id": "0102f6be", 49 | "metadata": {}, 50 | "outputs": [ 51 | { 52 | "data": { 53 | "text/html": [ 54 | "
\n", 55 | "\n", 68 | "\n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | "
cgpaiqprofile_scoreplaced
1764.60116710
777.1197491
798.4193781
766.9994731
1827.6692711
\n", 116 | "
" 117 | ], 118 | "text/plain": [ 119 | " cgpa iq profile_score placed\n", 120 | "176 4.60 116 71 0\n", 121 | "77 7.11 97 49 1\n", 122 | "79 8.41 93 78 1\n", 123 | "76 6.99 94 73 1\n", 124 | "182 7.66 92 71 1" 125 | ] 126 | }, 127 | "execution_count": 4, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "df.sample(5)" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 5, 139 | "id": "bebb8518", 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [ 143 | "X = df.drop(columns=['placed'])\n", 144 | "y = df['placed']" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 6, 150 | "id": "7bf7d3ce", 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "from sklearn.model_selection import train_test_split\n", 155 | "X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=2)" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": 22, 161 | "id": "08abd989", 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "0.8833333333333333" 168 | ] 169 | }, 170 | "execution_count": 22, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "from sklearn.ensemble import RandomForestClassifier\n", 177 | "from sklearn.metrics import accuracy_score\n", 178 | "\n", 179 | "rf = RandomForestClassifier()\n", 180 | "\n", 181 | "rf.fit(X_train,y_train)\n", 182 | "\n", 183 | "y_pred = rf.predict(X_test)\n", 184 | "\n", 185 | "accuracy_score(y_test,y_pred)" 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 7, 191 | "id": "38ec1510", 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "data": { 196 | "text/plain": [ 197 | "0.9" 198 | ] 199 | }, 200 | "execution_count": 7, 201 | "metadata": {}, 202 | "output_type": "execute_result" 203 | } 204 | ], 205 | "source": [ 206 | "from sklearn.neighbors import KNeighborsClassifier\n", 207 | "from sklearn.metrics import accuracy_score\n", 208 | "\n", 209 | "knn = KNeighborsClassifier(n_neighbors=5)\n", 210 | "\n", 211 | "knn.fit(X_train,y_train)\n", 212 | "\n", 213 | "y_pred = knn.predict(X_test)\n", 214 | "\n", 215 | "accuracy_score(y_test,y_pred)" 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 8, 221 | "id": "52ce0f1a", 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "import pickle \n", 226 | "pickle.dump(knn,open('model.pkl','wb'))" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": null, 232 | "id": "32eac8d0", 233 | "metadata": {}, 234 | "outputs": [], 235 | "source": [] 236 | } 237 | ], 238 | "metadata": { 239 | "kernelspec": { 240 | "display_name": "Python 3", 241 | "language": "python", 242 | "name": "python3" 243 | }, 244 | "language_info": { 245 | "codemirror_mode": { 246 | "name": "ipython", 247 | "version": 3 248 | }, 249 | "file_extension": ".py", 250 | "mimetype": "text/x-python", 251 | "name": "python", 252 | "nbconvert_exporter": "python", 253 | "pygments_lexer": "ipython3", 254 | "version": "3.8.8" 255 | } 256 | }, 257 | "nbformat": 4, 258 | "nbformat_minor": 5 259 | } 260 | -------------------------------------------------------------------------------- /students_placement.csv: -------------------------------------------------------------------------------- 1 | cgpa,iq,profile_score,placed 2 | 5.97,106,61,0 3 | 6.83,113,77,0 4 | 6.6,110,61,0 5 | 5.54,113,68,0 6 | 6.84,102,67,0 7 | 7.15,98,63,1 8 | 7.4,100,71,1 9 | 7.97,86,100,1 10 | 6.64,111,56,0 11 | 7.82,99,58,0 12 | 7.64,102,51,0 13 | 5.64,106,36,0 14 | 6.83,103,29,1 15 | 7.74,96,72,1 16 | 8.03,92,54,1 17 | 7.88,91,59,1 18 | 6.6,111,51,0 19 | 8.83,93,45,1 20 | 7.05,97,62,1 21 | 7.37,99,77,1 22 | 5.78,112,46,0 23 | 5.41,115,54,0 24 | 7.36,105,77,1 25 | 7.76,96,62,1 26 | 5.51,112,51,0 27 | 7.19,97,47,1 28 | 7.73,90,68,1 29 | 6.66,106,61,0 30 | 6.74,107,66,0 31 | 7.21,96,94,1 32 | 5.99,113,59,0 33 | 6.27,106,80,0 34 | 6.57,110,61,0 35 | 7.4,105,44,1 36 | 7.55,92,63,1 37 | 5.5,112,54,0 38 | 7.93,94,53,1 39 | 6.89,103,37,0 40 | 6.79,92,73,1 41 | 6.57,108,71,1 42 | 6.76,101,64,0 43 | 6.05,106,94,0 44 | 6.01,115,61,0 45 | 6.34,105,62,1 46 | 6.04,111,71,0 47 | 6.84,95,51,1 48 | 7.32,97,54,1 49 | 8.09,97,80,1 50 | 7.6,98,58,0 51 | 7.65,94,87,1 52 | 7.05,102,45,1 53 | 6.75,106,69,0 54 | 6.56,104,77,1 55 | 8.43,88,42,1 56 | 7.19,98,65,1 57 | 8.48,91,51,1 58 | 5.31,116,51,0 59 | 6.46,109,61,0 60 | 7.7,103,56,1 61 | 6.45,107,63,0 62 | 6.85,104,49,1 63 | 6.24,111,69,0 64 | 7.1,97,86,1 65 | 7.24,95,43,1 66 | 7.5,102,59,0 67 | 8.41,100,58,1 68 | 6.42,115,59,0 69 | 5.56,107,95,0 70 | 5.23,111,75,0 71 | 8.12,92,37,1 72 | 6.02,121,27,0 73 | 7.05,96,49,1 74 | 6.15,85,63,1 75 | 5.52,107,78,0 76 | 7.49,88,47,1 77 | 5.76,108,64,0 78 | 6.99,94,73,1 79 | 7.11,97,49,1 80 | 6.83,111,63,0 81 | 8.41,93,78,1 82 | 5.29,103,83,0 83 | 5.61,110,67,0 84 | 6.06,116,53,0 85 | 6.11,106,64,0 86 | 7.01,97,59,1 87 | 6.86,106,59,0 88 | 7.31,104,43,1 89 | 5.33,103,75,0 90 | 5.91,114,54,0 91 | 5.83,110,68,0 92 | 7.63,91,79,1 93 | 4.94,104,82,0 94 | 5.81,115,35,0 95 | 7.06,108,39,1 96 | 7.08,99,61,1 97 | 7.43,88,69,1 98 | 5.25,113,65,0 99 | 7.32,101,69,1 100 | 7.27,91,70,1 101 | 8.11,95,60,1 102 | 8.35,98,71,1 103 | 5.83,106,60,0 104 | 8.21,94,52,1 105 | 5.61,108,55,0 106 | 8.08,94,49,1 107 | 7.35,93,45,1 108 | 5.61,108,74,0 109 | 6.89,105,76,1 110 | 7.45,108,65,0 111 | 6.23,113,65,0 112 | 7.4,111,46,0 113 | 5.67,112,67,0 114 | 6.75,111,27,0 115 | 8.25,92,67,1 116 | 5.89,108,72,0 117 | 7.3,101,50,1 118 | 6.61,105,53,0 119 | 7.41,110,57,0 120 | 4.8,109,25,0 121 | 5.54,118,60,0 122 | 7.93,95,50,1 123 | 5.54,114,78,0 124 | 7.71,109,50,0 125 | 6.26,97,82,1 126 | 7.55,100,57,1 127 | 6.27,110,38,0 128 | 6.73,101,70,0 129 | 6.65,106,45,1 130 | 8.0,92,59,1 131 | 5.8,116,50,0 132 | 6.69,93,72,1 133 | 7.08,95,43,1 134 | 6.99,116,63,0 135 | 8.21,89,51,1 136 | 6.58,113,57,0 137 | 6.54,97,43,0 138 | 7.54,98,67,1 139 | 9.07,84,70,1 140 | 8.8,83,62,1 141 | 7.54,96,71,1 142 | 6.34,105,65,0 143 | 5.05,109,58,0 144 | 6.01,106,72,0 145 | 7.0,100,62,1 146 | 7.01,99,64,1 147 | 6.13,107,78,0 148 | 6.84,96,32,1 149 | 8.11,93,72,1 150 | 7.54,90,53,1 151 | 5.86,99,87,0 152 | 5.67,103,68,0 153 | 5.7,118,65,0 154 | 8.12,103,26,1 155 | 6.27,107,59,1 156 | 5.56,117,68,1 157 | 6.68,110,50,0 158 | 5.71,117,76,0 159 | 5.19,108,69,0 160 | 4.9,110,44,0 161 | 5.84,105,67,1 162 | 5.65,116,70,0 163 | 6.11,111,44,0 164 | 6.0,101,55,1 165 | 5.52,116,58,0 166 | 6.02,107,69,0 167 | 7.52,106,73,0 168 | 8.17,94,54,1 169 | 5.13,114,83,0 170 | 8.12,94,72,1 171 | 6.34,99,52,0 172 | 5.76,103,67,0 173 | 8.71,88,58,1 174 | 6.62,96,37,1 175 | 7.22,94,58,1 176 | 7.81,95,59,1 177 | 6.4,105,55,0 178 | 4.6,116,71,0 179 | 6.66,105,67,1 180 | 5.77,105,47,0 181 | 5.67,109,54,0 182 | 8.04,89,48,1 183 | 6.17,115,52,0 184 | 7.66,92,71,1 185 | 6.69,104,74,1 186 | 8.49,89,70,1 187 | 6.88,92,59,1 188 | 7.52,110,51,0 189 | 8.54,88,67,1 190 | 6.97,101,68,1 191 | 6.04,104,30,0 192 | 7.21,96,59,1 193 | 5.34,104,98,0 194 | 5.6,109,57,0 195 | 8.37,107,58,0 196 | 7.04,96,47,1 197 | 7.97,96,76,1 198 | 6.76,108,72,1 199 | 6.32,107,68,0 200 | 6.64,98,49,1 201 | 5.67,111,69,0 202 | 8.37,91,63,1 203 | 7.83,97,43,1 204 | 4.97,116,72,0 205 | 8.47,87,72,1 206 | 6.55,107,59,0 207 | 6.7,102,58,1 208 | 5.97,116,23,0 209 | 7.65,93,35,1 210 | 6.44,114,42,0 211 | 7.24,95,66,1 212 | 7.12,88,48,1 213 | 5.64,110,51,0 214 | 6.89,88,98,1 215 | 6.44,102,54,0 216 | 5.8,107,92,0 217 | 7.0,104,48,0 218 | 6.47,108,41,0 219 | 7.21,104,76,1 220 | 6.54,109,51,1 221 | 7.59,87,68,1 222 | 7.23,89,58,1 223 | 8.25,96,57,1 224 | 7.38,99,64,1 225 | 5.62,106,78,0 226 | 5.77,112,62,0 227 | 7.42,92,63,1 228 | 6.49,109,54,0 229 | 7.07,94,49,1 230 | 8.07,92,62,1 231 | 9.3,85,68,1 232 | 9.05,94,67,1 233 | 6.02,107,74,0 234 | 5.85,114,68,0 235 | 6.97,105,53,1 236 | 7.86,101,70,0 237 | 5.12,105,68,0 238 | 5.86,105,43,0 239 | 7.12,107,62,0 240 | 8.29,89,70,1 241 | 6.92,99,85,1 242 | 7.49,95,64,1 243 | 8.56,102,63,1 244 | 7.24,113,72,0 245 | 5.76,120,64,0 246 | 6.49,108,45,1 247 | 8.52,99,58,1 248 | 6.14,110,57,0 249 | 6.75,92,39,1 250 | 5.94,101,38,1 251 | 6.53,90,99,1 252 | 5.49,110,58,0 253 | 7.62,97,43,1 254 | 6.88,94,71,1 255 | 8.84,91,81,1 256 | 7.34,97,51,1 257 | 6.34,112,54,0 258 | 7.65,98,50,1 259 | 5.54,107,76,0 260 | 5.76,114,52,0 261 | 5.13,114,54,0 262 | 7.48,100,54,1 263 | 7.51,90,69,1 264 | 6.79,102,55,1 265 | 6.8,103,52,0 266 | 7.12,96,54,1 267 | 6.34,105,65,0 268 | 7.26,110,56,0 269 | 6.91,112,45,0 270 | 7.42,98,49,1 271 | 7.88,97,31,1 272 | 5.51,114,51,0 273 | 7.03,97,50,0 274 | 5.94,108,28,0 275 | 8.13,91,35,1 276 | 5.49,110,47,0 277 | 6.29,102,59,1 278 | 6.89,104,81,1 279 | 5.19,116,86,0 280 | 5.91,108,45,0 281 | 7.14,99,70,1 282 | 6.85,102,67,1 283 | 7.6,103,64,0 284 | 8.26,92,69,1 285 | 8.35,96,89,1 286 | 7.06,93,44,1 287 | 8.7,96,56,1 288 | 6.98,105,54,0 289 | 5.28,111,52,0 290 | 7.15,106,78,1 291 | 5.83,104,51,0 292 | 5.84,112,32,0 293 | 7.83,101,41,1 294 | 6.8,109,41,0 295 | 6.86,110,63,0 296 | 7.18,106,61,0 297 | 6.44,107,54,0 298 | 6.09,108,52,0 299 | 7.68,101,70,1 300 | 7.0,90,28,1 301 | 4.79,118,70,0 302 | --------------------------------------------------------------------------------