def fitness(data, label, zero_index, answer): out = np.zeros(5) if label == 3: out[0] = 1 elif label == 5: out[1] = 1 elif label == 6: out[2] = 1 elif label == 7: out[3] = 1 elif label == 9: out[4] = 1 dd = data for e in range(20): dd[zero_index + e] = answer[e] label_arr = out model = load_model('./model.h5') g = [dd] res = model.predict(funcs.extract(g)) label_classifier = res[0] # score = 0 for f in range(len(label_arr)): d = label_arr[f] - label_classifier[f] if d < 0: d *= -1 score += d return 5 - score
def extract(): if "url" not in request.values: return response(400, msg="Missing parameter.") url = request.values["url"] return funcs.extract(url)
for item in label_train: out = np.zeros(5) if item == 3: out[0] = 1 elif item == 5: out[1] = 1 elif item == 6: out[2] = 1 elif item == 7: out[3] = 1 elif item == 9: out[4] = 1 output_data.append(out) output_data = np.asarray(output_data) data_features = funcs.extract(data_train) print("===========================") print('Start NN') model = Sequential() model.add(Dense(100, activation='relu')) model.add(Dense(200, activation='relu')) model.add(Dense(4000, activation='sigmoid')) model.add(Dense(100, activation='softmax')) model.add(Dense(5, activation='sigmoid')) model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy']) print("Start fit data") trainedModel = model.fit(data_features, output_data, epochs=100,
output_data = [] for item in t_label: out = np.zeros(5) if item == 3: out[0] = 1 elif item == 5: out[1] = 1 elif item == 6: out[2] = 1 elif item == 7: out[3] = 1 elif item == 9: out[4] = 1 output_data.append(out) output_data = np.asarray(output_data) f = funcs.extract(t_data) res = model.evaluate(f, output_data) print(res) print(model.metrics_names) res = model.predict(f) for i, item in enumerate(res): idxMax = np.argmax(item) predict = 0 if idxMax == 0: predict = 3 elif idxMax == 1: predict = 5 elif idxMax == 2:
import numpy as np from keras.models import load_model import funcs model = load_model('./model.h5') print("get test data") data_test, label_test = funcs.get_test_data() f = funcs.extract(data_test) output_data = [] for item in label_test: out = np.zeros(5) if item == 3: out[0] = 1 elif item == 5: out[1] = 1 elif item == 6: out[2] = 1 elif item == 7: out[3] = 1 elif item == 9: out[4] = 1 output_data.append(out) output_data = np.asarray(output_data) res = model.evaluate(f, output_data) print(res) print(model.metrics_names) res = model.predict(f)