-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestModel.py
More file actions
68 lines (52 loc) · 2.08 KB
/
testModel.py
File metadata and controls
68 lines (52 loc) · 2.08 KB
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
64
65
66
67
68
#preprocess test data
#creating a testset and we will use our model to inference on it
import numpy as np
from random import randint
from sklearn.preprocessing import MinMaxScaler
from sklearn.utils import shuffle
#import tensorflow as tf
#from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Dense
#Below two used while training the model
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
test_labels = []
test_samples = []
for i in range(10):
#The ~5% of younger individuals who experienced side effects
random_younger = randint(13,64)
test_samples.append(random_younger)
test_labels.append(1)
#The ~5% of older individuals who didn't experience side effects
random_older = randint(65,100)
test_samples.append(random_older)
test_labels.append(0)
for i in range(200):
#The ~95% of younger individuals who did not experience side effects
random_younger = randint(13,64)
test_samples.append(random_younger)
test_labels.append(0)
#The ~95% of older individuals who experienced side effects
random_older = randint(65,100)
test_samples.append(random_older)
test_labels.append(1)
test_labels = np.array(test_labels)
test_samples = np.array(test_samples)
test_labels, test_samples = shuffle(test_labels, test_samples)
scaler = MinMaxScaler(feature_range=(0,1))
scaled_test_samples = scaler.fit_transform(test_samples.reshape(-1, 1))
model = Sequential([
Dense(units=16, input_shape=(1,), activation='relu'),
Dense(units=32, activation='relu'),
Dense(units=2, activation='softmax')
])
#Predicting model
predictions = model.predict(x=scaled_test_samples, batch_size=10, verbose=0)
for i in predictions:
print(i)
#Interpreting the return i values. For example [0.43515587 0.56484413] represents 43% probability to 'x' patient not experiencing side effects
#Around 56% probability of the patient experiencing a side effect
rounded_predictions = np.argmax(predictions, axis=-1)
for i in rounded_predictions:
print(i)