def test_MLRs(region_sparse, region_dense, base_sparse, base_dense, bias_sparse, bias_dense): model_name = "MLRs" _, y, region_feature_columns = get_test_data( SAMPLE_SIZE, sparse_feature_num=region_sparse, dense_feature_num=region_dense, prefix='region') base_x, y, base_feature_columns = get_test_data( SAMPLE_SIZE, sparse_feature_num=region_sparse, dense_feature_num=region_dense, prefix='base') bias_x, y, bias_feature_columns = get_test_data( SAMPLE_SIZE, sparse_feature_num=region_sparse, dense_feature_num=region_dense, prefix='bias') model = MLR(region_feature_columns, base_feature_columns, bias_feature_columns=bias_feature_columns) model.compile('adam', 'binary_crossentropy', metrics=['binary_crossentropy']) print(model_name + " test pass!")
def test_MLRs(region_sparse, region_dense, base_sparse, base_dense, bias_sparse, bias_dense): model_name = "MLRs" region_fd = {"sparse": {}, 'dense': []} for name, num in zip(["sparse", "dense"], [region_sparse, region_dense]): if name == "sparse": for i in range(num): region_fd[name][name + '_' + str(i)] = np.random.randint(1, 10) else: for i in range(num): region_fd[name].append(name + '_' + str(i)) base_fd = {"sparse": {}, 'dense': []} for name, num in zip(["sparse", "dense"], [base_sparse, base_dense]): if name == "sparse": for i in range(num): base_fd[name][name + '_' + str(i)] = np.random.randint(1, 10) else: for i in range(num): base_fd[name].append(name + '_' + str(i)) bias_fd = {"sparse": {}, 'dense': []} for name, num in zip(["sparse", "dense"], [bias_sparse, bias_dense]): if name == "sparse": for i in range(num): bias_fd[name][name + '_' + str(i)] = np.random.randint(1, 10) else: for i in range(num): bias_fd[name].append(name + '_' + str(i)) model = MLR(region_fd, base_fd, bias_feature_dim_dict=bias_fd) model.compile('adam', 'binary_crossentropy', metrics=['binary_crossentropy']) print(model_name + " test pass!")
def test_MLR(): model_name = "MLR" sample_size = 64 feature_dim_dict = {'sparse': {'sparse_1': 2, 'sparse_2': 5, 'sparse_3': 10}, 'dense': ['dense_1', 'dense_2', 'dense_3']} sparse_input = [np.random.randint(0, dim, sample_size) for dim in feature_dim_dict['sparse'].values()] dense_input = [np.random.random(sample_size) for name in feature_dim_dict['dense']] y = np.random.randint(0, 2, sample_size) x = sparse_input + dense_input model = MLR(feature_dim_dict) model.compile('adam', 'binary_crossentropy', metrics=['binary_crossentropy']) model.fit(x, y, batch_size=100, epochs=1, validation_split=0.5) print(model_name+" test train valid pass!") model.save_weights(model_name + '_weights.h5') model.load_weights(model_name + '_weights.h5') print(model_name+" test save load weight pass!") save_model(model, model_name + '.h5') model = load_model(model_name + '.h5', custom_objects) print(model_name + " test save load model pass!") print(model_name + " test pass!")
def test_MLR(): model_name = "MLR" region_x, y, region_feature_columns = get_test_data(SAMPLE_SIZE, 3, 3, prefix='region') base_x, y, base_feature_columns = get_test_data(SAMPLE_SIZE, 3, 3, prefix='base') bias_x, y, bias_feature_columns = get_test_data(SAMPLE_SIZE, 3, 3, prefix='bias') model = MLR(region_feature_columns) model.compile('adam', 'binary_crossentropy', metrics=['binary_crossentropy']) check_model(model, model_name, region_x, y) print(model_name + " test pass!")