def norm_encode(y_true, y_pred): y_true_1 = set(y_true) y_pred_1 = set(y_pred) joint = y_true_1.copy() joint.update(y_pred_1) norm = OrdinalEncoder().fit_transform(np.array(list(joint)).reshape(-1, 1)) norm = norm.reshape(1, -1)[0] coding = {k: v for k, v in zip(np.array(list(joint)), norm)} y_true = [coding[i] for i in y_true] y_pred = [coding[i] for i in y_pred] return np.array(y_true).astype(int), np.array(y_pred).astype(int)
plt.rcParams['figure.figsize'] = [3.2, 2.4] plt.rcParams['figure.dpi'] = 144 plt.hist(y_train) plt.title('y_train {}'.format(response_list[0])) plt.show() # ## Random Forest classification <a id='two'></a> # In[ ]: # Reshape arrays X_train_nx, X_train_ny, X_train_ns = X_train.shape X_train = X_train.reshape((X_train_nx * X_train_ny, X_train_ns)) y_train_nx, y_train_ny = y_train.shape y_train = y_train.reshape((y_train_nx * y_train_ny)) X_test_nx, X_test_ny, X_test_ns = X_test.shape X_test = X_test.reshape((X_test_nx * X_test_ny, X_test_ns)) y_test_nx, y_test_ny = y_test.shape y_test = y_test.reshape((y_test_nx * y_test_ny)) print("Dimensions of X_train: {}".format(X_train.shape)) print("Dimensions of y_train: {}".format(y_train.shape)) print("Dimensions of X_test: {}".format(X_test.shape)) print("Dimensions of y_test: {}".format(y_test.shape)) # In[ ]: # Unique value counts