-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode Program
More file actions
58 lines (36 loc) · 1.13 KB
/
Code Program
File metadata and controls
58 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pandas as pd
from sklearn import datasets
iris = datasets.load_iris()
x = iris.data
y = iris.target
x = pd.DataFrame(x, columns=iris.feature_names)
df_y = pd.DataFrame(y, columns=['target'])
df_x
df_x.shape
df_y
df = pd.concat([df_x, df_y], axis=1)
df.head(10)
df.info
df['target'].unique()
df.describe()
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
round(150*0.2)
round(150*0.8)
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(x_train, y_train)
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
y_pred = model.predict(x_test)
accuracy = accuracy_score(y_test, y_pred)
print("Laporan Klasifikasi:")
print(f'Accuracy: {accuracy * 100:.1f}%')
import seaborn as sns
import matplotlib.pyplot as plt
cm = confusion_matrix(y_test, y_pred)
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues', xticklabels=iris.target_names, yticklabels=iris.target_names)
plt.xlabel('Prediksi')
plt.ylabel('Aktual')
plt.title('Confusion Matrix')
plt.show()