Upload files to "/"
This commit is contained in:
parent
5f58bb43a5
commit
0af3226a9f
521
klasifikasi_teks_FNN.ipynb
Normal file
521
klasifikasi_teks_FNN.ipynb
Normal file
@ -0,0 +1,521 @@
|
||||
{
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0,
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"provenance": []
|
||||
},
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python"
|
||||
}
|
||||
},
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "wOCzKrPTS65M"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"{\n",
|
||||
" \"cells\": [\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"markdown\",\n",
|
||||
" \"id\": \"f4a1399a-f23d-4060-a07e-bce5a5c7ddac\",\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"f4a1399a-f23d-4060-a07e-bce5a5c7ddac\"\n",
|
||||
" },\n",
|
||||
" \"source\": [\n",
|
||||
" \"# Klasifikasi Teks menggunakan FNN\\n\",\n",
|
||||
" \"## Alya Priscilla Putri\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"execution_count\": 3,\n",
|
||||
" \"id\": \"53a214ae-c9cf-4d46-925d-068f1685537b\",\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"53a214ae-c9cf-4d46-925d-068f1685537b\"\n",
|
||||
" },\n",
|
||||
" \"outputs\": [],\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 1. IMPORT LIBRARY\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"import re\\n\",\n",
|
||||
" \"import numpy as np\\n\",\n",
|
||||
" \"import pandas as pd\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"from sklearn.model_selection import train_test_split\\n\",\n",
|
||||
" \"from sklearn.feature_extraction.text import TfidfVectorizer\\n\",\n",
|
||||
" \"from sklearn.preprocessing import LabelEncoder\\n\",\n",
|
||||
" \"from sklearn.metrics import accuracy_score, classification_report\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"from tensorflow.keras.models import Sequential\\n\",\n",
|
||||
" \"from tensorflow.keras.layers import Dense, Dropout\\n\",\n",
|
||||
" \"from tensorflow.keras.utils import to_categorical\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 2. DATA TEKS MANUAL\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"texts = [\\n\",\n",
|
||||
" \" \\\"saya suka belajar machine learning\\\",\\n\",\n",
|
||||
" \" \\\"data science sangat menarik\\\",\\n\",\n",
|
||||
" \" \\\"saya tidak suka matematika\\\",\\n\",\n",
|
||||
" \" \\\"python mudah dipelajari\\\",\\n\",\n",
|
||||
" \" \\\"machine learning membutuhkan data\\\",\\n\",\n",
|
||||
" \" \\\"saya benci debugging error\\\",\\n\",\n",
|
||||
" \" \\\"belajar python menyenangkan\\\",\\n\",\n",
|
||||
" \" \\\"matematika penting dalam data science\\\"\\n\",\n",
|
||||
" \"]\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"labels = [\\n\",\n",
|
||||
" \" \\\"positif\\\",\\n\",\n",
|
||||
" \" \\\"positif\\\",\\n\",\n",
|
||||
" \" \\\"negatif\\\",\\n\",\n",
|
||||
" \" \\\"positif\\\",\\n\",\n",
|
||||
" \" \\\"netral\\\",\\n\",\n",
|
||||
" \" \\\"negatif\\\",\\n\",\n",
|
||||
" \" \\\"positif\\\",\\n\",\n",
|
||||
" \" \\\"netral\\\"\\n\",\n",
|
||||
" \"]\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"YUpHatB8LATR\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"YUpHatB8LATR\",\n",
|
||||
" \"execution_count\": 4,\n",
|
||||
" \"outputs\": []\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"execution_count\": 5,\n",
|
||||
" \"id\": \"9f7d90fe-4af4-446c-9547-c9312bfa6fc7\",\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"9f7d90fe-4af4-446c-9547-c9312bfa6fc7\"\n",
|
||||
" },\n",
|
||||
" \"outputs\": [],\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 3. PREPROCESSING TEKS\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"def clean_text(text):\\n\",\n",
|
||||
" \" text = text.lower()\\n\",\n",
|
||||
" \" text = re.sub(r\\\"[^a-z\\\\s]\\\", \\\"\\\", text)\\n\",\n",
|
||||
" \" text = re.sub(r\\\"\\\\s+\\\", \\\" \\\", text).strip()\\n\",\n",
|
||||
" \" return text\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"texts = [clean_text(t) for t in texts]\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"execution_count\": 6,\n",
|
||||
" \"id\": \"d4b9a7c2-0f08-43fd-8da8-018d839a4917\",\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"d4b9a7c2-0f08-43fd-8da8-018d839a4917\"\n",
|
||||
" },\n",
|
||||
" \"outputs\": [],\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 4. ENCODING LABEL\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"le = LabelEncoder()\\n\",\n",
|
||||
" \"y = le.fit_transform(labels)\\n\",\n",
|
||||
" \"y = to_categorical(y)\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 5. FEATURE EXTRACTION (TF-IDF)\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"vectorizer = TfidfVectorizer(max_features=1000)\\n\",\n",
|
||||
" \"X = vectorizer.fit_transform(texts).toarray()\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"jgBIwoPxLJkw\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"jgBIwoPxLJkw\",\n",
|
||||
" \"execution_count\": 7,\n",
|
||||
" \"outputs\": []\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 6. SPLIT DATA\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"X_train, X_test, y_train, y_test = train_test_split(\\n\",\n",
|
||||
" \" X, y, test_size=0.25, random_state=42\\n\",\n",
|
||||
" \")\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"id\": \"112p_r_WLMEI\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"112p_r_WLMEI\",\n",
|
||||
" \"execution_count\": 8,\n",
|
||||
" \"outputs\": []\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 7. MODEL FNN (DIMODIFIKASI)\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"model = Sequential()\\n\",\n",
|
||||
" \"model.add(Dense(64, activation=\\\"relu\\\", input_shape=(X_train.shape[1],)))\\n\",\n",
|
||||
" \"model.add(Dropout(0.3))\\n\",\n",
|
||||
" \"model.add(Dense(32, activation=\\\"relu\\\"))\\n\",\n",
|
||||
" \"model.add(Dense(y.shape[1], activation=\\\"softmax\\\"))\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"model.compile(\\n\",\n",
|
||||
" \" optimizer=\\\"adam\\\",\\n\",\n",
|
||||
" \" loss=\\\"categorical_crossentropy\\\",\\n\",\n",
|
||||
" \" metrics=[\\\"accuracy\\\"]\\n\",\n",
|
||||
" \")\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"model.summary()\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"colab\": {\n",
|
||||
" \"base_uri\": \"https://localhost:8080/\",\n",
|
||||
" \"height\": 329\n",
|
||||
" },\n",
|
||||
" \"id\": \"WFemRciMLORN\",\n",
|
||||
" \"outputId\": \"a76a6d80-fce1-4ca7-fcb5-9d6e048b7382\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"WFemRciMLORN\",\n",
|
||||
" \"execution_count\": 9,\n",
|
||||
" \"outputs\": [\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"stream\",\n",
|
||||
" \"name\": \"stderr\",\n",
|
||||
" \"text\": [\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/keras/src/layers/core/dense.py:93: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\\n\",\n",
|
||||
" \" super().__init__(activity_regularizer=activity_regularizer, **kwargs)\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"display_data\",\n",
|
||||
" \"data\": {\n",
|
||||
" \"text/plain\": [\n",
|
||||
" \"\\u001b[1mModel: \\\"sequential\\\"\\u001b[0m\\n\"\n",
|
||||
" ],\n",
|
||||
" \"text/html\": [\n",
|
||||
" \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\">Model: \\\"sequential\\\"</span>\\n\",\n",
|
||||
" \"</pre>\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" \"metadata\": {}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"display_data\",\n",
|
||||
" \"data\": {\n",
|
||||
" \"text/plain\": [\n",
|
||||
" \"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
|
||||
" \"┃\\u001b[1m \\u001b[0m\\u001b[1mLayer (type) \\u001b[0m\\u001b[1m \\u001b[0m┃\\u001b[1m \\u001b[0m\\u001b[1mOutput Shape \\u001b[0m\\u001b[1m \\u001b[0m┃\\u001b[1m \\u001b[0m\\u001b[1m Param #\\u001b[0m\\u001b[1m \\u001b[0m┃\\n\",\n",
|
||||
" \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
|
||||
" \"│ dense (\\u001b[38;5;33mDense\\u001b[0m) │ (\\u001b[38;5;45mNone\\u001b[0m, \\u001b[38;5;34m64\\u001b[0m) │ \\u001b[38;5;34m1,408\\u001b[0m │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dropout (\\u001b[38;5;33mDropout\\u001b[0m) │ (\\u001b[38;5;45mNone\\u001b[0m, \\u001b[38;5;34m64\\u001b[0m) │ \\u001b[38;5;34m0\\u001b[0m │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dense_1 (\\u001b[38;5;33mDense\\u001b[0m) │ (\\u001b[38;5;45mNone\\u001b[0m, \\u001b[38;5;34m32\\u001b[0m) │ \\u001b[38;5;34m2,080\\u001b[0m │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dense_2 (\\u001b[38;5;33mDense\\u001b[0m) │ (\\u001b[38;5;45mNone\\u001b[0m, \\u001b[38;5;34m3\\u001b[0m) │ \\u001b[38;5;34m99\\u001b[0m │\\n\",\n",
|
||||
" \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\"\n",
|
||||
" ],\n",
|
||||
" \"text/html\": [\n",
|
||||
" \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
|
||||
" \"┃<span style=\\\"font-weight: bold\\\"> Layer (type) </span>┃<span style=\\\"font-weight: bold\\\"> Output Shape </span>┃<span style=\\\"font-weight: bold\\\"> Param # </span>┃\\n\",\n",
|
||||
" \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
|
||||
" \"│ dense (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>) │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>) │ <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">1,408</span> │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dropout (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dropout</span>) │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>) │ <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dense_1 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>) │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">32</span>) │ <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">2,080</span> │\\n\",\n",
|
||||
" \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
|
||||
" \"│ dense_2 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>) │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">3</span>) │ <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">99</span> │\\n\",\n",
|
||||
" \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\",\n",
|
||||
" \"</pre>\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" \"metadata\": {}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"display_data\",\n",
|
||||
" \"data\": {\n",
|
||||
" \"text/plain\": [\n",
|
||||
" \"\\u001b[1m Total params: \\u001b[0m\\u001b[38;5;34m3,587\\u001b[0m (14.01 KB)\\n\"\n",
|
||||
" ],\n",
|
||||
" \"text/html\": [\n",
|
||||
" \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Total params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">3,587</span> (14.01 KB)\\n\",\n",
|
||||
" \"</pre>\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" \"metadata\": {}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"display_data\",\n",
|
||||
" \"data\": {\n",
|
||||
" \"text/plain\": [\n",
|
||||
" \"\\u001b[1m Trainable params: \\u001b[0m\\u001b[38;5;34m3,587\\u001b[0m (14.01 KB)\\n\"\n",
|
||||
" ],\n",
|
||||
" \"text/html\": [\n",
|
||||
" \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">3,587</span> (14.01 KB)\\n\",\n",
|
||||
" \"</pre>\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" \"metadata\": {}\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"display_data\",\n",
|
||||
" \"data\": {\n",
|
||||
" \"text/plain\": [\n",
|
||||
" \"\\u001b[1m Non-trainable params: \\u001b[0m\\u001b[38;5;34m0\\u001b[0m (0.00 B)\\n\"\n",
|
||||
" ],\n",
|
||||
" \"text/html\": [\n",
|
||||
" \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Non-trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> (0.00 B)\\n\",\n",
|
||||
" \"</pre>\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" \"metadata\": {}\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 8. TRAINING\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"history = model.fit(\\n\",\n",
|
||||
" \" X_train,\\n\",\n",
|
||||
" \" y_train,\\n\",\n",
|
||||
" \" epochs=30,\\n\",\n",
|
||||
" \" batch_size=4,\\n\",\n",
|
||||
" \" validation_split=0.2,\\n\",\n",
|
||||
" \" verbose=1\\n\",\n",
|
||||
" \")\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"colab\": {\n",
|
||||
" \"base_uri\": \"https://localhost:8080/\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"TQH90ZNrLRBt\",\n",
|
||||
" \"outputId\": \"40144c0a-ecbd-478b-a35c-30a51c755836\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"TQH90ZNrLRBt\",\n",
|
||||
" \"execution_count\": 10,\n",
|
||||
" \"outputs\": [\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"stream\",\n",
|
||||
" \"name\": \"stdout\",\n",
|
||||
" \"text\": [\n",
|
||||
" \"Epoch 1/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m2s\\u001b[0m 2s/step - accuracy: 0.5000 - loss: 1.0428 - val_accuracy: 0.0000e+00 - val_loss: 1.0974\\n\",\n",
|
||||
" \"Epoch 2/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 168ms/step - accuracy: 0.2500 - loss: 1.0820 - val_accuracy: 0.0000e+00 - val_loss: 1.1007\\n\",\n",
|
||||
" \"Epoch 3/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 239ms/step - accuracy: 0.5000 - loss: 1.0417 - val_accuracy: 0.0000e+00 - val_loss: 1.1046\\n\",\n",
|
||||
" \"Epoch 4/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 86ms/step - accuracy: 0.7500 - loss: 1.0252 - val_accuracy: 0.0000e+00 - val_loss: 1.1079\\n\",\n",
|
||||
" \"Epoch 5/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 88ms/step - accuracy: 0.5000 - loss: 1.0166 - val_accuracy: 0.0000e+00 - val_loss: 1.1109\\n\",\n",
|
||||
" \"Epoch 6/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 132ms/step - accuracy: 0.5000 - loss: 0.9857 - val_accuracy: 0.0000e+00 - val_loss: 1.1139\\n\",\n",
|
||||
" \"Epoch 7/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 93ms/step - accuracy: 1.0000 - loss: 0.9839 - val_accuracy: 0.0000e+00 - val_loss: 1.1175\\n\",\n",
|
||||
" \"Epoch 8/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 92ms/step - accuracy: 1.0000 - loss: 0.9848 - val_accuracy: 0.0000e+00 - val_loss: 1.1218\\n\",\n",
|
||||
" \"Epoch 9/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 87ms/step - accuracy: 1.0000 - loss: 0.9697 - val_accuracy: 0.0000e+00 - val_loss: 1.1260\\n\",\n",
|
||||
" \"Epoch 10/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 93ms/step - accuracy: 0.7500 - loss: 0.9688 - val_accuracy: 0.0000e+00 - val_loss: 1.1295\\n\",\n",
|
||||
" \"Epoch 11/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 94ms/step - accuracy: 1.0000 - loss: 0.9126 - val_accuracy: 0.0000e+00 - val_loss: 1.1330\\n\",\n",
|
||||
" \"Epoch 12/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 87ms/step - accuracy: 0.5000 - loss: 1.0176 - val_accuracy: 0.0000e+00 - val_loss: 1.1366\\n\",\n",
|
||||
" \"Epoch 13/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 96ms/step - accuracy: 0.7500 - loss: 0.9968 - val_accuracy: 0.0000e+00 - val_loss: 1.1404\\n\",\n",
|
||||
" \"Epoch 14/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 93ms/step - accuracy: 0.7500 - loss: 0.9723 - val_accuracy: 0.0000e+00 - val_loss: 1.1439\\n\",\n",
|
||||
" \"Epoch 15/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 91ms/step - accuracy: 0.7500 - loss: 0.9863 - val_accuracy: 0.0000e+00 - val_loss: 1.1474\\n\",\n",
|
||||
" \"Epoch 16/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 94ms/step - accuracy: 1.0000 - loss: 0.9335 - val_accuracy: 0.0000e+00 - val_loss: 1.1506\\n\",\n",
|
||||
" \"Epoch 17/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 109ms/step - accuracy: 0.7500 - loss: 0.9062 - val_accuracy: 0.0000e+00 - val_loss: 1.1541\\n\",\n",
|
||||
" \"Epoch 18/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 99ms/step - accuracy: 0.7500 - loss: 0.9250 - val_accuracy: 0.0000e+00 - val_loss: 1.1575\\n\",\n",
|
||||
" \"Epoch 19/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 90ms/step - accuracy: 0.7500 - loss: 0.9448 - val_accuracy: 0.0000e+00 - val_loss: 1.1609\\n\",\n",
|
||||
" \"Epoch 20/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 90ms/step - accuracy: 0.7500 - loss: 0.8955 - val_accuracy: 0.0000e+00 - val_loss: 1.1640\\n\",\n",
|
||||
" \"Epoch 21/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 92ms/step - accuracy: 1.0000 - loss: 0.8694 - val_accuracy: 0.0000e+00 - val_loss: 1.1667\\n\",\n",
|
||||
" \"Epoch 22/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 89ms/step - accuracy: 0.5000 - loss: 0.9652 - val_accuracy: 0.0000e+00 - val_loss: 1.1694\\n\",\n",
|
||||
" \"Epoch 23/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 97ms/step - accuracy: 0.7500 - loss: 0.8697 - val_accuracy: 0.0000e+00 - val_loss: 1.1723\\n\",\n",
|
||||
" \"Epoch 24/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 89ms/step - accuracy: 0.7500 - loss: 0.8764 - val_accuracy: 0.0000e+00 - val_loss: 1.1758\\n\",\n",
|
||||
" \"Epoch 25/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 89ms/step - accuracy: 0.7500 - loss: 0.8423 - val_accuracy: 0.0000e+00 - val_loss: 1.1791\\n\",\n",
|
||||
" \"Epoch 26/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 94ms/step - accuracy: 0.7500 - loss: 0.7802 - val_accuracy: 0.0000e+00 - val_loss: 1.1823\\n\",\n",
|
||||
" \"Epoch 27/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 109ms/step - accuracy: 0.7500 - loss: 0.8458 - val_accuracy: 0.0000e+00 - val_loss: 1.1854\\n\",\n",
|
||||
" \"Epoch 28/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 95ms/step - accuracy: 0.7500 - loss: 0.8357 - val_accuracy: 0.0000e+00 - val_loss: 1.1881\\n\",\n",
|
||||
" \"Epoch 29/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 86ms/step - accuracy: 0.7500 - loss: 0.7801 - val_accuracy: 0.0000e+00 - val_loss: 1.1910\\n\",\n",
|
||||
" \"Epoch 30/30\\n\",\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 90ms/step - accuracy: 0.7500 - loss: 0.8469 - val_accuracy: 0.0000e+00 - val_loss: 1.1941\\n\"\n",
|
||||
" ]\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 9. EVALUASI\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"y_pred = model.predict(X_test)\\n\",\n",
|
||||
" \"y_pred_class = np.argmax(y_pred, axis=1)\\n\",\n",
|
||||
" \"y_true = np.argmax(y_test, axis=1)\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"print(\\\"\\\\nAccuracy:\\\", accuracy_score(y_true, y_pred_class))\\n\",\n",
|
||||
" \"print(\\\"\\\\nClassification Report:\\\")\\n\",\n",
|
||||
" \"print(classification_report(y_true, y_pred_class, target_names=le.classes_))\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"colab\": {\n",
|
||||
" \"base_uri\": \"https://localhost:8080/\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"KZsJ9UBSLTYe\",\n",
|
||||
" \"outputId\": \"a1c9f60c-cb11-4ac2-cfe5-b9b541c4444d\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"KZsJ9UBSLTYe\",\n",
|
||||
" \"execution_count\": 11,\n",
|
||||
" \"outputs\": [\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"stream\",\n",
|
||||
" \"name\": \"stdout\",\n",
|
||||
" \"text\": [\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 76ms/step\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"Accuracy: 0.0\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"Classification Report:\\n\",\n",
|
||||
" \" precision recall f1-score support\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \" negatif 0.00 0.00 0.00 1.0\\n\",\n",
|
||||
" \" netral 0.00 0.00 0.00 0.0\\n\",\n",
|
||||
" \" positif 0.00 0.00 0.00 1.0\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \" accuracy 0.00 2.0\\n\",\n",
|
||||
" \" macro avg 0.00 0.00 0.00 2.0\\n\",\n",
|
||||
" \"weighted avg 0.00 0.00 0.00 2.0\\n\",\n",
|
||||
" \"\\n\"\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"stream\",\n",
|
||||
" \"name\": \"stderr\",\n",
|
||||
" \"text\": [\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\",\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\",\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\",\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\",\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\",\n",
|
||||
" \"/usr/local/lib/python3.12/dist-packages/sklearn/metrics/_classification.py:1565: UndefinedMetricWarning: Recall is ill-defined and being set to 0.0 in labels with no true samples. Use `zero_division` parameter to control this behavior.\\n\",\n",
|
||||
" \" _warn_prf(average, modifier, f\\\"{metric.capitalize()} is\\\", len(result))\\n\"\n",
|
||||
" ]\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"cell_type\": \"code\",\n",
|
||||
" \"source\": [\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"# 10. UJI KALIMAT BARU\\n\",\n",
|
||||
" \"# =========================\\n\",\n",
|
||||
" \"test_text = [\\\"saya suka belajar python\\\"]\\n\",\n",
|
||||
" \"test_text = [clean_text(test_text[0])]\\n\",\n",
|
||||
" \"X_new = vectorizer.transform(test_text).toarray()\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"prediction = model.predict(X_new)\\n\",\n",
|
||||
" \"predicted_label = le.inverse_transform([np.argmax(prediction)])\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"print(\\\"\\\\nKalimat uji:\\\", test_text[0])\\n\",\n",
|
||||
" \"print(\\\"Hasil klasifikasi:\\\", predicted_label[0])\"\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"colab\": {\n",
|
||||
" \"base_uri\": \"https://localhost:8080/\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"hfiVQ8rGLWZ-\",\n",
|
||||
" \"outputId\": \"091f87bc-e9ec-4853-d253-32e5d87f4d95\"\n",
|
||||
" },\n",
|
||||
" \"id\": \"hfiVQ8rGLWZ-\",\n",
|
||||
" \"execution_count\": 12,\n",
|
||||
" \"outputs\": [\n",
|
||||
" {\n",
|
||||
" \"output_type\": \"stream\",\n",
|
||||
" \"name\": \"stdout\",\n",
|
||||
" \"text\": [\n",
|
||||
" \"\\u001b[1m1/1\\u001b[0m \\u001b[32m━━━━━━━━━━━━━━━━━━━━\\u001b[0m\\u001b[37m\\u001b[0m \\u001b[1m0s\\u001b[0m 70ms/step\\n\",\n",
|
||||
" \"\\n\",\n",
|
||||
" \"Kalimat uji: saya suka belajar python\\n\",\n",
|
||||
" \"Hasil klasifikasi: netral\\n\"\n",
|
||||
" ]\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
" }\n",
|
||||
" ],\n",
|
||||
" \"metadata\": {\n",
|
||||
" \"kernelspec\": {\n",
|
||||
" \"display_name\": \"Python 3 (ipykernel)\",\n",
|
||||
" \"language\": \"python\",\n",
|
||||
" \"name\": \"python3\"\n",
|
||||
" },\n",
|
||||
" \"language_info\": {\n",
|
||||
" \"codemirror_mode\": {\n",
|
||||
" \"name\": \"ipython\",\n",
|
||||
" \"version\": 3\n",
|
||||
" },\n",
|
||||
" \"file_extension\": \".py\",\n",
|
||||
" \"mimetype\": \"text/x-python\",\n",
|
||||
" \"name\": \"python\",\n",
|
||||
" \"nbconvert_exporter\": \"python\",\n",
|
||||
" \"pygments_lexer\": \"ipython3\",\n",
|
||||
" \"version\": \"3.12.2\"\n",
|
||||
" },\n",
|
||||
" \"colab\": {\n",
|
||||
" \"provenance\": []\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"nbformat\": 4,\n",
|
||||
" \"nbformat_minor\": 5\n",
|
||||
"}"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user