Skip to content

Commit

Permalink
Add meaningful example to the rest/grpc requests to the model (#33)
Browse files Browse the repository at this point in the history
Add meaningful example to the rest/grpc requests to the model
  • Loading branch information
esposem authored Jun 17, 2024
1 parent 387535a commit 2dd49bb
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 10 deletions.
68 changes: 67 additions & 1 deletion 3_rest_requests_multi_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,72 @@
"else:\n",
" print('not fraud')"
]
},
{
"cell_type": "markdown",
"id": "5697c2ff",
"metadata": {},
"source": [
"## Example 1: user buys a coffee\n",
"\n",
"In this example, the user is buying a coffee. The parameters given to the model are:\n",
"* same location as the last transaction (distance=0)\n",
"* same median price as the last transaction (ratio_to_median=1)\n",
"* using a pin number (pin=1)\n",
"* using the credit card chip (chip=1)\n",
"* not an online transaction (online=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0393a5a7",
"metadata": {},
"outputs": [],
"source": [
"data = [0.0, 1.0, 1.0, 1.0, 0.0]\n",
"prediction = rest_request(data)\n",
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('The model predicts that this is not fraud')"
]
},
{
"cell_type": "markdown",
"id": "e889cdd6",
"metadata": {},
"source": [
"## Example 2: fraudulent transaction\n",
"\n",
"In this example, someone stole the user's credit card and is buying something online. The parameters given to the model are:\n",
"* very far away from the last transaction (distance=100)\n",
"* median price similar to the last transaction (ratio_to_median=1.2)\n",
"* not using a pin number (pin=0)\n",
"* not using the credit card chip (chip=0)\n",
"* is an online transaction (online=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5deba1d5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"data = [100, 1.2, 0.0, 0.0, 1.0]\n",
"prediction = rest_request(data)\n",
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('The model predicts that this is not fraud')"
]
}
],
"metadata": {
Expand All @@ -115,7 +181,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
74 changes: 65 additions & 9 deletions 4_grpc_requests_multi_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
" inputs[0].datatype = \"FP32\"\n",
" inputs[0].shape.extend([1, 5])\n",
" inputs[0].contents.fp32_contents.extend(data)\n",
" print(inputs)\n",
"\n",
" # request building\n",
" request = grpc_predict_v2_pb2.ModelInferRequest()\n",
Expand Down Expand Up @@ -133,32 +132,89 @@
"outputs": [],
"source": [
"data = [0.3111400080477545, 1.9459399775518593, 1.0, 0.0, 0.0]\n",
"prediction = grpc_request(data)"
"prediction = grpc_request(data)\n",
"prediction"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1e2cbfa-848c-4f9e-891c-45ff8658b673",
"id": "946f9f1d-b24a-4aa6-b839-f0e8013ef84d",
"metadata": {},
"outputs": [],
"source": [
"prediction[0]"
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('fraud')\n",
"else:\n",
" print('not fraud')"
]
},
{
"cell_type": "markdown",
"id": "1d7f6b51",
"metadata": {},
"source": [
"## Example 1: user buys a coffee\n",
"\n",
"In this example, the user is buying a coffee. The parameters given to the model are:\n",
"* same location as the last transaction (distance=0)\n",
"* same median price as the last transaction (ratio_to_median=1)\n",
"* using a pin number (pin=1)\n",
"* using the credit card chip (chip=1)\n",
"* not an online transaction (online=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "946f9f1d-b24a-4aa6-b839-f0e8013ef84d",
"id": "f0a68b67-b109-4a2f-b097-092f4a4d25ce",
"metadata": {},
"outputs": [],
"source": [
"data = [0.0, 1.0, 1.0, 1.0, 0.0]\n",
"prediction = grpc_request(data)\n",
"threshhold = 0.995\n",
"\n",
"if (prediction > threshhold):\n",
" print('fraud')\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('not fraud')"
" print('The model predicts that this is not fraud')"
]
},
{
"cell_type": "markdown",
"id": "1dd27d88",
"metadata": {},
"source": [
"## Example 2: fraudulent transaction\n",
"\n",
"In this example, someone stole the user's credit card and is buying something online. The parameters given to the model are:\n",
"* very far away from the last transaction (distance=100)\n",
"* median price similar to the last transaction (ratio_to_median=1.2)\n",
"* not using a pin number (pin=0)\n",
"* not using the credit card chip (chip=0)\n",
"* is an online transaction (online=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7a736a21",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"data = [100, 1.2, 0.0, 0.0, 1.0]\n",
"prediction = grpc_request(data)\n",
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('The model predicts that this is not fraud')"
]
}
],
Expand All @@ -178,7 +234,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.9.18"
}
},
"nbformat": 4,
Expand Down
76 changes: 76 additions & 0 deletions 5_rest_requests_single_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,82 @@
"else:\n",
" print('not fraud')"
]
},
{
"cell_type": "markdown",
"id": "5f7b17c0",
"metadata": {},
"source": [
"## Example 1: user buys a coffee\n",
"\n",
"In this example, the user is buying a coffee. The parameters given to the model are:\n",
"* same location as the last transaction (distance=0)\n",
"* same median price as the last transaction (ratio_to_median=1)\n",
"* using a pin number (pin=1)\n",
"* using the credit card chip (chip=1)\n",
"* not an online transaction (online=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f0a68b67-b109-4a2f-b097-092f4a4d25ce",
"metadata": {},
"outputs": [],
"source": [
"data = [0.0, 1.0, 1.0, 1.0, 0.0]\n",
"prediction = rest_request(data)\n",
"prediction\n",
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('The model predicts that this is not fraud')"
]
},
{
"cell_type": "markdown",
"id": "db10b280",
"metadata": {},
"source": [
"## Example 2: fraudulent transaction\n",
"\n",
"In this example, someone stole the user's credit card and is buying something online. The parameters given to the model are:\n",
"* very far away from the last transaction (distance=100)\n",
"* median price similar to the last transaction (ratio_to_median=1.2)\n",
"* not using a pin number (pin=0)\n",
"* not using the credit card chip (chip=0)\n",
"* is an online transaction (online=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "219b8927",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"data = [100, 1.2, 0.0, 0.0, 1.0]\n",
"prediction = rest_request(data)\n",
"prediction\n",
"threshhold = 0.995\n",
"\n",
"if (prediction[0] > threshhold):\n",
" print('The model predicts that this is fraud')\n",
"else:\n",
" print('The model predicts that this is not fraud')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29f82fa0-c38b-4f2c-b17e-c061f24817be",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit 2dd49bb

Please sign in to comment.