-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathANN_load.py
More file actions
31 lines (24 loc) · 916 Bytes
/
ANN_load.py
File metadata and controls
31 lines (24 loc) · 916 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
import numpy as np
from keras.saving.save import load_model
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from Utils import RawData, Plotter
# Taking clean data from RawData() class
df = RawData().df
# Separating features and label
X = df[RawData().feature_cols] # Features
y = df.music_genre # Target variable
# Separating train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=1)
# Applying standardization
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)
# Load pretrained model
ann = load_model('others/ann_50_50.h5')
# Use model
y_pred = ann.predict(X_test)
y_pred = np.argmax(y_pred, axis=1)
print("Accuracy:", accuracy_score(y_test, y_pred))
Plotter().plot_cofusion_matrix(y_test, y_pred, "ANN")