-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwd7_iris.py
59 lines (50 loc) · 1.55 KB
/
wd7_iris.py
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
59
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 30 18:47:50 2023
@author: hama
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("D:/ai middle class/data/iris3.csv")
print(df.head())
# sns.pairplot(df, hue='species')
#직접 컬럼을 선택하는 방법
# sns.pairplot(df[['petal_length', 'petal_width']])
#vars옵션을 사용해서 컬럼 선택 후 입력하는 방법
# sns.pairplot(df, vars=['petal_length', 'petal_width'], hue='species')
# plt.show()
#히스토그램
# sns.histplot(data=df, x='sepal_length', kde=True, hue='species')
#jointplot
# sns.jointplot(x='petal_length', y='petal_width',data=df, kind='kde')
# plt.show()
x = df.iloc[:,0:4]
y = df.iloc[:,4]
print(x.isnull().sum())
y_encode = pd.get_dummies(y)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
#모델 설정
model = Sequential()
model.add(Dense(12, input_dim=4, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(3, activation='softmax'))
#환경설정(컴파일)
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
#학습
history = model.fit(x, y_encode, epochs=50, batch_size=5)
#plt.plot(history.history['loss])
# Loss 그래프
plt.subplot(1, 2, 1)
plt.plot(history.history['loss'])
plt.title('Loss')
plt.xlabel('Epoch')
plt.ylabel('Loss')
# Accuracy 그래프
plt.subplot(1, 2, 2)
plt.plot(history.history['accuracy'])
plt.title('Accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.show()