작성
·
127
0
파이썬 - 저장되어 있는 데이터로 그래프를 그리고 싶은데 plot 해도 그래프가 나오지 않아 혹시 그래프를 그리고 싶다면 어떤 코딩을 어느 위치에 추가해야 하는지 알수 있을까요 ?
밑에 코딩 첨부하겠습니다.
import time
import pymysql
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
groups_folder_path = 'D:/3DP/' #학습데이터 저장 경로
A = np.empty((0,5))
D = np.empty((0,4))
mid_D = np.empty((0,4))
for indx in range(1,8):
data_dir = groups_folder_path + 'ACC_' + str(indx) + '.csv'
data = pd.read_csv(data_dir)
data = data.to_numpy()
A = np.vstack([A, data])
data_dir = groups_folder_path + 'DHT_' + str(indx) + '.csv'
data2 = pd.read_csv(data_dir)
data2 = data2.to_numpy()
for i in range(0, len(data2)):
dummy = data2[i].reshape([1,4])
dummy = np.repeat(dummy,repeats = 750, axis = 0)
mid_D = np.vstack([mid_D, dummy])
D = np.vstack([D, mid_D[0:len(data)]])
SS = np.empty((0,6))
A = np.delete(A,0,1)
D = np.delete(D,0,1)
D = np.delete(D,2,1)
Sum = np.hstack([A,D])
for i in range(len(Sum)):
if Sum[i,3] == 4:
a = Sum[i]
a = a.reshape(1,6)
SS=np.vstack([SS,a])
else :
1
dummy2 = np.repeat(SS,repeats = 9, axis = 0)
SS = np.vstack([SS,dummy2])
Sum = np.vstack([Sum,SS])
label = Sum[:,3]
label = label.reshape([len(Sum),1])
X = np.delete(Sum,3,1)
Y = label
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.1,shuffle=True)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)
from sklearn.svm import SVC
svm_model = SVC(kernel='rbf',C=5, gamma=0.1, decision_function_shape='ovo')
# ovo = one vs. one / ovr = one vs. rest
svm_model.fit(X_train_std, y_train) # SVM 분류 모델 훈련
y_pred = svm_model.predict(X_test_std)
q = len(y_test)
L1 = len(y_test[y_test == 1])
L2 = len(y_test[y_test == 2])
L3 = len(y_test[y_test == 3])
L4 = len(y_test[y_test == 4])
A1 = 0
A2 = 0
A3 = 0
A4 = 0
A5 = 0
for i in range (0,len(y_test)):
if y_pred[i] == y_test[i]:
if y_pred[i] == 1:
A1 = A1 + 1
elif y_pred[i] == 2:
A2 = A2+1
elif y_pred[i] == 3:
A3 = A3+1
else:
A4 = A4+1
else:
A5 = A5+1
print(A1/L1)
print(A2/L2)
print(A3/L3)
print(A4/L4)
print((len(y_test)-A5)/len(y_test)*100) #최종 정답률
from sklearn.metrics import confusion_matrix, plot_confusion_matrix
import matplotlib.pyplot as plt
confusion_matrix(y_test, y_pred)
답변