forked from MartynaSokolowska/Vibroacoustic-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualisation.py
More file actions
34 lines (26 loc) · 946 Bytes
/
visualisation.py
File metadata and controls
34 lines (26 loc) · 946 Bytes
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
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
def audio_plot(data, samplerate):
if len(data.shape) > 1:
data = data[:, 0]
times = np.arange(len(data)) / samplerate
plt.figure(figsize=(12, 4))
plt.plot(times, data)
plt.xlabel('Time [s]')
plt.ylabel('Amplitude')
plt.title('Audio signal in the time domain')
plt.show()
def plot2D(X_2d, labels, title="2D Projection"):
plt.figure(figsize=(8, 6))
for label in np.unique(labels):
idx = labels == label
plt.scatter(X_2d[idx, 0], X_2d[idx, 1], label=label)
plt.legend()
plt.title(title)
plt.show()
def show_confusion_matrix(y_pred, y_true, display_labels=None):
cm = confusion_matrix(y_true, y_pred, labels=display_labels)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=display_labels)
disp.plot()
plt.show()