task.set_train_task(func=f_train, data=train, epoch=args.epoch, name='train') task.set_valid_task(func=f_score, data=valid, freq=training.Timer(percentage=0.8), name='valid') task.run() # =========================================================================== # Prediction # =========================================================================== y_pred_proba, Z1_test, Z2_test, Z3_test = make_dnn_prediction( functions=[f_pred_proba, f_z1, f_z2, f_z3], X=X_test_data, title='TEST') print("Test Latent:", Z1_test.shape, Z2_test.shape, Z3_test.shape) y_pred = np.argmax(y_pred_proba, axis=-1) evaluate(y_true=X_test_true, y_pred_proba=y_pred_proba, labels=labels, title="Test set (Deep prediction)", path=os.path.join(EXP_DIR, 'test_deep.pdf')) # ====== make a streamline classifier ====== # # training PLDA Z3_train, y_train = make_dnn_prediction(f_z3, X=train, title="TRAIN") print("Z3_train:", Z3_train.shape, y_train.shape) Z3_valid, y_valid = make_dnn_prediction(f_z3, X=valid, title="VALID") print("Z3_valid:", Z3_valid.shape, y_valid.shape) plda = PLDA(n_phi=200, random_state=K.get_rng().randint(10e8), n_iter=12, labels=labels, verbose=0) plda.fit(np.concatenate([Z3_train, Z3_valid], axis=0), np.concatenate([y_train, y_valid], axis=0))
]) task.set_train_task(func=f_train, data=train, epoch=args.epoch, name='train') task.set_valid_task(func=f_score, data=valid, freq=training.Timer(percentage=0.8), name='valid') task.run() # =========================================================================== # Prediction # =========================================================================== y_pred_proba, Z1_test, Z2_test, Z3_test = make_dnn_prediction( functions=[f_pred_proba, f_z1, f_z2, f_z3], X=X_test_data, title='TEST') print("Test Latent:", Z1_test.shape, Z2_test.shape, Z3_test.shape) y_pred = np.argmax(y_pred_proba, axis=-1) evaluate(y_true=X_test_true, y_pred_proba=y_pred_proba, labels=labels, title="Test set (Deep prediction)", path=os.path.join(EXP_DIR, 'test_deep.pdf')) # ====== make a streamline classifier ====== # # training PLDA Z3_train, y_train = make_dnn_prediction(f_z3, X=train, title="TRAIN") print("Z3_train:", Z3_train.shape, y_train.shape) Z3_valid, y_valid = make_dnn_prediction(f_z3, X=valid, title="VALID") print("Z3_valid:", Z3_valid.shape, y_valid.shape) plda = PLDA(n_phi=200, random_state=K.get_rng().randint(10e8), n_iter=12, labels=labels, verbose=0) plda.fit(np.concatenate([Z3_train, Z3_valid], axis=0), np.concatenate([y_train, y_valid], axis=0)) y_pred_log_proba = plda.predict_log_proba(Z3_test) evaluate(y_true=X_test_true, y_pred_log_proba=y_pred_log_proba, labels=labels, title="Test set (PLDA - Latent prediction)", path=os.path.join(EXP_DIR, 'test_latent.pdf'))