-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_data.py
82 lines (56 loc) · 2.21 KB
/
test_data.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# coding: utf-8
from testing.test_bin import NNtesting_bin
from testing.test_rgr import NNtesting_rgr
from testing.test_multi import NNtesting_multi
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from io import StringIO
import sys
import json
import tensorflow as tf
class GetRequiredVal():
def __init__(self):
self.x_test = None
self.y_test = None
self.problem_type = None
_train_str_file_PATH = 'autotuning/training_strategy.json'
with open(_train_str_file_PATH) as f:
training_param = json.load(f)
self.train_parameters = training_param
self.test_data = pd.read_csv(self.train_parameters["test_data_Path"])
self.target_col = self.train_parameters["target_col"]
self.batch_size = self.train_parameters["batch_size"]
self.y_test = self.test_data[self.target_col]
self.x_test = self.test_data.drop([self.target_col], 1)
def findProblemType(self):
if(len(set(self.y_test))/len(self.y_test))>.15:
self.problem_type = 'regression'
return 'regression'
if len(set(self.y_test))==2:
self.problem_type = 'binary_classification'
return 'binary_classification'
self.problem_type = 'multi_classification'
return 'multi_classification'
def get_data(self):
return self.x_test, self.y_test, self.batch_size
if __name__ == '__main__':
datasetName = sys.argv[1]
model_path = sys.argv[2]
if datasetName=='MNIST':
X_test = 'data/mnist/x_test.npy'
y_test = 'data/mnist/y_test.npy'
tmnist = NNtesting_multi(model_path, X_test, y_test, 128)
tmnist.test_score()
elif datasetName=='LOAN':
pass
else:
x_test, y_test, batch_size = GetRequiredVal().get_data()
prob_typ = GetRequiredVal().findProblemType()
if prob_typ=='binary_classification':
nndtst = NNtesting_bin(model_path, x_test, y_test, batch_size)
nndtst.test_score()
elif prob_typ=='regression':
nndtstr = NNtesting_rgr(model_path, x_test, y_test, batch_size)
nndtstr.test_score()