Tugas 6.2 : Uji Coba Model Logistic Regression#

Pada Tugas 6.2 ini diminta untuk melakukan uji coba model yang telah dibuat dengan algoritma Logistic Regression dari data SVD (Singular Value Decomposition).

Dibuat Oleh:

  • Nama : Sabil Ahmad Hidayat

  • NIM : 220411100058

  • Kelas : PPW A

Link Code : https://colab.research.google.com/drive/1kOIWgzTUapCLbDVpFRFWMu5hCXrKnHxp?usp=sharing

Link Github : meinhere/ppw

Import Library#

!pip install -q Sastrawi
[notice] A new release of pip is available: 23.2.1 -> 24.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip
# library awal untuk perhitungan dan pengolahan teks
import numpy as np
import re
import pandas as pd

# alat untuk crawling
from urllib.request import urlopen
from bs4 import BeautifulSoup

# monitoring
from tqdm import tqdm

# library untuk praproses teks
import nltk
nltk.download('stopwords')
nltk.download('wordnet')
nltk.download('punkt')
from nltk.corpus import stopwords
from Sastrawi.Stemmer.StemmerFactory import StemmerFactory

# library untuk proses modeling
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

# library untuk evaluasi model
from sklearn.metrics import classification_report, confusion_matrix

# plotting
import matplotlib.pyplot as plt
import seaborn as sns

# save model
import pickle
import requests

preprocessing disini digunakan untuk melakukan proses encoding pada label

train_test_split digunakan untuk membagi dataset menjadi data training dan testing

LogisticRegression digunakan untuk tahap modeling menggunakan library LogisticRegression

classification_report dan confusion_matrix digunakan untuk melihat laporan dan hasil evaluasi setelah proses training data

matplotlib dan seaborn digunakan untuk plotting grafik

pickle digunakan untuk menyimpan model hasil training dan testing

Persiapan Data#

Load Data#

