From 63555b54ef11758e4cd9c14a93e64dc6c7716586 Mon Sep 17 00:00:00 2001 From: Nitesh Date: Fri, 27 Oct 2023 19:37:56 +0530 Subject: [PATCH] final code --- .../Untitled-checkpoint.ipynb | 6 ++ models/Untitled.ipynb | 94 ++++++++++++++++++ models/create_model.py | 12 +++ models/spam_model.pkl | Bin 244 -> 41 bytes 4 files changed, 112 insertions(+) create mode 100644 models/.ipynb_checkpoints/Untitled-checkpoint.ipynb create mode 100644 models/Untitled.ipynb create mode 100644 models/create_model.py diff --git a/models/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/models/.ipynb_checkpoints/Untitled-checkpoint.ipynb new file mode 100644 index 0000000..363fcab --- /dev/null +++ b/models/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/models/Untitled.ipynb b/models/Untitled.ipynb new file mode 100644 index 0000000..0cb14e4 --- /dev/null +++ b/models/Untitled.ipynb @@ -0,0 +1,94 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "id": "58c4cfc2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 0]\n" + ] + } + ], + "source": [ + "import pickle\n", + "with open(\"spam_model.pkl\", \"rb\") as f:\n", + " loaded_model = pickle.load(f)\n", + "predictions = loaded_model.predict([\"You've won a gift!\", \"Hello, how are you?\"])\n", + "print(predictions)\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "800879f4", + "metadata": {}, + "outputs": [], + "source": [ + "%run create_model.py\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "ff9b9c41", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['.ipynb_checkpoints', 'spam_model.pkl', 'Untitled.ipynb']\n" + ] + } + ], + "source": [ + "print(os.listdir())\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54f97e94", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10353dc5", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/models/create_model.py b/models/create_model.py new file mode 100644 index 0000000..cfd00a8 --- /dev/null +++ b/models/create_model.py @@ -0,0 +1,12 @@ +#pickle module is used to serialize (convert a Python object into a byte stream) +#and deserialize (convert a byte stream back into a Python object) Python objects. Serialization is useful for saving the state of an object and later restoring it. +import pickle + + +class DummyModel: + def predict(self, texts): + return [1 if "win" in text or "gift" in text else 0 for text in texts] + +model = DummyModel() +with open("spam_model.pkl", "wb") as f: + pickle.dump(model, f) diff --git a/models/spam_model.pkl b/models/spam_model.pkl index bd91b64536e8349ec699c83d339ac7fcfd3ffa98..7358a5ef9a2627a9d15def16cd081f3a005d66da 100644 GIT binary patch literal 41 scmZo*nJUKs0X-b?@wthadGYa6dbnIlb8{Iia%Gun^&JeL~6UyrAZsIDb=?(O%dJGvhy)B%RY=TA#mF} zQmS>02u_pt@AKG^J1FGo$Rb4QxJ^dL*&2ynNvc&{h)8LQ11@{8g`RoP;Gs|$BlLr9 z`d!EgVF#O)#pg@PwS;9irTh|(<6jd~shQIgW1zw4qRUo7<8Ni(gx={oN8fdYMqt-& O>tCC0^1&3YhOItiPEBY4