from keras.models import Sequential import pandas as pd from sklearn.preprocessing import LabelEncoder from sklearn import metrics import math import numpy as np def write_list(names): with open('listfile.txt', 'w') as fp: fp.write("\n".join(str(item) for item in names)) def get_x_y(data): lb = LabelEncoder() data = data.drop(["Location 1"], axis=1) data = data.drop(columns=["Longitude", "Latitude", "Location", "Total Incidents", "CrimeTime", "Neighborhood", "Post", "CrimeDate", "Inside/Outside"], axis=1) for column_name in data.columns: data[column_name] = lb.fit_transform(data[column_name]) x = data.drop('Weapon', axis=1) y = data['Weapon'] return data, x, y def predict(): model = load_model('baltimore_model.h5') train = pd.read_csv('baltimore_train.csv') baltimore_data_test = pd.read_csv('baltimore_test.csv') baltimore_data_test.columns = train.columns baltimore_data_test, x_test, y_test = get_x_y(baltimore_data_test) scores = model.evaluate(x_test, y_test) print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100)) y_predicted = model.predict(x_test) y_predicted = np.argmax(y_predicted,axis=1) test_results = {} test_results['Weapon'] = model.evaluate( x_test, y_test, verbose=0) write_list(y_predicted) predict()