22/12/2020 IRIS BPNN.
ipynb - Colaboratory
import pandas as pd
import numpy as np
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import seaborn as sns
data = pd.read_csv('/content/drive/MyDrive/Latihan IRIS Data Sheet/IRIS1.csv')
data.head()
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa
print('Ukuran data : ', data.shape)
print(pd.value_counts(data.species))
Ukuran data : (150, 5)
Iris-versicolor 50
Iris-virginica 50
Iris-setosa 50
Name: species, dtype: int64
sns.FacetGrid(data, hue="species", size=7) \
.map(plt.scatter, "sepal_length", "sepal_width") \
.add_legend()
https://colab.research.google.com/drive/1PiclQYI4EPXdGhdZrkiIlHgOLFubM0V4#scrollTo=eIDwIeBD0--B&printMode=true 1/4
22/12/2020 IRIS BPNN.ipynb - Colaboratory
/usr/local/lib/python3.6/dist-packages/seaborn/axisgrid.py:316: UserWarning: Th
warnings.warn(msg, UserWarning)
<seaborn.axisgrid.FacetGrid at 0x7f1fb4451828>
sns.FacetGrid(data, hue="species", size=7) \
.map(plt.scatter, "petal_length", "petal_width") \
.add_legend()
/usr/local/lib/python3.6/dist-packages/seaborn/axisgrid.py:316: UserWarning: Th
warnings.warn(msg, UserWarning)
<seaborn.axisgrid.FacetGrid at 0x7f1fb3ce1f60>
sns.pairplot(data,hue="species",size=3);
plt.show()
https://colab.research.google.com/drive/1PiclQYI4EPXdGhdZrkiIlHgOLFubM0V4#scrollTo=eIDwIeBD0--B&printMode=true 2/4
22/12/2020 IRIS BPNN.ipynb - Colaboratory
/usr/local/lib/python3.6/dist-packages/seaborn/axisgrid.py:1912: UserWarning: T
warnings.warn(msg, UserWarning)
data.describe()
sepal_length sepal_width petal_length petal_width
count 150.000000 150.000000 150.000000 150.000000
mean 5.843333 3.054000 3.758667 1.198667
std 0.828066 0.433594 1.764420 0.763161
min 4.300000 2.000000 1.000000 0.100000
25% 5.100000 2.800000 1.600000 0.300000
50% 5.800000 3.000000 4.350000 1.300000
75% 6.400000 3.300000 5.100000 1.800000
max 7.900000 4.400000 6.900000 2.500000
sns.boxplot(x="species",y="sepal_length", data=data)
plt.show()
y = data.pop('species') #pisahkan antara data dan label
https://colab.research.google.com/drive/1PiclQYI4EPXdGhdZrkiIlHgOLFubM0V4#scrollTo=eIDwIeBD0--B&printMode=true 3/4
22/12/2020 IRIS BPNN.ipynb - Colaboratory
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(data, y, test_size=0.33, random_s
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',
max_depth=None, max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, presort='deprecated',
random_state=None, splitter='best')
hasil = model.predict(X_test)
from sklearn.metrics import accuracy_score
hasil = model.predict(X_train)
print('Accuracy Score : ', accuracy_score(hasil, y_train))
Accuracy Score : 1.0
from sklearn.metrics import accuracy_score
hasil = model.predict(X_test)
print('Accuracy Score : ', accuracy_score(hasil, y_test))
Accuracy Score : 0.98
https://colab.research.google.com/drive/1PiclQYI4EPXdGhdZrkiIlHgOLFubM0V4#scrollTo=eIDwIeBD0--B&printMode=true 4/4