{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IndoHoaxDetector Example Notebook\n", "\n", "This notebook demonstrates how to use the IndoHoaxDetector model to classify Indonesian news articles as hoax or legitimate.\n", "\n", "## Setup\n", "\n", "First, make sure you have the required libraries installed:\n", "```bash\n", "pip install scikit-learn\n", "```\n", "\n", "And ensure the `logreg_model.pkl` file is in the same directory as this notebook." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "import numpy as np\n", "\n", "# Load the model\n", "with open('logreg_model.pkl', 'rb') as f:\n", " model = pickle.load(f)\n", "\n", "print(\"Model loaded successfully!\")\n", "print(f\"Model type: {type(model)}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example Predictions\n", "\n", "Let's test the model with some example Indonesian news texts." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Example texts\n", "test_texts = [\n", " \"Presiden Joko Widodo mengumumkan program vaksinasi COVID-19 untuk seluruh masyarakat Indonesia.\",\n", " \"Ditemukan dinosaurus hidup di Danau Toba, Sumatera Utara.\",\n", " \"Harga BBM akan naik mulai bulan depan akibat kenaikan harga minyak dunia.\",\n", " \"Minum jus lemon setiap hari bisa menyembuhkan diabetes secara permanen.\"\n", "]\n", "\n", "# Make predictions\n", "predictions = model.predict(test_texts)\n", "probabilities = model.predict_proba(test_texts)\n", "\n", "# Display results\n", "for i, (text, pred, prob) in enumerate(zip(test_texts, predictions, probabilities)):\n", " label = \"Hoax\" if pred == 1 else \"Legitimate\"\n", " confidence = prob[pred]\n", " print(f\"Example {i+1}:\")\n", " print(f\"Text: {text[:80]}{'...' if len(text) > 80 else ''}\")\n", " print(f\"Prediction: {label} (Confidence: {confidence:.4f})\")\n", " print(f\"Probabilities: Legitimate={prob[0]:.4f}, Hoax={prob[1]:.4f}\")\n", " print(\"-\" * 50)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Custom Prediction\n", "\n", "Try your own text below:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Enter your own Indonesian news text here\n", "custom_text = \"Masukkan berita Indonesia yang ingin Anda periksa di sini.\"\n", "\n", "# Make prediction\n", "custom_pred = model.predict([custom_text])[0]\n", "custom_prob = model.predict_proba([custom_text])[0]\n", "\n", "custom_label = \"Hoax\" if custom_pred == 1 else \"Legitimate\"\n", "custom_confidence = custom_prob[custom_pred]\n", "\n", "print(f\"Custom Text: {custom_text}\")\n", "print(f\"Prediction: {custom_label}\")\n", "print(f\"Confidence: {custom_confidence:.4f}\")\n", "print(f\"Probabilities: Legitimate={custom_prob[0]:.4f}, Hoax={custom_prob[1]:.4f}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Notes\n", "\n", "- This model is trained on Indonesian news data and may not work well with other languages.\n", "- Always use human judgment and verify information from multiple sources.\n", "- The model provides probability scores that can help assess confidence in predictions." ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }