From bc51f669b3ed911f1eba6920ecedfdb2e63d0760 Mon Sep 17 00:00:00 2001
From: 202210715336 ADITIYA ELFAN CRISIYO <202210715336@mhs.ubharajaya.ac.id>
Date: Fri, 13 Nov 2026 16:49:05 +0700
Subject: [PATCH] Upload files to "/"
Upload Source Code EAS pembelajaran mesin
---
Kelompok 1 ETS.ipynb | 1 +
1 file changed, 1 insertion(+)
create mode 100644 Kelompok 1 ETS.ipynb
diff --git a/Kelompok 1 ETS.ipynb b/Kelompok 1 ETS.ipynb
new file mode 100644
index 0000000..788e3fe
--- /dev/null
+++ b/Kelompok 1 ETS.ipynb
@@ -0,0 +1 @@
+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyNE/AVfPCndZRo3VrKym5D7"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":2,"metadata":{"id":"Uy-HrhzJJ3Nn","executionInfo":{"status":"ok","timestamp":1793973707520,"user_tz":-420,"elapsed":39,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}}},"outputs":[],"source":["import pandas as pd\n","\n","import numpy as np\n","\n","import matplotlib.pyplot as plt\n","\n","import seaborn as sns\n","\n","\n","from sklearn.model_selection import train_test_split\n","\n","from sklearn.tree import DecisionTreeClassifier\n","\n","from sklearn.ensemble import RandomForestClassifier\n","\n","from sklearn.metrics import accuracy_score, classification_report, confusion_matrix"]},{"cell_type":"code","source":["# Membaca file CSV\n","df = pd.read_csv('DataSet-Tugas-1.csv')\n","\n","# Menampilkan 5 baris pertama untuk memastikan data termuat dengan benar\n","df.head()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"nUVSP27_KRsM","executionInfo":{"status":"ok","timestamp":1793973715866,"user_tz":-420,"elapsed":103,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"979a4fcf-71f2-448f-e248-d2c239e3d480"},"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Hematokrit Hemoglobin Jumlah Eritrosit Jumlah Lekosit Jumlah Trombosit \\\n","0 45.0 15.2 5.81 5.9 219 \n","1 45.0 15.3 5.49 6.2 312 \n","2 47.5 16.6 5.84 7.4 244 \n","3 45.4 15.0 5.33 6.7 342 \n","4 44.9 15.8 5.19 7.0 328 \n","\n"," MCH MCHC MCV SOURCE \n","0 26.2 33.8 77.5 rwj \n","1 27.9 34.0 82.0 rwj \n","2 28.4 34.9 81.3 rwj \n","3 28.1 33.0 85.2 rwj \n","4 30.4 35.2 86.5 rwj "],"text/html":["\n","
\n","
\n","\n","
\n"," \n"," \n"," | \n"," Hematokrit | \n"," Hemoglobin | \n"," Jumlah Eritrosit | \n"," Jumlah Lekosit | \n"," Jumlah Trombosit | \n"," MCH | \n"," MCHC | \n"," MCV | \n"," SOURCE | \n","
\n"," \n"," \n"," \n"," | 0 | \n"," 45.0 | \n"," 15.2 | \n"," 5.81 | \n"," 5.9 | \n"," 219 | \n"," 26.2 | \n"," 33.8 | \n"," 77.5 | \n"," rwj | \n","
\n"," \n"," | 1 | \n"," 45.0 | \n"," 15.3 | \n"," 5.49 | \n"," 6.2 | \n"," 312 | \n"," 27.9 | \n"," 34.0 | \n"," 82.0 | \n"," rwj | \n","
\n"," \n"," | 2 | \n"," 47.5 | \n"," 16.6 | \n"," 5.84 | \n"," 7.4 | \n"," 244 | \n"," 28.4 | \n"," 34.9 | \n"," 81.3 | \n"," rwj | \n","
\n"," \n"," | 3 | \n"," 45.4 | \n"," 15.0 | \n"," 5.33 | \n"," 6.7 | \n"," 342 | \n"," 28.1 | \n"," 33.0 | \n"," 85.2 | \n"," rwj | \n","
\n"," \n"," | 4 | \n"," 44.9 | \n"," 15.8 | \n"," 5.19 | \n"," 7.0 | \n"," 328 | \n"," 30.4 | \n"," 35.2 | \n"," 86.5 | \n"," rwj | \n","
\n"," \n","
\n","
\n","
\n","
\n"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"dataframe","variable_name":"df","summary":"{\n \"name\": \"df\",\n \"rows\": 4517,\n \"fields\": [\n {\n \"column\": \"Hematokrit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 6.2491782216471,\n \"min\": 13.7,\n \"max\": 71.3,\n \"num_unique_values\": 357,\n \"samples\": [\n 50.9,\n 46.7,\n 58.1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Hemoglobin\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.2005436286635716,\n \"min\": 3.8,\n \"max\": 24.9,\n \"num_unique_values\": 153,\n \"samples\": [\n 9.0,\n 8.4,\n 17.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Eritrosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.7885816164402666,\n \"min\": 1.48,\n \"max\": 7.86,\n \"num_unique_values\": 438,\n \"samples\": [\n 6.47,\n 4.94,\n 6.54\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Lekosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 5.37338679582883,\n \"min\": 1.1,\n \"max\": 76.6,\n \"num_unique_values\": 296,\n \"samples\": [\n 18.7,\n 13.0,\n 9.5\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Jumlah Trombosit\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 113,\n \"min\": 8,\n \"max\": 1183,\n \"num_unique_values\": 556,\n \"samples\": [\n 355,\n 421,\n 305\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCH\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.796720521352356,\n \"min\": 14.9,\n \"max\": 40.8,\n \"num_unique_values\": 210,\n \"samples\": [\n 31.0,\n 17.5,\n 23.4\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCHC\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1.238716289689131,\n \"min\": 26.0,\n \"max\": 39.0,\n \"num_unique_values\": 106,\n \"samples\": [\n 36.2,\n 33.5,\n 35.2\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"MCV\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 7.140812899585524,\n \"min\": 54.0,\n \"max\": 115.6,\n \"num_unique_values\": 432,\n \"samples\": [\n 115.3,\n 94.9,\n 99.7\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"SOURCE\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"rwi\",\n \"rwj\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":{},"execution_count":3}]},{"cell_type":"code","source":["# Memeriksa informasi umum struktur data & tipe datanya\n","df.info()\n","\n","# Memisahkan Fitur (X) dan Target (y) secara benar:\n","# X adalah semua kolom dari awal sampai kolom ke-7 (kolom fitur laboratorium)\n","X = df.iloc[:, :-1] # atau df.drop(columns=['SOURCE'])\n","\n","# y adalah kolom terakhir yaitu 'SOURCE' (target kelas: 'rwj' / 'rwi')\n","y = df.iloc[:, -1] # atau df['SOURCE']\n","\n","# Membagi data menjadi Data Latih (80%) dan Data Uji (20%)\n","X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"raBgTpzjKSrX","executionInfo":{"status":"ok","timestamp":1793973741239,"user_tz":-420,"elapsed":1514,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"d6294b7f-6443-4551-cc4d-39fa6fcea60f"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["\n","RangeIndex: 4517 entries, 0 to 4516\n","Data columns (total 9 columns):\n"," # Column Non-Null Count Dtype \n","--- ------ -------------- ----- \n"," 0 Hematokrit 4517 non-null float64\n"," 1 Hemoglobin 4517 non-null float64\n"," 2 Jumlah Eritrosit 4517 non-null float64\n"," 3 Jumlah Lekosit 4517 non-null float64\n"," 4 Jumlah Trombosit 4517 non-null int64 \n"," 5 MCH 4517 non-null float64\n"," 6 MCHC 4517 non-null float64\n"," 7 MCV 4517 non-null float64\n"," 8 SOURCE 4517 non-null object \n","dtypes: float64(7), int64(1), object(1)\n","memory usage: 317.7+ KB\n"]}]},{"cell_type":"code","source":["# Inisialisasi dan melatih model Decision Tree\n","model_1 = DecisionTreeClassifier(random_state=42)\n","model_1.fit(X_train, y_train)\n","\n","print(\"Model 1 (Decision Tree) berhasil dilatih!\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"YjBvt2pHKVug","executionInfo":{"status":"ok","timestamp":1793973763963,"user_tz":-420,"elapsed":36,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"1f984531-8551-451d-e94b-971d2a3da22d"},"execution_count":5,"outputs":[{"output_type":"stream","name":"stdout","text":["Model 1 (Decision Tree) berhasil dilatih!\n"]}]},{"cell_type":"code","source":["# Inisialisasi dan melatih model Random Forest (sebagai pembanding)[cite: 2]\n","model_2 = RandomForestClassifier(random_state=42)\n","model_2.fit(X_train, y_train)\n","\n","print(\"Model 2 (Random Forest) berhasil dilatih!\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EIaNh-9tKY7Y","executionInfo":{"status":"ok","timestamp":1793973775285,"user_tz":-420,"elapsed":2669,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"7b25f28d-0c4b-4c43-f427-7acdf91068bd"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["Model 2 (Random Forest) berhasil dilatih!\n"]}]},{"cell_type":"code","source":["# Evaluasi Model 1 (Decision Tree)\n","y_pred_1 = model_1.predict(X_test)\n","acc_1 = accuracy_score(y_test, y_pred_1)\n","print(f\"Akurasi Model 1 (Decision Tree): {acc_1 * 100:.2f}%\")\n","print(classification_report(y_test, y_pred_1))\n","print(\"-\" * 60)\n","\n","# Evaluasi Model 2 (Random Forest)\n","y_pred_2 = model_2.predict(X_test)\n","acc_2 = accuracy_score(y_test, y_pred_2)\n","print(f\"Akurasi Model 2 (Random Forest): {acc_2 * 100:.2f}%\")\n","print(classification_report(y_test, y_pred_2))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"hDiRPgx1KdY4","executionInfo":{"status":"ok","timestamp":1793973789556,"user_tz":-420,"elapsed":42,"user":{"displayName":"Elfan Cris","userId":"15481999268029990356"}},"outputId":"70ac9cfe-a29e-4d65-ff9c-4ff40d020d8a"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["Akurasi Model 1 (Decision Tree): 65.49%\n"," precision recall f1-score support\n","\n"," rwi 0.59 0.60 0.59 381\n"," rwj 0.70 0.69 0.70 523\n","\n"," accuracy 0.65 904\n"," macro avg 0.65 0.65 0.65 904\n","weighted avg 0.66 0.65 0.66 904\n","\n","------------------------------------------------------------\n","Akurasi Model 2 (Random Forest): 74.12%\n"," precision recall f1-score support\n","\n"," rwi 0.71 0.64 0.68 381\n"," rwj 0.76 0.81 0.78 523\n","\n"," accuracy 0.74 904\n"," macro avg 0.74 0.73 0.73 904\n","weighted avg 0.74 0.74 0.74 904\n","\n"]}]}]}
\ No newline at end of file