[0241e6]: / notebooks / model / inference / inference.ipynb

Download this file

88 lines (87 with data), 2.1 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from time import time \n",
    "import warnings\n",
    "import pandas as pd\n",
    "import joblib\n",
    "\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prediction: 99% - Benign\n",
      "Prediction Speed: 0.003\n"
     ]
    }
   ],
   "source": [
    "# Load trained model\n",
    "model = joblib.load('../../../models/gradient_boosting.joblib')\n",
    "\n",
    "'''\n",
    "GENDER: (1 - male, 2 - female)\n",
    "AGE: any\n",
    "SMOKING: (1 - no, 2 - yes)\n",
    "YELLOW_FINGERS: (1 - no, 2 - yes)\n",
    "FATIGUE: (1 - no, 2 - yes)\n",
    "WHEEZING: (1 - no, 2 - yes)\n",
    "COUGHING: (1 - no, 2 - yes)\n",
    "SHORTNESS OF BREATH: (1 - no, 2 - yes)\n",
    "SWALLOWING DIFFICULTY: (1 - no, 2 - yes)\n",
    "CHEST PAIN: (1 - no, 2 - yes)\n",
    "CHRONIC DISEASE: (1 - no, 2 - yes)\n",
    "\n",
    "'''\n",
    "\n",
    "new_data = [1,24,1,1,2,1,1,2,1,1,1] # My health status\n",
    "\n",
    "timer = time()\n",
    "\n",
    "pred = model.predict([new_data])[0] # Predict new data\n",
    "proba = f'{(model.predict_proba([new_data])[0][pred] * 100):.0f}%' # Get the prediction outcome\n",
    "\n",
    "if pred == 1:\n",
    "   print(f'Prediction: {proba} - Affected')\n",
    "else:\n",
    "   print(f'Prediction: {proba} - Benign')\n",
    "\n",
    "print(f'Prediction Speed: {(time() - timer):.3f}')"
   ]
  }
 ],
 "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.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}