{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import library\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"import pickle\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Load all files\n",
"\n",
"with open('list_num_cols.txt', 'r') as file_1:\n",
" list_num_cols = json.load(file_1)\n",
"\n",
"with open('model_scaler.pkl', 'rb') as file_2:\n",
" scaler = pickle.load(file_2)\n",
"\n",
"with open('model_rfc.pkl', 'rb') as file_3:\n",
" model_rfc = pickle.load(file_3)\n",
" \n",
"with open('model_gbc.pkl', 'rb') as file_4:\n",
" model_gbc = pickle.load(file_4)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" age | \n",
" anaemia | \n",
" creatinine_phosphokinase | \n",
" diabetes | \n",
" ejection_fraction | \n",
" high_blood_pressure | \n",
" platelets | \n",
" serum_creatinine | \n",
" serum_sodium | \n",
" sex | \n",
" smoking | \n",
" time | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 20 | \n",
" 1 | \n",
" 300 | \n",
" 1 | \n",
" 50 | \n",
" 1 | \n",
" 150000 | \n",
" 2.5 | \n",
" 150 | \n",
" 0 | \n",
" 1 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" age anaemia creatinine_phosphokinase diabetes ejection_fraction \\\n",
"0 20 1 300 1 50 \n",
"\n",
" high_blood_pressure platelets serum_creatinine serum_sodium sex \\\n",
"0 1 150000 2.5 150 0 \n",
"\n",
" smoking time \n",
"0 1 2 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Create new data\n",
"\n",
"data_inf = pd.DataFrame({\n",
" 'age' : [20],\n",
" 'anaemia' : [1],\n",
" 'creatinine_phosphokinase' : [300],\n",
" 'diabetes' : [1],\n",
" 'ejection_fraction' : [50],\n",
" 'high_blood_pressure' : [1],\n",
" 'platelets' : [150000],\n",
" 'serum_creatinine' : [2.5],\n",
" 'serum_sodium' : [150],\n",
" 'sex' : [0],\n",
" 'smoking' : [1],\n",
" 'time' : [2],\n",
"})\n",
"\n",
"data_inf"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" age | \n",
" ejection_fraction | \n",
" serum_creatinine | \n",
" serum_sodium | \n",
" time | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 20 | \n",
" 50 | \n",
" 2.5 | \n",
" 150 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" age ejection_fraction serum_creatinine serum_sodium time\n",
"0 20 50 2.5 150 2"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Split between numerical columns and categorical columns\n",
"\n",
"data_inf_num = data_inf[list_num_cols]\n",
"data_inf_num"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Feature scaling and feature encoding\n",
"\n",
"data_inf_num_scaled = scaler.transform(data_inf_num)\n",
"data_inf_final = data_inf_num_scaled"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0\n",
"0 1"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Predict using Random Forest Classification Model\n",
"\n",
"y_pred_inf_rfc = pd.DataFrame(model_rfc.predict(data_inf_final))\n",
"y_pred_inf_rfc"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" 0 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" 0\n",
"0 1"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Predict using GradientBoost Classification - Hyperparameter\n",
"\n",
"y_pred_inf_gbc = pd.DataFrame(model_gbc.predict(data_inf_final))\n",
"y_pred_inf_gbc"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.10.10"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}