blob: df3c6910b605dda1121f0eaa5b0b2229233c135d [file] [log] [blame]
{
"metadata": {
"orig_nbformat": 2,
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"interpreter": {
"hash": "7fe315b7a207e63d5c2ef5139e719409788deb4436627680109abc8a609c6411"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"source": [
"import json # will be needed for saving preprocessing details\r\n",
"import numpy as np # for data manipulation\r\n",
"import pandas as pd # for data manipulation\r\n",
"from sklearn.model_selection import train_test_split # will be used for data split\r\n",
"import requests\r\n",
"\r\n",
"df = pd.read_csv('zoo/data/german_data.csv', index_col=0)\r\n",
"df = df.drop(columns = ['Saving accounts', 'Checking account'])\r\n",
"\r\n",
"x_cols = [c for c in df.columns if c != 'Risk']\r\n",
"\r\n",
"# set input matrix and target column\r\n",
"X = df[x_cols]\r\n",
"y = df['Risk']\r\n",
"# show first rows of data\r\n",
"\r\n",
"df.head()"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Age Sex Job Housing Credit amount Duration Purpose \\\n",
"0 67 male 2 own 1169 6 radio/TV \n",
"1 22 female 2 own 5951 48 radio/TV \n",
"2 49 male 1 own 2096 12 education \n",
"3 45 male 2 free 7882 42 furniture/equipment \n",
"4 53 male 2 free 4870 24 car \n",
"\n",
" Risk \n",
"0 good \n",
"1 bad \n",
"2 good \n",
"3 good \n",
"4 bad "
],
"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>Sex</th>\n",
" <th>Job</th>\n",
" <th>Housing</th>\n",
" <th>Credit amount</th>\n",
" <th>Duration</th>\n",
" <th>Purpose</th>\n",
" <th>Risk</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>67</td>\n",
" <td>male</td>\n",
" <td>2</td>\n",
" <td>own</td>\n",
" <td>1169</td>\n",
" <td>6</td>\n",
" <td>radio/TV</td>\n",
" <td>good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>22</td>\n",
" <td>female</td>\n",
" <td>2</td>\n",
" <td>own</td>\n",
" <td>5951</td>\n",
" <td>48</td>\n",
" <td>radio/TV</td>\n",
" <td>bad</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>49</td>\n",
" <td>male</td>\n",
" <td>1</td>\n",
" <td>own</td>\n",
" <td>2096</td>\n",
" <td>12</td>\n",
" <td>education</td>\n",
" <td>good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>45</td>\n",
" <td>male</td>\n",
" <td>2</td>\n",
" <td>free</td>\n",
" <td>7882</td>\n",
" <td>42</td>\n",
" <td>furniture/equipment</td>\n",
" <td>good</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>53</td>\n",
" <td>male</td>\n",
" <td>2</td>\n",
" <td>free</td>\n",
" <td>4870</td>\n",
" <td>24</td>\n",
" <td>car</td>\n",
" <td>bad</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
]
},
"metadata": {},
"execution_count": 1
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"# data split train / test\r\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state=1234)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 5,
"source": [
"for i in range(2):\r\n",
" input_data = dict(X_test.iloc[i])\r\n",
" target = y_test.iloc[i]\r\n",
" r = requests.post(\"http://127.0.0.1:8000/api/v1/algorithms/predict?status=ab_testing\", input_data)\r\n",
" response = r.json()\r\n",
" print(response)\r\n",
" # provide feedback\r\n",
" requests.put(\"http://127.0.0.1:8000/api/v1/requests/{}\".format(response[\"request_id\"]), {\"feedback\": target})"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'probability': 0.05733167685353127, 'label': 'bad', 'status': 'OK', 'request_id': 1}\n",
"{'probability': 0.43333333333333335, 'label': 'bad', 'status': 'OK', 'request_id': 2}\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"r = requests.post(\"http://127.0.0.1:8000/api/v1/abtest/predict?status=ab_testing\", input_data)"
],
"outputs": [],
"metadata": {}
}
]
}