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
db02e3a7
Commit
db02e3a7
authored
Jul 04, 2021
by
Mihiranga G.L.V - IT18500790
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
a8a24fab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
958 additions
and
0 deletions
+958
-0
Railway_Line_Predict.ipynb
Railway_Line_Predict.ipynb
+958
-0
No files found.
Railway_Line_Predict.ipynb
0 → 100644
View file @
db02e3a7
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2c445b47",
"metadata": {},
"outputs": [],
"source": [
"#Import All libraries for Prediction\n",
"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.model_selection import train_test_split\n",
"from sklearn.metrics import classification_report,confusion_matrix"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "adcb4ca1",
"metadata": {},
"outputs": [],
"source": [
"#Filter Warning messages\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2e97a069",
"metadata": {},
"outputs": [],
"source": [
"#Import Passenger's Dataset and Assign that dataset to Variable \n",
"PassData = pd.read_csv(\"Passenger_Travel_Line_Data.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "fae02b53",
"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>Count</th>\n",
" <th>Country</th>\n",
" <th>GenderNo</th>\n",
" <th>LineNo</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [Age, Count, Country, GenderNo, LineNo]\n",
"Index: []"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PassData[pd.isnull(PassData).any(axis=1)]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "83755e8a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 3\n",
"1 1\n",
"2 6\n",
"3 6\n",
"4 1\n",
" ..\n",
"7387 1\n",
"7388 5\n",
"7389 4\n",
"7390 5\n",
"7391 5\n",
"Name: LineNo, Length: 7392, dtype: int64\n"
]
}
],
"source": [
"#Y feature (Line No) Assign to Y variable\n",
"Y = PassData.LineNo.copy()\n",
"print(Y)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "3c434d28",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Age Count Country GenderNo\n",
"0 38 7 169 1\n",
"1 33 1 165 1\n",
"2 52 6 186 2\n",
"3 52 8 165 2\n",
"4 33 4 165 1\n",
"... ... ... ... ...\n",
"7387 56 7 9 2\n",
"7388 48 3 165 1\n",
"7389 16 4 77 1\n",
"7390 14 6 165 1\n",
"7391 38 3 77 1\n",
"\n",
"[7392 rows x 4 columns]\n"
]
}
],
"source": [
"#X feature (Passenger age, Passenger Country, Passengers count, Passenger Gender) Assign to Y variable\n",
"X = PassData.drop(['LineNo'], axis=1)\n",
"print(X)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "aa6eb91f",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"1 3611\n",
"2 1941\n",
"6 1263\n",
"5 178\n",
"4 169\n",
"3 168\n",
"7 62\n",
"Name: LineNo, dtype: int64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Data row count for each line\n",
"PassData['LineNo'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f8ad1a87",
"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": "ff7c07bb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.29489433997181086\n",
"0.12408172469911788\n",
"-0.3019730376888903\n",
"0.001401546695404602\n"
]
}
],
"source": [
"print(pearson(X.Age, Y))\n",
"print(pearson(X.Count, Y))\n",
"print(pearson(X.Country, Y))\n",
"print(pearson(X.GenderNo, Y))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "865e647a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8.251627549828065\n",
"0.7795532262240084\n",
"-22.882514934947803\n",
"0.0013326433634917101\n"
]
}
],
"source": [
"print(np.cov(X.Age, Y)[0,1])\n",
"print(np.cov(X.Count, Y)[0,1])\n",
"print(np.cov(X.Country, Y)[0,1])\n",
"print(np.cov(X.GenderNo, Y)[0,1])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "62dff0f9",
"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>Count</th>\n",
" <th>Country</th>\n",
" <th>GenderNo</th>\n",
" <th>LineNo</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>38</td>\n",
" <td>7</td>\n",
" <td>169</td>\n",
" <td>1</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>33</td>\n",
" <td>1</td>\n",
" <td>165</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>52</td>\n",
" <td>6</td>\n",
" <td>186</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>52</td>\n",
" <td>8</td>\n",
" <td>165</td>\n",
" <td>2</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>33</td>\n",
" <td>4</td>\n",
" <td>165</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Age Count Country GenderNo LineNo\n",
"0 38 7 169 1 3\n",
"1 33 1 165 1 1\n",
"2 52 6 186 2 6\n",
"3 52 8 165 2 6\n",
"4 33 4 165 1 1"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"PassData.head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "8ed8fa4a",
"metadata": {},
"outputs": [],
"source": [
"finalFeaturedDataset = PassData[['Age', 'Count','Country','GenderNo']]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "6dcb7e74",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.preprocessing import MinMaxScaler\n",
"scaler = MinMaxScaler(feature_range=(0,1)) \n",
"\n",
"#assign scaler to column:\n",
"PassData = pd.DataFrame(scaler.fit_transform(finalFeaturedDataset), columns=finalFeaturedDataset.columns)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "f707600c",
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.30, random_state=123)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b689e6a7",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LogisticRegression"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "8deca7e2",
"metadata": {},
"outputs": [],
"source": [
"model = LogisticRegression()\n",
"model.fit(X_train, Y_train)\n",
"\n",
"Y_pred = pd.Series(model.predict(X_test))\n",
"\n",
"Y_test = Y_test.reset_index(drop=True)\n",
"Z = pd.concat([Y_test, Y_pred], axis = 1)\n",
"Z.columns = ['True', 'Prediction']\n",
"\n",
"acc_log = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_log = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_log = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_log = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "0177e879",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.6262398557258791\n",
"Precision: 0.24419142446879588\n",
"Recall: 0.26669667105604467\n",
"f1-score: 0.2532355511236177\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": "markdown",
"id": "d563d7ef",
"metadata": {},
"source": [
"# Support Vector Machine Algorithm"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f1b4e2ca",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.svm import SVC, LinearSVC"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "d8de5898",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09e9c47220984de082d0399855bc1607",
"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": 20,
"id": "cd61bc74",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.5365193868349865\n",
"Precision: 0.2589134336854379\n",
"Recall: 0.28523216312749744\n",
"f1-score: 0.24436669759464053\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": "markdown",
"id": "0e36188a",
"metadata": {},
"source": [
"# Naive Bayes Algorithm"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "64b800fc",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.naive_bayes import GaussianNB"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "b28b868a",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2bbd68e465f24b8191123ad89ba67080",
"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",
"gaussian = GaussianNB() \n",
"for i in tqdm(range(10)):\n",
" gaussian.fit(X_train, Y_train) \n",
"Y_pred = gaussian.predict(X_test)\n",
"\n",
"acc_gaussian = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_gaussian = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_gaussian = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_gaussian = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "229aeefe",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.8214607754733995\n",
"Precision: 0.3975998841137974\n",
"Recall: 0.4016636978863704\n",
"f1-score: 0.3979258465031035\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": "markdown",
"id": "651501da",
"metadata": {},
"source": [
"# Decision Tree Algorithm"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "7fb9cf66",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import DecisionTreeClassifier"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "713d1ce9",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "27ac4b63b5d740d5b80bf7557bfc4d04",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"decision_tree = DecisionTreeClassifier() \n",
"for i in tqdm(range(10)):\n",
" decision_tree.fit(X_train, Y_train) \n",
"Y_pred = decision_tree.predict(X_test)\n",
"\n",
"acc_decision = metrics.accuracy_score(Y_test, Y_pred)\n",
"pre_decision = metrics.precision_score(Y_test,Y_pred, average='macro')\n",
"recall_decision = metrics.recall_score(Y_test,Y_pred, average='macro')\n",
"f1_decision = metrics.f1_score(Y_test,Y_pred, average='macro')"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "d7f314f9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[1091 0 2 4 3 3 2]\n",
" [ 3 544 2 3 4 1 2]\n",
" [ 2 6 39 4 2 1 2]\n",
" [ 3 2 3 28 5 2 3]\n",
" [ 3 4 3 0 39 2 1]\n",
" [ 5 1 2 2 2 359 5]\n",
" [ 6 4 5 2 3 2 2]]\n"
]
}
],
"source": [
"print(confusion_matrix(Y_test, Y_pred))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "167f968d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 0.9477006311992786\n",
"Precision: 0.722550436699368\n",
"Recall: 0.7219630680336654\n",
"f1-score: 0.721422594292315\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": "markdown",
"id": "9d084280",
"metadata": {},
"source": [
"# Each Model Accuracy Level For Railway Line Predict"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "d2a2e1ea",
"metadata": {
"scrolled": true
},
"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>Model</th>\n",
" <th>Precission</th>\n",
" <th>Recall</th>\n",
" <th>F1-Score</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Accuracy</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0.947701</th>\n",
" <td>Decision Tree</td>\n",
" <td>0.722550</td>\n",
" <td>0.721963</td>\n",
" <td>0.721423</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0.821461</th>\n",
" <td>Naive Bayes</td>\n",
" <td>0.397600</td>\n",
" <td>0.401664</td>\n",
" <td>0.397926</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0.626240</th>\n",
" <td>Logistic Regression</td>\n",
" <td>0.244191</td>\n",
" <td>0.266697</td>\n",
" <td>0.253236</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0.536519</th>\n",
" <td>Support Vector Machines</td>\n",
" <td>0.258913</td>\n",
" <td>0.285232</td>\n",
" <td>0.244367</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Model Precission Recall F1-Score\n",
"Accuracy \n",
"0.947701 Decision Tree 0.722550 0.721963 0.721423\n",
"0.821461 Naive Bayes 0.397600 0.401664 0.397926\n",
"0.626240 Logistic Regression 0.244191 0.266697 0.253236\n",
"0.536519 Support Vector Machines 0.258913 0.285232 0.244367"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"results = pd.DataFrame({\n",
" 'Model': ['Support Vector Machines', 'Logistic Regression','Naive Bayes', \n",
" 'Decision Tree', ],\n",
" 'Accuracy': [acc_linear_svc, acc_log, \n",
" acc_gaussian, acc_decision],\n",
" 'Precission': [pre_linear_svc, pre_log, \n",
" pre_gaussian, pre_decision],\n",
" 'Recall': [recall_linear_svc, recall_log, \n",
" recall_gaussian, recall_decision],\n",
" 'F1-Score': [f1_linear_svc, f1_log, \n",
" f1_gaussian, f1_decision]})\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": 29,
"id": "0336f802",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAE/CAYAAABW/Dj8AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAaKklEQVR4nO3df5SdVX3v8ffHBAnywwpJXUrEoAKCJkANaf1RpQoRSi2txRuoWovt5XJVKrWrFW1t/dlltb0tpbQYK02tVrQXbkVEoVovXlulSQD5IYIsUBjhXgkVQSRC8Hv/OM/AOEySk8xMnjk779das2ae/Txz5nvOynyyZ5/97J2qQpI0+h7TdwGSpJlhoEtSIwx0SWqEgS5JjTDQJakRBrokNWJ+Xz944cKFtWTJkr5+vCSNpPXr12+oqkVTnest0JcsWcK6dev6+vGSNJKSfGtz5xxykaRGGOiS1AgDXZIa0dsY+lQefPBBxsbG2LhxY9+l7HALFixg8eLF7LLLLn2XImlEzalAHxsbY88992TJkiUk6bucHaaquOuuuxgbG2P//ffvuxxJI2pODbls3LiRffbZZ6cKc4Ak7LPPPjvlXyaSZs6cCnRgpwvzcTvr85Y0c+ZcoM8F73nPe3jWs57FsmXLOOyww7j88sv7LkmStmpOjaFPtuSMT8/o433zvcdt9Zovf/nLXHTRRVxxxRXsuuuubNiwgQceeGC7f+amTZuYP39Ov8zSyJnpbJgtw2TOTLKHPskdd9zBwoUL2XXXXQFYuHAhT37yk1m7di3Pe97zOPTQQ1mxYgX33nsvGzdu5OSTT2bp0qUcfvjhfOELXwBgzZo1vOIVr+BlL3sZK1eu5L777uO1r30tRxxxBIcffjif/OQn+3yKkhpl13GSlStX8s53vpMDDzyQo446ilWrVvHc5z6XVatW8fGPf5wjjjiCe+65h912240zzzwTgGuuuYavf/3rrFy5khtvvBEY9PSvvvpq9t57b9761rfy4he/mHPPPZe7776bFStWcNRRR7H77rv3+VQlNcYe+iR77LEH69evZ/Xq1SxatIhVq1bxgQ98gCc96UkcccQRAOy1117Mnz+fL33pS7z61a8G4JnPfCZPfepTHw70o48+mr333huASy+9lPe+970cdthhHHnkkWzcuJFbb721nycoqVn20Kcwb948jjzySI488kiWLl3K2WefPeUslC1tsD2x911VnH/++Rx00EGzUq8kgT30R7nhhhv4xje+8fDxVVddxcEHH8ztt9/O2rVrAbj33nvZtGkTL3zhC/noRz8KwI033sitt946ZWi/9KUv5ayzznr4P4Arr7xyBzwTSTsbe+iTfP/73+e0007j7rvvZv78+TzjGc9g9erVnHzyyZx22mncf//97Lbbbnzuc5/jda97HaeeeipLly5l/vz5rFmz5uE3Uyd629vexumnn86yZcuoKpYsWcJFF13Uw7OT1LJsadhgNi1fvrwmr4d+/fXXc/DBB/dSz1ywsz9/aVg787TFJOuravlU5xxykaRGGOiS1AgDXZIaMecCva8x/b7trM9b0syZU4G+YMEC7rrrrp0u3MbXQ1+wYEHfpUgaYXNq2uLixYsZGxvjzjvv7LuUHW58xyJJ2l5zKtB32WUXd+yRpO00p4ZcJEnbz0CXpEYY6JLUCANdkhphoEtSIwx0SWqEgS5JjTDQJakRBrokNcJAl6RGGO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NVS3ttbBpsIcuzXFJ/nALp6uq3rXDimnLD6vqgfHb/pPMZ8TvYnaWizT33TfFBww2235zX0U14LIkbwV2S3I08E/Ap3quaVoccpFGSJI9gTcyCPNPAH9WVd/pt6rRlOQxDF7HlQxmuVwC/G2NcCga6NIISLI38CbglQzmSp9ZVd/tt6rR192sRVXd2XctM8EhF2mOS/J+BjcQ3Qssraq3G+bbLwNvT7IB+DpwQ5I7t/JexUiwhy7NcUl+BPwQ2MSPv2kXBm+K7tVLYSMqyW8z2HbulKq6pWt7GvA3wGer6s/7rG86DHRJO5UkVwJHV9WGSe2LGNwtevjU3zn3OeQiaWezy+Qwh4fH0XeZ4vqRYaBL2tk8sJ3n5jyHXCTtVJI8xCNz+X/sFLCgqka2l26gS1IjHHKRpEYY6JLUCANdkhphoKtpSSrJP0w4nt/dFXjRNj7ON5MsnO410mwy0NW6+4BndxsAAxwNfLvHeqRZY6BrZ/AZ4Lju65OAj42fSLJ3kn9OcnWSryQZ36tznySXJrkyyQcYTGkb/55XJfmPJFcl+UCSeTvyyUibY6BrZ3AecGKSBcAy4PIJ594BXNltuvxW4MNd+x8BX+puA78Q2A8gycHAKuD5VXUY8BCDFRCl3rljkZpXVVcnWcKgd37xpNMvAH6lu+5fu57544EXAi/v2j+dZHx1w5cAzwHWdjvd7Aa4HrnmBANdO4sLgT8FjgT2mdCeKa6tSZ8nCvD3VfWWGa1OmgEOuWhncS7wzqq6ZlL7F+mGTJIcCWyoqnsmtR8LPKG7/vPACUl+sju3d5Knznr10hDsoWunUFVjwJlTnHo78HdJrgZ+ALyma38H8LEkVwCXAbd2j/O1JH8AXNptYfYg8HrgW7P7DKStcy0XSWqEQy6S1AgDXZIaYaBLUiMMdElqhIEuSY0w0CWpEQa6JDXCQJekRvx/cF/GZn74sY4AAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"results= pd.DataFrame({'Model': ['S V M', 'Logistic R','Naive Bayes', \n",
" 'Decision Tree'], 'Score': [acc_linear_svc, acc_log, \n",
" acc_gaussian, acc_decision]})\n",
"\n",
"ax = results.plot.bar(x='Model', y='Score', rot=90)"
]
},
{
"cell_type": "markdown",
"id": "c1656c2c",
"metadata": {},
"source": [
"# Save Final Model (Decision tree model)\n",
"### Decision Tree model is best model for predict best line for passenger"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "9df04086",
"metadata": {},
"outputs": [],
"source": [
"#Save the Decision Tree strained modelusing pickle\n",
"import pickle\n",
"with open('ab_classifier_Decision_Tree', 'wb') as picklefile:\n",
" pickle.dump(decision_tree,picklefile)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "e032de3d",
"metadata": {},
"outputs": [],
"source": [
"with open('ab_classifier_Decision_Tree', 'rb') as training_model:\n",
" model6 = pickle.load(training_model)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "baae73c3",
"metadata": {},
"outputs": [],
"source": [
"def start_questionnaire():\n",
" my_predictors = []\n",
" parameters=['Age', 'Count','Country','GenderNo']\n",
" \n",
" print('Input Passenger Information:')\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",
" 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": "e69255e3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Input Passenger Information:\n"
]
}
],
"source": [
"start_questionnaire()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "012dc3a4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c64f4369",
"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