Skip to content

Commit

Permalink
final code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh committed Oct 27, 2023
1 parent ad74ad3 commit 63555b5
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions models/.ipynb_checkpoints/Untitled-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
94 changes: 94 additions & 0 deletions models/Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions models/create_model.py
Original file line number Diff line number Diff line change
@@ -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)
Binary file modified models/spam_model.pkl
Binary file not shown.

0 comments on commit 63555b5

Please sign in to comment.