ml_x_t = train_x_t @ L
ml_val_x_t = val_x_t @ L

ml_test_x = test_x_t @ L
print('Done')

# =============================================================================

num_inputs = ml_x_s.shape[1]  # input layer size
# =============================================================================
if 'ml_model' in locals():
    del ml_model
if 'ml_model_obj' in locals():
    del ml_model_obj
ml_model_obj = my_models(num_inputs, dropout=dropout_pr)
ml_model = ml_model_obj.build_model()
ml_model = ml_model_obj.fit(ml_x_s,
                            train_y_s,
                            ml_val_x_s,
                            val_y_s,
                            scale=NN_scaling)


error_metric, ml_train_loss, ml_val_loss, ml_test_loss = \
  ml_model_obj.evaluate(ml_x_t,train_y_t, ml_val_x_t, val_y_t, ml_test_x,
                     test_y_t, scale = NN_scaling)

if fine_tuning:
    ml_model = ml_model_obj.fit(ml_x_t,
                                train_y_t,
示例#2
0
#coef_s, coef_t =  ekmm_emb(emb_y_t, emb_y_s, kern = kmm_kernel, B = B,
#                           embedder_type = 'no_embedding', n_components = 100)
# =============================================================================
coef_val_s = coef_s[train_y_s.shape[0]:]
coef_s = coef_s[:train_y_s.shape[0]]

# =============================================================================
import numpy.matlib as npm
training_weights = npm.repmat(coef_s, 1, train_y_s.shape[1])
training_val_weights = npm.repmat(coef_val_s, 1, val_y_s.shape[1])
num_weights = training_weights.shape[1]

num_inputs = emb_x_s.shape[1]  # input layer size
# =============================================================================
w_model_obj = my_models(num_inputs,
                        num_weights=num_weights,
                        model_type='weighted',
                        dropout=dropout_pr)
model = w_model_obj.build_model()
model = w_model_obj.fit(emb_x_s,
                        train_y_s,
                        emb_val_x_s,
                        val_y_s,
                        val_w=training_val_weights,
                        scale=NN_scaling,
                        training_w=training_weights)

error_sample_bias, train_loss, val_loss, test_loss =\
  w_model_obj.evaluate(emb_x_t, train_y_t, emb_val_x_t, val_y_t,
                       emb_test_x, test_y_t, scale = NN_scaling)
title = 'metric learning plus sample selection bias'
print_stat(title, error_sample_bias, train_loss, val_loss, test_loss)