-
Notifications
You must be signed in to change notification settings - Fork 1
/
test3.py
63 lines (43 loc) · 1.37 KB
/
test3.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
60
61
62
63
import numpy as np
import pandas as pd
import tensorflow as tf
from keras.layers import LSTM, Dense, Dropout
from keras.metrics import top_k_categorical_accuracy
from keras.models import Sequential
# from keras.utils import plot_model
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
# import matplotlib.pyplot as plt
encoder = OneHotEncoder(handle_unknown='ignore', sparse=False)
Y = np.array([[32.], [64.], [128.]])
transformed_Y = encoder.fit_transform(Y)
inversed_Y = encoder.inverse_transform(transformed_Y)
print("Y:")
print(Y)
print("transformed_Y:")
print(transformed_Y)
print("inversed_Y:")
print(inversed_Y)
predicted_Y = np.array([[0.3, 0.2, 0.5]])
print("predicted_Y:")
print(predicted_Y)
inversed_predicted_Y = encoder.inverse_transform(predicted_Y)
print("inversed_predicted_Y:")
print(inversed_predicted_Y)
sess = tf.Session()
with sess.as_default():
scores, indices = tf.math.top_k(
tf.convert_to_tensor(predicted_Y, dtype=np.float32),
k=2,
sorted=True,
)
scores = scores.eval()
indices = indices.eval()
xxx = to_categorical(indices)
for i in range(np.size(xxx, 1)):
xx = xxx[:, i, :]
inversed_xx = encoder.inverse_transform(xx)
print("inversed_xx:")
print(inversed_xx)
print()