Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-193 User-friendly enhanced machine learning-based railway management system
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-193
2021-193 User-friendly enhanced machine learning-based railway management system
Commits
ea297840
Commit
ea297840
authored
Jul 04, 2021
by
Palliyaguruge T.L.P-IT18001280
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
e6e972d9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
875 additions
and
0 deletions
+875
-0
Untitled.ipynb
Untitled.ipynb
+875
-0
No files found.
Untitled.ipynb
0 → 100644
View file @
ea297840
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b2b62b44",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"from tqdm.notebook import tqdm\n",
"from collections import Counter\n",
"from sklearn import metrics\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "11016a95",
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "cec68912",
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv(\"Railway_Passenger_Final.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0870d81a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Country</th>\n",
" <th>Disability</th>\n",
" <th>Class</th>\n",
" <th>GenderNo</th>\n",
" <th>LineNo</th>\n",
" <th>SeatLine</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>38</td>\n",
" <td>169</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>33</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>52</td>\n",
" <td>186</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>52</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>33</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7387</th>\n",
" <td>56</td>\n",
" <td>9</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7388</th>\n",
" <td>48</td>\n",
" <td>165</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7389</th>\n",
" <td>16</td>\n",
" <td>77</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7390</th>\n",
" <td>14</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7391</th>\n",
" <td>38</td>\n",
" <td>77</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>5</td>\n",
" <td>9</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7392 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" Age Country Disability Class GenderNo LineNo SeatLine\n",
"0 38 169 0 1 1 3 6\n",
"1 33 165 0 2 1 1 4\n",
"2 52 186 0 1 2 6 8\n",
"3 52 165 0 2 2 6 8\n",
"4 33 165 0 2 1 1 4\n",
"... ... ... ... ... ... ... ...\n",
"7387 56 9 1 2 2 1 1\n",
"7388 48 165 1 1 1 5 6\n",
"7389 16 77 0 1 1 4 10\n",
"7390 14 165 0 1 1 5 4\n",
"7391 38 77 0 1 1 5 9\n",
"\n",
"[7392 rows x 7 columns]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "dc782f98",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Country</th>\n",
" <th>Disability</th>\n",
" <th>Class</th>\n",
" <th>GenderNo</th>\n",
" <th>LineNo</th>\n",
" <th>SeatLine</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [Age, Country, Disability, Class, GenderNo, LineNo, SeatLine]\n",
"Index: []"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data[pd.isnull(data).any(axis=1)]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "b7d860da",
"metadata": {},
"outputs": [],
"source": [
"Y = data.SeatLine.copy()\n",
"X = data.drop(['SeatLine'], axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "b85ff8d6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4 1928\n",
"7 1842\n",
"5 1015\n",
"6 915\n",
"3 742\n",
"8 679\n",
"2 76\n",
"9 68\n",
"10 64\n",
"1 63\n",
"Name: SeatLine, dtype: int64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data['SeatLine'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d498a8ce",
"metadata": {},
"outputs": [],
"source": [
"def pearson(X,Y):\n",
" correlation_matrix = np.corrcoef(X,Y)\n",
" return correlation_matrix[0,1]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "c041cb4c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.0035806135588234236\n",
"-0.009099476534655794\n",
"0.01109999125101634\n",
"0.7410300176783485\n"
]
}
],
"source": [
"print(pearson(X.Age, Y))\n",
"print(pearson(X.Country, Y))\n",
"print(pearson(X.Disability, Y))\n",
"print(pearson(X.GenderNo, Y))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "094a84fa",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.09118144742552847\n",
"-0.627520395988806\n",
"0.0036254166615416767\n",
"0.6412361822996381\n"
]
}
],
"source": [
"print(np.cov(X.Age, Y)[0,1])\n",
"print(np.cov(X.Country, Y)[0,1])\n",
"print(np.cov(X.Disability, Y)[0,1])\n",
"print(np.cov(X.GenderNo, Y)[0,1])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "c001994a",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Age</th>\n",
" <th>Country</th>\n",
" <th>Disability</th>\n",
" <th>Class</th>\n",
" <th>GenderNo</th>\n",
" <th>LineNo</th>\n",
" <th>SeatLine</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>38</td>\n",
" <td>169</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>33</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>52</td>\n",
" <td>186</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>52</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>33</td>\n",
" <td>165</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Country Disability Class GenderNo LineNo SeatLine\n",
"0 38 169 0 1 1 3 6\n",
"1 33 165 0 2 1 1 4\n",
"2 52 186 0 1 2 6 8\n",
"3 52 165 0 2 2 6 8\n",
"4 33 165 0 2 1 1 4"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "0de26781",
"metadata": {},
"outputs": [],
"source": [
"finalFeaturedDataset = data[['Age', 'Country','Disability','Class','GenderNo']]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0042371f",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler\n",
"scaler = MinMaxScaler(feature_range=(0,1)) \n",
"\n",
"#assign scaler to column:\n",
"data = pd.DataFrame(scaler.fit_transform(finalFeaturedDataset), columns=finalFeaturedDataset.columns)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "c5b4937c",
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.20, random_state=123)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "bb0a6886",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.svm import SVC, LinearSVC"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "da921c77",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1dad2d9530bd43c7b6abdadac29fdfa4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#X_train, X_test, Y_train, Y_test,Y_pred\n",
"\n",
"linear_svc = LinearSVC()\n",
"for i in tqdm(range(10)):\n",
" linear_svc.fit(X_train, Y_train)\n",
"\n",
"Y_pred = linear_svc.predict(X_test)\n",
"\n",
"acc_linear_svc = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_linear_svc = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_linear_svc = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_linear_svc = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "a79ef29a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.2738336713995943\n",
"Precision: 0.35832646520146516\n",
"Recall: 0.11236006475404055\n",
"f1-score: 0.06488542557685116\n"
]
}
],
"source": [
"print(\"Accuracy:\", metrics.accuracy_score(Y_test, Y_pred))\n",
"print(\"Precision:\", metrics.precision_score(Y_test, Y_pred,average='macro'))\n",
"print(\"Recall:\", metrics.recall_score(Y_test, Y_pred,average='macro'))\n",
"print(\"f1-score:\", metrics.f1_score(Y_test,Y_pred, average='macro'))"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "ee385170",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "a1bb8f06",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0df9475381644df594ce15d28dfe72a5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#X_train, X_test, Y_train, Y_test\n",
"\n",
"knn = KNeighborsClassifier(n_neighbors = 2)\n",
"for i in tqdm(range(10)):\n",
" knn.fit(X_train, Y_train) \n",
"Y_pred = knn.predict(X_test)\n",
"\n",
"\n",
"acc_knn = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_knn = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_knn = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_knn = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "f25572c9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.9350912778904665\n",
"Precision: 0.8078615566477673\n",
"Recall: 0.717261850491169\n",
"f1-score: 0.7114544346026009\n"
]
}
],
"source": [
"print(\"Accuracy:\", metrics.accuracy_score(Y_test, Y_pred))\n",
"print(\"Precision:\", metrics.precision_score(Y_test, Y_pred,average='macro'))\n",
"print(\"Recall:\", metrics.recall_score(Y_test, Y_pred,average='macro'))\n",
"print(\"f1-score:\", metrics.f1_score(Y_test,Y_pred, average='macro'))"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "ac6748e8",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.ensemble import RandomForestClassifier"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "2f48f36e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d2d315141cb1411ebf65727eae04efc9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rf = RandomForestClassifier()\n",
"for i in tqdm(range(10)):\n",
" rf.fit(X_train,Y_train)\n",
"Y_pred = rf.predict(X_test)\n",
"\n",
"acc_rf = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_rf = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_rf = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_rf = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "fc1ebd91",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.9445571331981069\n",
"Precision: 0.7413751655908479\n",
"Recall: 0.7385777558448817\n",
"f1-score: 0.7368101892594321\n"
]
}
],
"source": [
"print(\"Accuracy:\", metrics.accuracy_score(Y_test, Y_pred))\n",
"print(\"Precision:\", metrics.precision_score(Y_test, Y_pred,average='macro'))\n",
"print(\"Recall:\", metrics.recall_score(Y_test, Y_pred,average='macro'))\n",
"print(\"f1-score:\", metrics.f1_score(Y_test,Y_pred, average='macro'))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "e7086868",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'acc_log' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-24-d117186c3a1d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m results = pd.DataFrame({\n\u001b[0;32m 2\u001b[0m \u001b[1;34m'Model'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;34m'Support Vector Machines'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'KNN'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Logistic Regression'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'Random Forest'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;34m'Accuracy'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0macc_linear_svc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0macc_knn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0macc_log\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0macc_rf\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[1;34m'Precission'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mpre_linear_svc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpre_knn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpre_log\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mpre_rf\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;34m'Recall'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mrecall_linear_svc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecall_knn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecall_log\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrecall_rf\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'acc_log' is not defined"
]
}
],
"source": [
"results = pd.DataFrame({\n",
" 'Model': ['Support Vector Machines', 'KNN', 'Random Forest'],\n",
" 'Accuracy': [acc_linear_svc, acc_knn, acc_rf],\n",
" 'Precission': [pre_linear_svc, pre_knn, pre_log, pre_rf],\n",
" 'Recall': [recall_linear_svc, recall_knn, recall_log, recall_rf],\n",
" 'F1-Score': [f1_linear_svc, f1_knn, f1_log, f1_rf]})\n",
"\n",
"result_df = results.sort_values(by='Accuracy', ascending=False)\n",
"result_df = result_df.set_index('Accuracy')\n",
"result_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edd5c2db",
"metadata": {},
"outputs": [],
"source": [
"results= pd.DataFrame({'Model': ['S V M', 'KNN', 'Logistic R','Random Forest'], 'Score': [acc_linear_svc, acc_knn, acc_log, acc_rf ]})\n",
"\n",
"ax = results.plot.bar(x='Model', y='Score', rot=90)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3148b25",
"metadata": {},
"outputs": [],
"source": [
"#Save the Decision Tree strained modelusing pickle\n",
"import pickle\n",
"with open('ab_classifier_Random_forest', 'wb') as picklefile:\n",
" pickle.dump(rf,picklefile)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "698412e2",
"metadata": {},
"outputs": [],
"source": [
"with open('ab_classifier_Random_forest', 'rb') as training_model:\n",
" model6 = pickle.load(training_model)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5964b95",
"metadata": {},
"outputs": [],
"source": [
"def start_questionnaire():\n",
" my_predictors = []\n",
" parameters=['Age', 'Count','Country','Disability','Class','GenderNo']\n",
" \n",
" print('Input Passenger Information:')\n",
" \n",
" age = input(\"Passenger age: >>> \") \n",
" my_predictors.append(age)\n",
" count = input(\"Passenger Count: >>> \") \n",
" my_predictors.append(count)\n",
" country = input(\"Passenger Country: >>> \") \n",
" my_predictors.append(country)\n",
" disability = input(\"Any Disability: >>> \")\n",
" my_predictors.append(disability)\n",
" classNo = input(\"Choice Class: >>> \")\n",
" my_predictors.append(classNo)\n",
" gender = input(\"Passenger Gender: >>> \")\n",
" my_predictors.append(gender)\n",
" \n",
" my_data = dict(zip(parameters, my_predictors))\n",
" my_df = pd.DataFrame(my_data, index=[0])\n",
" scaler = MinMaxScaler(feature_range=(1,6))\n",
" \n",
" # assign scaler to column:\n",
" my_df_scaled = pd.DataFrame(scaler.fit_transform(my_df), columns=my_df.columns)\n",
" my_y_pred = model6.predict(my_df)\n",
" print('\\n')\n",
" print('Result:')\n",
" print(my_y_pred);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1b355f4",
"metadata": {},
"outputs": [],
"source": [
"start_questionnaire()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e622dcf5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment