Delete Untitled2.ipynb
Browse files- Untitled2.ipynb +0 -158
Untitled2.ipynb
DELETED
@@ -1,158 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": 3,
|
6 |
-
"id": "2a0f61a3",
|
7 |
-
"metadata": {},
|
8 |
-
"outputs": [
|
9 |
-
{
|
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",
|
53 |
-
"from sklearn.model_selection import train_test_split\n",
|
54 |
-
"from sklearn.pipeline import Pipeline\n",
|
55 |
-
"from sklearn.preprocessing import LabelEncoder, StandardScaler\n",
|
56 |
-
"\n",
|
57 |
-
"# Load the CSV data\n",
|
58 |
-
"data = pd.read_csv('dataset.csv')\n",
|
59 |
-
"\n",
|
60 |
-
"# Split the data into features and labels\n",
|
61 |
-
"X = data.drop('PlacedOrNot', axis=1)\n",
|
62 |
-
"y = data['PlacedOrNot']\n",
|
63 |
-
"\n",
|
64 |
-
"# Encode categorical features\n",
|
65 |
-
"categorical_features = ['HistoryOfBacklogs']\n",
|
66 |
-
"for feature in categorical_features:\n",
|
67 |
-
" encoder = LabelEncoder()\n",
|
68 |
-
" X[feature] = encoder.fit_transform(X[feature])\n",
|
69 |
-
"\n",
|
70 |
-
"# Split the data into training and testing sets\n",
|
71 |
-
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
|
72 |
-
"\n",
|
73 |
-
"# Create the pipeline\n",
|
74 |
-
"numerical_features = ['Internships', 'CGPA']\n",
|
75 |
-
"numerical_transformer = StandardScaler()\n",
|
76 |
-
"categorical_features = [ 'HistoryOfBacklogs']\n",
|
77 |
-
"categorical_transformer = SimpleImputer(strategy='most_frequent')\n",
|
78 |
-
"preprocessor = ColumnTransformer(\n",
|
79 |
-
" transformers=[\n",
|
80 |
-
" ('num', numerical_transformer, numerical_features),\n",
|
81 |
-
" ('cat', categorical_transformer, categorical_features)\n",
|
82 |
-
" ])\n",
|
83 |
-
"\n",
|
84 |
-
"pipeline = Pipeline([\n",
|
85 |
-
" ('preprocessor', preprocessor),\n",
|
86 |
-
" ('classifier', RandomForestClassifier(random_state=42))\n",
|
87 |
-
"])\n",
|
88 |
-
"\n",
|
89 |
-
"# Train the model\n",
|
90 |
-
"pipeline.fit(X_train, y_train)\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 |
-
{
|
121 |
-
"cell_type": "code",
|
122 |
-
"execution_count": null,
|
123 |
-
"id": "8e941b77",
|
124 |
-
"metadata": {},
|
125 |
-
"outputs": [],
|
126 |
-
"source": []
|
127 |
-
},
|
128 |
-
{
|
129 |
-
"cell_type": "code",
|
130 |
-
"execution_count": null,
|
131 |
-
"id": "4a2788a3",
|
132 |
-
"metadata": {},
|
133 |
-
"outputs": [],
|
134 |
-
"source": []
|
135 |
-
}
|
136 |
-
],
|
137 |
-
"metadata": {
|
138 |
-
"kernelspec": {
|
139 |
-
"display_name": "Python 3 (ipykernel)",
|
140 |
-
"language": "python",
|
141 |
-
"name": "python3"
|
142 |
-
},
|
143 |
-
"language_info": {
|
144 |
-
"codemirror_mode": {
|
145 |
-
"name": "ipython",
|
146 |
-
"version": 3
|
147 |
-
},
|
148 |
-
"file_extension": ".py",
|
149 |
-
"mimetype": "text/x-python",
|
150 |
-
"name": "python",
|
151 |
-
"nbconvert_exporter": "python",
|
152 |
-
"pygments_lexer": "ipython3",
|
153 |
-
"version": "3.9.12"
|
154 |
-
}
|
155 |
-
},
|
156 |
-
"nbformat": 4,
|
157 |
-
"nbformat_minor": 5
|
158 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|