main_df = pd.read_csv('https://raw.githubusercontent.com/meinhere/ppw/master/publish/tugas-2/dataset/data_berita.csv', delimiter=',')
main_df
No Judul Berita Isi Berita Tanggal Berita Kategori Berita
0 1 Simak Jadwal dan Lokasi SIM Keliling di Jakart... JAKARTA, KOMPAS.com - Surat Izin Mengemudi (S... 07/09/2024 OTOMOTIF
1 2 [POPULER OTOMOTIF] Diskon Motor Honda Septembe... JAKARTA, KOMPAS.com - Banyak pembaca yang ingi... 07/09/2024 OTOMOTIF
2 3 Cek Saldo Minimal BRI, BNI, BCA, Mandiri, dan BSI JAKARTA, KOMPAS.com - Penting bagi calon nasab... 06/09/2024 MONEY
3 4 KAI Uji Coba Teknologi "Face Recognition Board... KOMPAS.com - PT Kereta Api Indonesia (KAI) Div... 06/09/2024 MONEY
4 5 OJK Blokir 10.890 Entitas Keuangan Ilegal Seja... JAKARTA, KOMPAS.com - Otoritas Jasa Keuangan (... 06/09/2024 MONEY
... ... ... ... ... ...
95 96 Waspada Masalah yang Timbul akibat Telat Ganti... JAKARTA, KOMPAS.com - Oli mesin pada mobil den... 06/09/2024 OTOMOTIF
96 97 Sosok Faisal Basri di Mata Para Tokoh, Ekonom ... JAKARTA, KOMPAS.com - Ekonom senior Faisal Bas... 06/09/2024 MONEY
97 98 Pendaftaran CPNS Diperpanjang 4 Hari, Pelamar ... JAKARTA, KOMPAS.com - Pemerintah telah memperp... 06/09/2024 MONEY
98 99 Harga Emas Terbaru Pegadaian, Jumat 6 Septembe... JAKARTA, KOMPAS.com - Pegadaian menyediakan be... 06/09/2024 MONEY
99 100 Harga Emas Antam Terbaru Jumat 6 September 202... JAKARTA, KOMPAS.com - Pada Jumat 6 September 2... 06/09/2024 MONEY

100 rows × 5 columns

Membuat Fungsi untuk Persiapan Crawling#

# fungsi untuk mengambil link yang akan dilakukan crawling
def extract_urls(url):
    html = urlopen(url).read()
    soup = BeautifulSoup(html, 'html.parser')

    urls = soup.find_all("a", {"class": "paging__link"})
    urls = [url.get('href') for url in urls]

    return urls

# fungsi untuk mengambil isi dari berita
def get_content(url):
    html = urlopen(url).read()
    soup = BeautifulSoup(html, 'html.parser')

    div = soup.find("div", {"class": "read__content"})
    paragraf = div.find_all("p")

    content = ''
    for p in paragraf:
        content += p.text

    return content


# fungsi utama crawling
def crawl(link = "https://indeks.kompas.com", max_money = 1, max_otomotif = 1, allow_category = ["OTOMOTIF", "MONEY"], is_train = True, title_old = []):
    # inisialisasi variabel penampung hasil berita
    news_data = []

    # inisialisasi persiapan untuk crawling berita
    last_url = extract_urls(link).pop()
    page = last_url.split('=').pop() # jumlah halaman secara otomatis
    # page = 1 # jumlah halaman secara manual

    # persiapan link yang akan dilakukan crawling
    urls = [link + '/?page=' + str(a) for a in range(1, int(page) + 1)]
    count_money = 0
    count_otomotif = 0

    # menelusuri semua link yang telah ditentukan
    for idx, url in enumerate(urls):
        if (len(news_data) == max_money + max_otomotif) :
          break

        html = urlopen(url).read()
        soup = BeautifulSoup(html, 'html.parser')

        # mengambil data yang diperlukan pada struktur html
        links       = soup.find_all("a", {"class": "article-link"})
        titles      = soup.find_all("h2", {"class": "articleTitle"})
        dates       = soup.find_all("div", {"class": "articlePost-date"})
        categories  = soup.find_all("div", {"class": "articlePost-subtitle"})

        news_per_page = len(links) # berita artikel yang ditampilkan

        # memasukkan data ke dalam list
        for elem in tqdm(range(news_per_page), desc=f"Crawling page {idx+1}"):
          news = {}
          category = categories[elem].text
          title = titles[elem].text

          if (category in allow_category):
            if (is_train):
              cond = (category == "MONEY" and count_money < max_money) or (category == "OTOMOTIF" and count_otomotif < max_otomotif)
            else:
              cond = (category == "MONEY" and count_money < max_money) or (category == "OTOMOTIF" and count_otomotif < max_otomotif) and title not in title_old


            if (cond):
              news['No'] = len(news_data) + 1
              news['Judul Berita']     = title
              news['Isi Berita']       = get_content(links[elem].get("href"))
              news['Tanggal Berita']   = dates[elem].text
              news['Kategori Berita']  = category
              news_data.append(news)

              if (category == "MONEY"):
                count_money += 1
              else:
                count_otomotif += 1

        print(f"=======> Money: {count_money} | Otomotif: {count_otomotif} | Total: {count_money + count_otomotif}")

    return news_data

function extract_urls digunakan untuk melakukan ekstraksi link url yang memiliki pagination pada halaman awal, sehingga didapat beberapa url yang bisa mengarah ke halaman selanjutnya atau sebelumnya.

function get_content digunakan untuk melakukan proses pembuatan isi berita sesuai link berita yang dicari.

Pengambilan Data Baru#

title_old = main_df["Judul Berita"].tolist()

test_news = crawl(max_money=5, max_otomotif=5, is_train=False, title_old=title_old)
Crawling page 1: 100%|██████████| 15/15 [00:00<00:00, 68.89it/s]
=======> Money: 1 | Otomotif: 0 | Total: 1
Crawling page 2: 100%|██████████| 15/15 [00:00<00:00, 30.83it/s]
=======> Money: 4 | Otomotif: 0 | Total: 4
Crawling page 3: 100%|██████████| 15/15 [00:00<00:00, 12136.30it/s]
=======> Money: 4 | Otomotif: 0 | Total: 4
Crawling page 4: 100%|██████████| 15/15 [00:00<00:00, 47.77it/s]
=======> Money: 5 | Otomotif: 0 | Total: 5
Crawling page 5: 100%|██████████| 15/15 [00:00<00:00, 36074.86it/s]
=======> Money: 5 | Otomotif: 0 | Total: 5
Crawling page 6: 100%|██████████| 15/15 [00:00<00:00, 31.37it/s]
=======> Money: 5 | Otomotif: 1 | Total: 6
Crawling page 7: 100%|██████████| 15/15 [00:00<00:00, 4068.19it/s]
=======> Money: 5 | Otomotif: 1 | Total: 6
Crawling page 8: 100%|██████████| 15/15 [00:00<00:00, 16.06it/s]
=======> Money: 5 | Otomotif: 2 | Total: 7
Crawling page 9: 100%|██████████| 15/15 [00:00<00:00, 34971.96it/s]
=======> Money: 5 | Otomotif: 2 | Total: 7
Crawling page 10: 100%|██████████| 15/15 [00:00<00:00, 23643.20it/s]
=======> Money: 5 | Otomotif: 2 | Total: 7
Crawling page 11: 100%|██████████| 15/15 [00:00<00:00, 46.79it/s]
=======> Money: 5 | Otomotif: 3 | Total: 8
Crawling page 12: 100%|██████████| 15/15 [00:00<00:00, 17327.06it/s]
=======> Money: 5 | Otomotif: 3 | Total: 8
Crawling page 13: 100%|██████████| 15/15 [00:00<00:00, 30.36it/s]
=======> Money: 5 | Otomotif: 4 | Total: 9
Crawling page 14: 100%|██████████| 15/15 [00:00<00:00, 33.93it/s]
=======> Money: 5 | Otomotif: 5 | Total: 10

main_df = pd.DataFrame(test_news)
main_df
No Judul Berita Isi Berita Tanggal Berita Kategori Berita
0 1 Harga Bitcoin Kembali Sentuh Rekor Tertinggi, ... JAKARTA, KOMPAS.com - Harga bitcoin kembali me... 07/11/2024 MONEY
1 2 PNM Kembali Buka Unit Mekaar di Wilayah 3T JAKARTA, KOMPAS.com – PT Permodalan Nasional M... 07/11/2024 MONEY
2 3 Djoko Siswanto Dilantik Jadi Kepala SKK Migas ... JAKARTA, KOMPAS.com - Menteri Energi dan Sumbe... 07/11/2024 MONEY
3 4 Apakah Danantara Bisa Berbisnis? Ini Penjelasa... JAKARTA, KOMPAS.com - Menteri Badan Usaha Mili... 07/11/2024 MONEY
4 5 Moratorium Kenaikan Tarif Cukai Penting untuk ... JAKARTA, KOMPAS.com - Pusat Penelitian Kebijak... 07/11/2024 MONEY
5 6 MPV Listrik Maxus Mifa 7 Dijadwalkan Meluncur ... JAKARTA, KOMPAS.com - Maxus akan resmi berbisn... 07/11/2024 OTOMOTIF
6 7 Maxus Mifa 9 yang Meluncur di GJAW 2024 Sudah ... JAKARTA, KOMPAS.com - Maxus Mifa 9 akan resmi ... 07/11/2024 OTOMOTIF
7 8 United E-Motor C2000 Resmi Meluncur, Harga mul... JAKARTA, KOMPAS.com - United E-Motor resmi me... 07/11/2024 OTOMOTIF
8 9 Kata AHM Soal Wacana Sepeda Motor Wajib Pakai ... JAKARTA, KOMPAS.com – Kementerian Perhubungan ... 07/11/2024 OTOMOTIF
9 10 Merasakan Fitur Corolla Cross Hybrid GR Sport,... JAKARTA, KOMPAS.com - Toyota Corolla Cross Hyb... 07/11/2024 OTOMOTIF

Praproses Teks#

Membuat Fungsi#

# Case Folding
def clean_lower(lwr):
    lwr = lwr.lower() # lowercase text
    return lwr

# Menghapus tanda baca, angka, dan simbol
def clean_punct(text):
    clean_spcl = re.compile('[/(){}\[\]\|@,;_]')
    clean_symbol = re.compile('[^0-9a-z]')
    clean_number = re.compile('[0-9]')
    text = clean_spcl.sub('', text)
    text = clean_symbol.sub(' ', text)
    text = clean_number.sub('', text)
    return text

# Menghaps double atau lebih whitespace
def _normalize_whitespace(text):
    corrected = str(text)
    corrected = re.sub(r"//t",r"\t", corrected)
    corrected = re.sub(r"( )\1+",r"\1", corrected)
    corrected = re.sub(r"(\n)\1+",r"\1", corrected)
    corrected = re.sub(r"(\r)\1+",r"\1", corrected)
    corrected = re.sub(r"(\t)\1+",r"\1", corrected)
    return corrected.strip(" ")

# Menghapus stopwords
def clean_stopwords(text):
    stopword = set(stopwords.words('indonesian'))
    text = ' '.join(word for word in text.split() if word not in stopword) # hapus stopword dari kolom deskripsi
    return text

# Stemming with Sastrawi
def sastrawistemmer(text):
    factory = StemmerFactory()
    st = factory.create_stemmer()
    text = ' '.join(st.stem(word) for word in tqdm(text.split()) if word in text)
    return text

function clean_lower digunakan untuk merubah semua kata atau huruf menjadi huruf kecil semua

function clean_punct digunakan untuk menghapus karakter, simbol, dan angka

function _normalize_whitespace digunakan untuk menghapus spasi yang double atau lebih dari 2 spasi

function clean_stopwords digunakan untuk menghilangkan kata yang tidak perlu (kata hubung, kata tambahan dll)

function sastrawistemmer digunakan untuk proses stemming (mendapatkan kata dasar dari suatu kata)

Clean Lower#

# Buat kolom tambahan untuk data description yang telah dilakukan proses case folding
main_df['lwr'] = main_df['Isi Berita'].apply(clean_lower)
casefolding=pd.DataFrame(main_df['lwr'])
casefolding
lwr
0 jakarta, kompas.com - harga bitcoin kembali me...
1 jakarta, kompas.com – pt permodalan nasional m...
2 jakarta, kompas.com - menteri energi dan sumbe...
3 jakarta, kompas.com - menteri badan usaha mili...
4 jakarta, kompas.com - pusat penelitian kebijak...
5 jakarta, kompas.com - maxus akan resmi berbisn...
6 jakarta, kompas.com - maxus mifa 9 akan resmi ...
7 jakarta, kompas.com - united e-motor resmi me...
8 jakarta, kompas.com – kementerian perhubungan ...
9 jakarta, kompas.com - toyota corolla cross hyb...

Clean Punct#

# Buat kolom tambahan untuk data description yang telah dilakukan proses penghapusan tanda baca
main_df['clean_punct'] = main_df['lwr'].apply(clean_punct)
main_df['clean_punct']
clean_punct
0 jakarta kompas com harga bitcoin kembali men...
1 jakarta kompas com pt permodalan nasional ma...
2 jakarta kompas com menteri energi dan sumber...
3 jakarta kompas com menteri badan usaha milik...
4 jakarta kompas com pusat penelitian kebijaka...
5 jakarta kompas com maxus akan resmi berbisni...
6 jakarta kompas com maxus mifa akan resmi di...
7 jakarta kompas com united e motor resmi men...
8 jakarta kompas com kementerian perhubungan b...
9 jakarta kompas com toyota corolla cross hybr...

Normalize Whitespace#

main_df['clean_double_ws'] = main_df['clean_punct'].apply(_normalize_whitespace)
main_df['clean_double_ws']
clean_double_ws
0 jakarta kompas com harga bitcoin kembali menca...
1 jakarta kompas com pt permodalan nasional mada...
2 jakarta kompas com menteri energi dan sumber d...
3 jakarta kompas com menteri badan usaha milik n...
4 jakarta kompas com pusat penelitian kebijakan ...
5 jakarta kompas com maxus akan resmi berbisnis ...
6 jakarta kompas com maxus mifa akan resmi dijua...
7 jakarta kompas com united e motor resmi menjua...
8 jakarta kompas com kementerian perhubungan ber...
9 jakarta kompas com toyota corolla cross hybrid...

Clean Stopwords#

# Buat kolom tambahan untuk data description yang telah dilakukan proses penghapusan stopwords
main_df['clean_sw'] = main_df['clean_double_ws'].apply(clean_stopwords)
main_df['clean_sw']
clean_sw
0 jakarta kompas com harga bitcoin mencapai reko...
1 jakarta kompas com pt permodalan nasional mada...
2 jakarta kompas com menteri energi sumber daya ...
3 jakarta kompas com menteri badan usaha milik n...
4 jakarta kompas com pusat penelitian kebijakan ...
5 jakarta kompas com maxus resmi berbisnis indon...
6 jakarta kompas com maxus mifa resmi dijual pam...
7 jakarta kompas com united e motor resmi menjua...
8 jakarta kompas com kementerian perhubungan ber...
9 jakarta kompas com toyota corolla cross hybrid...

Stemming dengan Sastrawi#

# Buat kolom tambahan untuk data description yang telah dilemmatization
main_df['desc_clean_stem'] = main_df['clean_sw'].apply(sastrawistemmer)
main_df['desc_clean_stem']
100%|██████████| 169/169 [00:11<00:00, 14.28it/s]
100%|██████████| 134/134 [00:11<00:00, 11.79it/s]
100%|██████████| 187/187 [00:14<00:00, 13.25it/s]
100%|██████████| 162/162 [00:06<00:00, 25.37it/s]
100%|██████████| 197/197 [00:03<00:00, 55.28it/s]
100%|██████████| 146/146 [00:06<00:00, 21.11it/s]
100%|██████████| 165/165 [00:05<00:00, 30.92it/s]
100%|██████████| 221/221 [00:06<00:00, 34.55it/s]
100%|██████████| 207/207 [00:07<00:00, 27.65it/s]
100%|██████████| 261/261 [00:11<00:00, 22.67it/s]
desc_clean_stem
0 jakarta kompas com harga bitcoin capai rekor t...
1 jakarta kompas com pt modal nasional madani pn...
2 jakarta kompas com menteri energi sumber daya ...
3 jakarta kompas com menteri badan usaha milik n...
4 jakarta kompas com pusat teliti bijak ekonomi ...
5 jakarta kompas com maxus resmi bisnis indonesi...
6 jakarta kompas com maxus mifa resmi jual pamer...
7 jakarta kompas com united e motor resmi jual s...
8 jakarta kompas com menteri hubung wacana rem a...
9 jakarta kompas com toyota corolla cross hybrid...

Pembuatan VSM#

# Load the saved model from file
github_raw_url = "https://raw.githubusercontent.com/meinhere/ppw/master/publish/tugas-6/model/tfidf_vectorizer.sav"

response = requests.get(github_raw_url)
response.raise_for_status()

vectorizer = pickle.loads(response.content)
vectorizer
TfidfVectorizer()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
corpus = main_df['desc_clean_stem']
tfidf = vectorizer.transform(corpus)

tfidf.shape
(10, 3106)
vocabulary = vectorizer.get_feature_names_out().tolist()

tfidf_df = pd.DataFrame(tfidf.toarray(), columns=vocabulary)
tfidf_df['label'] = main_df['Kategori Berita'].tolist()
tfidf_df
aaion aali abadi abai abenkh abnormal absurd ac acara access ... yzr za zad zaman zarco zenix zero zigzag zona label
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 MONEY
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 MONEY
2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 MONEY
3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 MONEY
4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 MONEY
5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 OTOMOTIF
6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 OTOMOTIF
7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 OTOMOTIF
8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 OTOMOTIF
9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.04023 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 OTOMOTIF

10 rows × 3107 columns

Konversi ke SVD#

# Load the saved model from file
github_raw_url = "https://raw.githubusercontent.com/meinhere/ppw/master/publish/tugas-6/model/svd_model.pkl"

response = requests.get(github_raw_url)
response.raise_for_status()

svd = pickle.loads(response.content)
svd
TruncatedSVD(n_components=80)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
svd_df = tfidf_df.copy()
svd_df.drop(columns=['label'], inplace=True)

svd_df
aaion aali abadi abai abenkh abnormal absurd ac acara access ... yusdistira yzr za zad zaman zarco zenix zero zigzag zona
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00000 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.04023 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

10 rows × 3106 columns

svd.transform(svd_df)
array([[ 1.85530036e-01, -1.27696577e-01, -3.80916073e-02,
        -7.97553205e-02,  6.99959863e-02, -1.31089992e-01,
         1.29845036e-02, -1.08912924e-01, -9.75001220e-02,
        -5.01598350e-02, -1.31402510e-01,  4.00235219e-02,
        -1.06742480e-02,  1.59025029e-02,  1.63229279e-02,
         2.35818378e-03,  1.76122804e-02, -4.86398219e-02,
        -4.22725743e-02, -3.58899347e-02, -1.77636094e-02,
        -2.13620343e-02,  4.35994583e-02,  4.14258709e-02,
        -5.14539962e-02, -2.42116341e-02, -1.73485413e-02,
         3.30130855e-02, -3.86310533e-02,  1.82186195e-03,
         5.70401442e-02,  4.85326049e-02, -1.01714742e-02,
         1.43632293e-02,  5.20875640e-02,  3.04955635e-02,
         1.81480338e-03, -2.13612556e-02, -3.43864878e-02,
        -5.46103374e-02, -8.45259414e-03, -1.35638073e-02,
         2.44574768e-02,  3.69165136e-02,  1.24559322e-02,
         5.29608707e-03,  2.47701219e-02, -2.20122930e-02,
         4.32358364e-02, -1.59787781e-02, -2.15425392e-02,
         3.48845543e-02,  5.66693163e-03, -1.07832492e-02,
        -1.91263675e-02,  1.11081016e-03,  8.18604522e-03,
         2.00234379e-02, -2.81679769e-02, -9.55570671e-03,
        -2.43007550e-02, -1.27212047e-02,  1.93220932e-02,
         8.74626872e-03,  1.51233591e-02, -2.10778491e-03,
        -1.10673802e-02,  9.59346133e-03,  2.79527242e-03,
        -6.28306419e-03,  2.28599653e-02,  7.39829087e-04,
         2.32668427e-02,  9.78087307e-03, -4.84447735e-02,
         1.74182704e-02, -1.60006498e-02, -8.64420361e-03,
        -1.84820779e-04, -7.93515560e-03],
       [ 1.81555968e-01, -1.32466317e-01,  1.10330741e-02,
        -6.28662466e-02,  4.58039270e-02, -2.30099409e-02,
        -4.53330067e-02, -1.87337700e-02,  2.64518426e-02,
         1.92862880e-02,  5.75246215e-02, -6.50795182e-02,
        -7.87948334e-02,  4.07648809e-03,  8.40860439e-02,
        -5.02950466e-02, -6.84958530e-03,  5.72148228e-03,
         1.72716870e-02,  4.09534478e-02,  1.07545258e-02,
         5.51463753e-03, -1.37966478e-03, -3.03767098e-02,
        -4.78012018e-02,  2.90855070e-02, -2.83178962e-03,
         1.87844209e-02,  2.98269466e-02,  1.74557941e-02,
         9.89300430e-03,  5.43004496e-02, -3.87650656e-02,
         9.57090937e-03, -3.03129303e-02,  2.39567393e-02,
         2.59193625e-02, -4.58898805e-02, -2.09592827e-03,
        -3.88407888e-02, -2.94134970e-02, -6.32186224e-04,
        -1.37165883e-02, -3.38285027e-02, -5.38940362e-02,
         2.51638737e-02, -8.03435588e-03,  1.62710952e-02,
        -5.27465387e-02,  1.94280801e-02,  3.56420836e-02,
         8.62133261e-03,  4.71009739e-02,  8.93354668e-03,
        -3.51670152e-02, -1.84971959e-02,  5.81274729e-02,
        -8.07393455e-04,  4.94848610e-03, -4.48831947e-03,
         9.95652043e-03,  4.43141869e-03,  2.87636628e-02,
         8.56948214e-05,  1.99589806e-02, -1.51756535e-02,
        -2.84536740e-03, -2.55183066e-02, -4.75819500e-02,
         2.63922251e-02,  3.49084114e-02, -7.48541979e-03,
         2.26066981e-02,  1.03491545e-02,  3.26169329e-03,
         5.40750331e-03, -1.77590372e-02, -5.25483670e-03,
        -4.53855415e-03,  2.07517474e-02],
       [ 1.08025273e-01, -7.16939569e-02,  2.25538244e-04,
        -3.69435921e-02,  4.01622803e-02, -1.57711053e-02,
         6.18400985e-03, -9.88120928e-03, -7.25323900e-04,
        -3.22366897e-03, -3.90132059e-03, -2.74564854e-02,
        -1.99543639e-02,  1.23056491e-02, -3.34516567e-03,
        -2.25620770e-02,  5.74842146e-02, -3.23078495e-04,
         2.52835000e-04, -3.27868246e-02, -2.35191672e-02,
         8.19722625e-04,  2.21312916e-02,  1.36963594e-02,
        -2.62400885e-02, -1.91381694e-02,  2.28988697e-02,
         2.75369221e-02,  2.29284114e-02,  9.76126717e-05,
         1.22909412e-02, -1.87937091e-02,  3.04092608e-02,
         1.56867975e-02, -1.45409537e-02,  4.89737417e-02,
        -2.11817421e-02, -4.36592283e-02, -5.72723405e-02,
        -1.38903600e-02,  4.28722508e-02, -5.68103806e-02,
         1.87975200e-02,  5.70881821e-02,  4.45150899e-02,
        -2.27703171e-02, -1.60445560e-02, -8.33146202e-03,
         2.61223715e-02, -1.94287950e-02,  1.44131279e-02,
        -4.84445303e-02,  8.26369283e-03,  1.13560031e-02,
        -2.30207065e-02,  1.23407223e-02, -1.29769906e-02,
         9.04331488e-03, -1.85320915e-02,  2.40397376e-02,
         1.84653250e-02,  2.35918901e-03,  8.65256009e-03,
         1.31175918e-03,  9.70151037e-03,  2.58690118e-02,
         5.14953304e-03, -1.51129091e-03, -1.93917397e-03,
         6.29498685e-03,  7.82346017e-03, -8.70810429e-03,
        -7.28526825e-03,  3.68499946e-03, -2.65626542e-03,
        -2.10144325e-02,  1.63190614e-03,  2.71491411e-03,
         1.47600912e-02,  2.50467198e-02],
       [ 1.18053801e-01, -1.02630619e-01,  2.91495146e-02,
        -4.55669255e-02,  1.92697097e-02,  9.51096807e-03,
        -1.47049071e-02, -5.45717638e-03,  2.45492059e-02,
        -2.67707089e-02,  6.07598710e-02, -1.76006227e-02,
        -2.38889915e-02,  2.32745142e-02,  7.52827332e-02,
        -1.47735115e-02, -3.96226657e-03,  1.47635054e-02,
         2.61051666e-02, -6.75057237e-03, -5.07150211e-02,
        -1.20878754e-02, -4.83196206e-02,  1.23788596e-02,
        -2.56626964e-02,  2.62473466e-02,  2.44647424e-02,
         1.28579347e-02, -1.65763186e-02, -2.19152373e-02,
        -1.59488959e-02,  2.60800580e-02,  1.17565957e-02,
        -4.28946760e-03,  2.67042263e-03,  5.52171512e-02,
        -2.04594287e-02,  1.62203567e-02,  1.16406096e-02,
         5.21329477e-03, -2.17013884e-02,  1.91935419e-02,
         1.28622510e-02,  9.55381365e-03,  1.61478089e-03,
        -2.11879415e-02,  1.39424222e-02,  9.39037149e-03,
        -3.62779456e-02, -2.21134003e-02,  3.65485259e-02,
         5.18898893e-04, -1.03173746e-02, -1.08712587e-02,
         3.52684662e-02, -3.02109891e-02, -3.93941110e-03,
         1.02703728e-02, -3.49371780e-02,  6.22423387e-03,
         1.34549661e-02,  7.38570526e-03,  8.29632828e-03,
        -1.13650975e-02, -4.69230193e-05,  1.80181149e-03,
        -2.64134635e-02, -3.48350623e-02,  6.42483409e-03,
         2.00183831e-02, -1.33465216e-02, -4.23760824e-03,
         8.64074362e-03, -6.33471048e-03, -2.85419816e-03,
         7.89613844e-03, -1.41842327e-02, -2.53063399e-03,
         2.33007439e-02,  3.24083853e-03],
       [ 1.04932996e-01, -6.99619313e-02,  2.93528509e-03,
        -3.83515622e-02,  2.65407063e-02, -3.79300725e-02,
         3.38389131e-03, -1.87212803e-02,  6.77409487e-03,
         4.63625336e-03,  2.22046052e-03, -4.03703163e-02,
        -1.20172422e-02,  5.76362891e-02,  1.47291246e-02,
        -2.89352061e-02,  1.70203036e-03,  5.23529447e-02,
        -1.26614322e-03, -9.78940635e-02,  3.50793617e-02,
        -3.33688623e-02, -1.09080854e-01,  7.49740212e-02,
         4.76892798e-02, -2.92626406e-02,  5.50238431e-02,
        -2.74082155e-03,  5.20298331e-03,  1.34035395e-02,
        -1.06078484e-02,  6.62526734e-02,  6.85139016e-03,
         2.88603838e-02,  1.69312694e-02,  7.67561225e-02,
         7.58188805e-02,  3.91409957e-02, -1.24776910e-01,
         2.10060728e-03,  3.57492699e-02, -7.61411569e-03,
         3.45699532e-03,  3.92215947e-03,  1.44856806e-02,
         4.99786078e-02, -1.78428344e-02, -9.67878568e-02,
        -1.04290459e-01,  1.01081311e-01, -1.75365313e-02,
        -8.72621289e-03, -6.83098023e-02, -5.96589815e-03,
         2.56463909e-02,  7.92779559e-03,  2.09833163e-02,
        -3.05587694e-02,  1.22249099e-02, -9.83096092e-03,
        -1.55220755e-02,  9.56665253e-03,  2.41689967e-03,
         1.46850861e-02, -3.35333477e-02,  2.90391320e-02,
         2.50357909e-03,  4.09694007e-03,  1.55357441e-03,
        -1.98331937e-03, -8.83837596e-03, -5.64762085e-03,
        -1.73983631e-02, -9.98193823e-03, -1.20156145e-02,
         1.68948404e-02, -4.78423512e-02,  1.27916625e-02,
         3.68419999e-03, -2.40812875e-03],
       [ 2.41873192e-01, -5.80565364e-02, -3.77000176e-02,
         2.83194876e-02, -6.06360032e-02,  7.28592963e-03,
         3.25335302e-02,  5.28943727e-03, -3.29732362e-03,
         9.24561140e-02, -6.89744440e-03, -3.70941522e-02,
         9.61340336e-02,  2.20461749e-02, -1.08487499e-02,
         2.99071490e-02, -5.40032668e-02,  1.24089303e-03,
        -4.45874585e-02,  2.29191469e-03, -2.94730957e-02,
         8.59274579e-03, -1.31915689e-02, -6.93563118e-02,
        -1.71199594e-02,  1.03845469e-02,  1.17054872e-03,
         3.17788045e-02,  1.85279980e-02,  3.58328483e-02,
         1.16822797e-02,  1.13459443e-02, -1.17961505e-02,
         6.42721622e-03,  2.85882644e-02, -2.21527811e-02,
        -2.59644120e-03,  1.60137308e-02, -1.95147100e-02,
        -5.19108842e-03, -2.86769240e-03,  6.91042617e-04,
         2.28624882e-02,  3.05130635e-02, -7.51483912e-03,
        -1.03259602e-02,  2.60517777e-03,  1.33226828e-02,
        -1.08110356e-02, -7.92625317e-03,  2.61128872e-02,
        -5.05399631e-03,  3.44465641e-03,  1.88426563e-02,
        -3.14709525e-02,  5.44825052e-02, -1.75331309e-02,
        -1.40697402e-02,  4.13598775e-02,  3.89451992e-02,
        -3.32329179e-03,  2.43997836e-02,  6.36548060e-03,
        -1.18056504e-02,  3.14655538e-02, -1.06991243e-02,
        -3.64954333e-02,  4.52988856e-03, -2.50975228e-03,
        -2.67212809e-02,  4.42924694e-02,  1.01153872e-02,
         1.90820249e-03, -3.95738640e-03,  2.29816330e-02,
         7.20507141e-03,  4.37409408e-02, -2.02731625e-02,
        -2.15453351e-02, -1.16881248e-02],
       [ 2.09487669e-01, -5.46321629e-03, -5.31484817e-02,
         9.19017602e-03, -3.12069687e-02, -1.97664587e-02,
         1.59847432e-02,  1.52577945e-02,  1.96821858e-02,
         5.27291381e-02, -3.08031039e-03,  7.54121877e-04,
         5.77590985e-03,  2.94049659e-02, -5.75834265e-03,
         4.15204995e-02, -3.34525756e-02, -9.37375451e-03,
         9.57942327e-04, -3.60598575e-03, -1.72539313e-02,
         1.62861490e-02,  2.42585081e-02,  7.42340727e-03,
         2.84349908e-02,  2.53388707e-02,  9.77385541e-03,
         4.14572867e-02,  3.45511281e-03,  1.35442226e-02,
         1.17730786e-02,  8.41880585e-03,  5.59496963e-03,
        -1.00463794e-02,  2.22481239e-02, -3.48340639e-03,
         6.91397824e-03, -1.67275620e-02, -9.76439497e-03,
         4.67140901e-03, -1.03512910e-03,  2.12056596e-03,
         8.83029208e-03, -1.62876642e-02,  1.98088447e-02,
        -1.88428645e-02,  5.01123519e-02,  4.81623344e-03,
        -1.38990900e-02,  1.25730826e-02,  7.28539959e-03,
         3.83879643e-04,  1.10481511e-03,  1.20871414e-02,
        -2.44441040e-02,  2.50156646e-02, -1.21578676e-02,
        -2.04695543e-02,  1.63570464e-02,  5.32988540e-03,
        -3.36827078e-02,  1.54710532e-02,  1.21981170e-03,
        -7.70168227e-03, -5.26641434e-03,  1.72772214e-02,
        -1.10986061e-03, -4.42646653e-02,  1.08144829e-02,
        -2.34533340e-02,  6.03435744e-02,  6.76666596e-03,
        -2.61742437e-02, -1.76034022e-02,  2.34833172e-02,
         1.05713461e-02,  1.43891290e-02, -1.07160573e-02,
        -8.70909505e-03,  1.34072480e-02],
       [ 2.36427122e-01, -8.59559169e-03, -5.06928021e-02,
        -7.23370684e-03,  4.87229694e-02,  9.41475060e-02,
         1.38973289e-02, -7.76281695e-02,  1.98172140e-02,
         1.35887040e-01,  5.80620427e-02,  3.33537890e-02,
         2.29509270e-01, -9.14019382e-02,  2.04249820e-02,
         6.56101500e-02, -3.67763994e-02,  2.67194840e-02,
        -7.25365547e-02,  4.62112478e-02, -1.83010119e-03,
        -1.10589925e-02, -3.53804019e-02, -3.93250236e-02,
        -4.98597555e-02, -3.47403903e-02,  1.42293522e-02,
         2.08255029e-02, -1.35827915e-02, -2.00922815e-02,
         2.53727760e-02,  1.43180277e-03, -1.67845618e-02,
         2.26690541e-02, -6.27970348e-03, -2.54763088e-02,
         4.80798014e-02, -9.72167256e-03, -2.57559178e-02,
        -2.18321149e-02,  1.88765180e-02,  5.00229671e-02,
        -2.50299435e-02,  1.85881114e-02,  1.49818328e-02,
         4.07929212e-02,  6.88313743e-02, -1.67546586e-02,
        -3.65918758e-02,  1.07031380e-02,  3.99758001e-02,
         3.20078038e-02,  6.64323294e-03,  6.91688767e-02,
        -7.33333173e-02,  3.87488521e-02, -5.88189023e-02,
         6.20351876e-03, -1.63066781e-03, -3.48696362e-02,
        -3.47535602e-02, -2.16524603e-02,  5.38594530e-02,
        -1.32199894e-02, -4.20985159e-02, -3.17662448e-02,
         4.39545628e-02, -2.73327967e-02, -5.56596639e-02,
        -6.23520169e-03,  1.78358791e-02,  3.65974710e-02,
        -2.51668312e-02, -1.42426507e-02,  8.42699920e-02,
         1.05030457e-02, -1.48396788e-02,  1.40282370e-02,
         3.24536173e-03, -1.05502177e-02],
       [ 2.82602043e-01, -1.97300489e-02,  7.26043913e-02,
         6.89076960e-02, -6.56071706e-03,  1.15046997e-01,
        -4.09983233e-02, -3.09408379e-02,  1.20111641e-03,
         7.51017028e-02,  2.29530574e-02, -6.06244542e-02,
         7.89477357e-02, -5.48511272e-02,  4.62001956e-02,
         4.00523935e-02, -2.75950349e-03, -2.64459824e-02,
        -1.27489850e-02, -3.45125369e-02,  1.60670009e-02,
         8.23133721e-02,  4.81610902e-02, -2.35278443e-02,
        -5.92755812e-03, -5.76509575e-02, -4.17310567e-03,
        -4.06711932e-02, -7.41776730e-03, -4.92887301e-03,
         1.45916447e-02, -2.58232122e-02,  1.15554833e-03,
         2.38523144e-02,  5.30851925e-03,  8.94554327e-03,
         3.62105990e-02, -5.29370898e-03, -1.04593067e-02,
        -8.12347103e-03,  4.62765287e-02,  5.18505657e-02,
         2.34383840e-02, -1.26108262e-03,  2.29925254e-02,
         9.13034219e-03,  2.46631656e-02, -4.04568514e-02,
         2.59723073e-02, -3.63049817e-03,  3.30141593e-02,
         3.57035328e-02,  3.22515398e-02,  3.13770329e-02,
         1.24432607e-02,  7.89013203e-03, -5.17578232e-02,
        -1.53653290e-02,  1.55419481e-02, -2.51019729e-02,
        -4.42811330e-02, -1.26164002e-02,  3.41494143e-02,
        -3.37932135e-02,  1.43404438e-02, -3.45523650e-02,
         2.35658892e-02, -1.05119204e-02, -2.47855161e-02,
         5.56079501e-03, -2.13162057e-02, -1.20495866e-02,
        -1.45556339e-02,  3.42545515e-02,  1.74862770e-02,
        -1.98003998e-02,  7.69283825e-02,  2.94506708e-02,
         1.49548388e-03, -3.81724871e-02],
       [ 2.86494046e-01,  4.69921795e-02, -9.82816821e-02,
         9.26521298e-02, -5.99163206e-02,  2.02248676e-02,
        -9.98406975e-02,  6.46518912e-02, -3.08878467e-02,
         2.41681688e-02, -1.17132975e-02, -3.51487583e-02,
        -1.64530060e-03,  2.64759853e-02, -3.18107879e-02,
         4.50980755e-02, -7.82456644e-02,  2.31130541e-02,
         3.60612371e-02, -4.66096143e-02, -3.41793403e-02,
         3.58492153e-02,  3.37194599e-02,  8.23987755e-03,
        -9.12598536e-05,  1.79176625e-04, -7.15572819e-04,
         4.83028464e-03, -1.62819908e-03,  6.98231343e-03,
         1.30882052e-02,  5.11241370e-03, -8.91062616e-03,
         2.47885667e-02,  2.03528699e-02, -3.71819858e-02,
        -3.11529310e-02, -2.08953857e-03,  1.30322204e-04,
         3.77220530e-03, -9.65121609e-03, -2.39218330e-02,
        -2.06416361e-02,  4.01681984e-02, -4.40942617e-02,
        -4.58721553e-02,  2.41026360e-02,  2.60194941e-03,
         2.56907991e-02,  1.18043978e-02,  8.18365084e-03,
        -2.41933480e-02, -5.32216344e-03, -3.35099192e-02,
         3.67207041e-02, -1.11233495e-02, -1.31378996e-02,
        -3.84650229e-02,  2.65457168e-02, -2.88034759e-02,
         5.25929488e-02, -1.28495632e-01, -1.19212261e-02,
         1.63404795e-02, -4.17211017e-03,  4.46336455e-03,
         1.76664732e-02,  7.19033503e-03, -1.20039044e-03,
         2.02557206e-03,  6.32996273e-03,  3.00726156e-02,
        -2.54942685e-03,  1.70656829e-02, -4.15314302e-03,
        -3.04680917e-02,  1.57448830e-02,  2.37188372e-02,
        -1.26977796e-03, -4.29130134e-02]])
# menggunakan label_encoder untuk merubah kata menjadi angka
label_encoder = preprocessing.LabelEncoder()

svd_df = pd.DataFrame(svd.transform(svd_df), columns=[f"fitur_{i}" for i in range(n)])
svd_df['label'] = label_encoder.fit_transform(tfidf_df['label'])

svd_df
fitur_0 fitur_1 fitur_2 fitur_3 fitur_4 fitur_5 fitur_6 fitur_7 fitur_8 fitur_9 ... fitur_71 fitur_72 fitur_73 fitur_74 fitur_75 fitur_76 fitur_77 fitur_78 fitur_79 label
0 0.185530 -0.127697 -0.038092 -0.079755 0.069996 -0.131090 0.012985 -0.108913 -0.097500 -0.050160 ... 0.000740 0.023267 0.009781 -0.048445 0.017418 -0.016001 -0.008644 -0.000185 -0.007935 0
1 0.181556 -0.132466 0.011033 -0.062866 0.045804 -0.023010 -0.045333 -0.018734 0.026452 0.019286 ... -0.007485 0.022607 0.010349 0.003262 0.005408 -0.017759 -0.005255 -0.004539 0.020752 0
2 0.108025 -0.071694 0.000226 -0.036944 0.040162 -0.015771 0.006184 -0.009881 -0.000725 -0.003224 ... -0.008708 -0.007285 0.003685 -0.002656 -0.021014 0.001632 0.002715 0.014760 0.025047 0
3 0.118054 -0.102631 0.029150 -0.045567 0.019270 0.009511 -0.014705 -0.005457 0.024549 -0.026771 ... -0.004238 0.008641 -0.006335 -0.002854 0.007896 -0.014184 -0.002531 0.023301 0.003241 0
4 0.104933 -0.069962 0.002935 -0.038352 0.026541 -0.037930 0.003384 -0.018721 0.006774 0.004636 ... -0.005648 -0.017398 -0.009982 -0.012016 0.016895 -0.047842 0.012792 0.003684 -0.002408 0
5 0.241873 -0.058057 -0.037700 0.028319 -0.060636 0.007286 0.032534 0.005289 -0.003297 0.092456 ... 0.010115 0.001908 -0.003957 0.022982 0.007205 0.043741 -0.020273 -0.021545 -0.011688 1
6 0.209488 -0.005463 -0.053148 0.009190 -0.031207 -0.019766 0.015985 0.015258 0.019682 0.052729 ... 0.006767 -0.026174 -0.017603 0.023483 0.010571 0.014389 -0.010716 -0.008709 0.013407 1
7 0.236427 -0.008596 -0.050693 -0.007234 0.048723 0.094148 0.013897 -0.077628 0.019817 0.135887 ... 0.036597 -0.025167 -0.014243 0.084270 0.010503 -0.014840 0.014028 0.003245 -0.010550 1
8 0.282602 -0.019730 0.072604 0.068908 -0.006561 0.115047 -0.040998 -0.030941 0.001201 0.075102 ... -0.012050 -0.014556 0.034255 0.017486 -0.019800 0.076928 0.029451 0.001495 -0.038172 1
9 0.286494 0.046992 -0.098282 0.092652 -0.059916 0.020225 -0.099841 0.064652 -0.030888 0.024168 ... 0.030073 -0.002549 0.017066 -0.004153 -0.030468 0.015745 0.023719 -0.001270 -0.042913 1

10 rows × 81 columns

Testing Data#

# Load the saved model from file
github_raw_url = "https://raw.githubusercontent.com/meinhere/ppw/master/publish/tugas-6/model/lr_model.sav"

response = requests.get(github_raw_url)
response.raise_for_status()

lr_model = pickle.loads(response.content)
lr_model
LogisticRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
y_test = svd_df['label']
x_test = svd_df.drop(['label'], axis=1)
y_pred = lr_model.predict(x_test)

print(y_pred)
[0 0 0 0 0 1 1 1 1 1]
# melihat nilai actual dan predicted
a = pd.DataFrame({'Actual value': y_test, 'Predicted value':y_pred})
a
Actual value Predicted value
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 1 1
6 1 1
7 1 1
8 1 1
9 1 1
# Evaluation metrics
print(classification_report(y_test, y_pred))

# Confusion matrix
cm = confusion_matrix(y_test, y_pred)
print("Confusion Matrix:")
print(cm)

# Plotting the confusion matrix (optional)
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues',
            xticklabels=label_encoder.classes_,
            yticklabels=label_encoder.classes_)
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.title('Confusion Matrix')
plt.show()
              precision    recall  f1-score   support

           0       1.00      1.00      1.00         5
           1       1.00      1.00      1.00         5

    accuracy                           1.00        10
   macro avg       1.00      1.00      1.00        10
weighted avg       1.00      1.00      1.00        10

Confusion Matrix:
[[5 0]
 [0 5]]
../_images/a9cb6ffe95f85b1d5d15c07e6820ba5799733f41f841509c0a8f73e61f02a053.png