<jupyter_start><jupyter_text><jupyter_code>#Import library numpy, pandas dan sclikit-learn
import numpy as np
import pandas as pd
from sklearn import tree
#Membaca dataset dari file ke pandas dataFrame
irisDataset = pd.read_csv('horses.csv', delimiter=',', header=0)
irisDataset.head()
#mengubah kelas (kolom "species") dari string ke unique-integer
irisDataset["prize_money"] = pd.factorize(irisDataset.prize_money)[0]
irisDataset.head()
print(irisDataset)
#menghapus kolom "id"
irisDataset = irisDataset.drop(labels="id", axis=1)
print(irisDataset)
#mengubah dataframe ke array numpy
irisDataset = irisDataset.to_numpy()
print(irisDataset)
#membagi dataset => 80 baris data untuk training dan 20 baris data untuk testing
dataTraining = np.concatenate((irisDataset[0:20, :], irisDataset[60:100, :]), axis=0)
dataTesting = np.concatenate((irisDataset[20:60, :], irisDataset[100:200, :]), axis=0)                              
print(dataTraining)
len(dataTraining)
print(dataTesting)
len(dataTesting)
#memecah dataset ke input label
inputTraining = dataTraining[:, 0:1]
inputTesting = dataTesting[:, 0:1]
labelTraining = dataTraining[:, 1]
labelTesting = dataTesting[:, 1]
print(labelTraining)
len(labelTraining)
#mendefinisikan decision tree classifier
model = tree.DecisionTreeClassifier()
#mentraining model
model = model.fit(inputTraining, labelTraining)
#memprediksi input data testing
hasilPrediksi = model.predict(inputTesting)
print("Label Sebenarnya : ", labelTesting)
print("Hasil Prediksi : ", hasilPrediksi)
#menghitung akurasi
prediksiBenar = (hasilPrediksi == labelTesting).sum()
prediksiSalah = (hasilPrediksi != labelTesting).sum()
print("Prediksi Benar :", prediksiBenar, "data")
print("Prediksi Salah :", prediksiSalah, "data")
print("Akurasi :", prediksiBenar/(prediksiBenar+prediksiSalah) * 100, "%")<jupyter_output>Prediksi Benar : 79 data
Prediksi Salah : 61 data
Akurasi : 56.42857142857143 %
{'fraction_non_alphanumeric': 0.1206896551724138, 'fraction_numerical': 0.029258098223615466, 'mean_word_length': 7.114406779661017, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '124724', 'license': 'Apache-2.0', 'n_tokens_mistral': 710, 'n_tokens_neox': 673, 'n_words': 153, 'path': 'Decision_Tree.ipynb', 'repo_name': 'AdityaFaisal/DecisionTree_DataMining', 'size': '1914'}