Example #1
0
def test_structured_data_from_numpy_classifier(tmp_dir):
    num_data = 500
    data = common.structured_data(num_data)
    x_train = data
    y = np.random.randint(0, 3, num_data)
    y_train = y
    clf = ak.StructuredDataClassifier(directory=tmp_dir, max_trials=1)
    clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
Example #2
0
def test_structured_data_from_numpy_regressor(tmp_dir):
    num_data = 500
    data = common.structured_data(num_data)
    x_train = data
    y = np.random.rand(num_data, 1)
    y_train = y
    clf = ak.StructuredDataRegressor(directory=tmp_dir, max_trials=1)
    clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
Example #3
0
def test_structured_data_classifier_transform_new_data(tmp_dir):
    num_data = 200
    num_train = 100
    data = common.structured_data(num_data)
    x_train, x_test = data[:num_train], data[num_train:]
    y = np.random.randint(0, 3, num_data)
    y_train, y_test = y[:num_train], y[num_train:]
    clf = ak.StructuredDataClassifier(directory=tmp_dir, max_trials=1)
    clf.fit(x_train, y_train, epochs=2, validation_data=(x_test, y_test))
Example #4
0
def test_structured_data_assembler():
    data = common.structured_data()
    dataset = tf.data.Dataset.from_tensor_slices(data)
    assembler = meta_model.StructuredDataAssembler(
        column_names=common.COLUMN_NAMES_FROM_NUMPY)
    for line in dataset:
        assembler.update(line)

    assembler.assemble(node.StructuredDataInput())
Example #5
0
def test_structured_data_from_numpy_classifier(tmp_dir):
    num_data = 500
    num_train = 400
    data = common.structured_data(num_data)
    x_train, x_test = data[:num_train], data[num_train:]
    y = np.random.randint(0, 3, num_data)
    y_train, y_test = y[:num_train], y[num_train:]
    clf = ak.StructuredDataClassifier(directory=tmp_dir, max_trials=1)
    clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
    assert clf.predict(x_test).shape == (len(y_test), 1)
Example #6
0
def test_structured_data_from_numpy_col_name_classifier(tmp_dir):
    num_data = 500
    data = common.structured_data(num_data)
    x_train = data
    y = np.random.randint(0, 3, num_data)
    y_train = y
    clf = ak.StructuredDataClassifier(
        column_names=common.COLUMN_NAMES_FROM_NUMPY,
        directory=tmp_dir,
        max_trials=1)
    clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
Example #7
0
def test_structured_data_from_numpy_col_type_classifier(tmp_dir):
    num_data = 500
    data = common.structured_data(num_data)
    x_train = data
    y = np.random.randint(0, 3, num_data)
    y_train = y
    with pytest.raises(ValueError) as info:
        clf = ak.StructuredDataClassifier(
            column_types=common.COLUMN_TYPES_FROM_NUMPY,
            directory=tmp_dir,
            max_trials=1)
        clf.fit(x_train, y_train, epochs=2, validation_data=(x_train, y_train))
    assert str(info.value) == 'Column names must be specified.'
Example #8
0
def test_structured_data_input(tmp_dir):
    num_data = 500
    data = common.structured_data(num_data)
    x_train = data
    y = np.random.randint(0, 3, num_data)
    y_train = y

    input_node = ak.StructuredDataInput(
        column_names=common.COLUMN_NAMES_FROM_NUMPY,
        column_types=common.COLUMN_TYPES_FROM_NUMPY)
    output_node = input_node
    output_node = ak.StructuredDataBlock()(output_node)
    output_node = ak.ClassificationHead(loss='categorical_crossentropy',
                                        metrics=['accuracy'])(output_node)

    auto_model = ak.GraphAutoModel(input_node,
                                   output_node,
                                   directory=tmp_dir,
                                   max_trials=1)
    auto_model.fit(x_train,
                   y_train,
                   epochs=1,
                   validation_data=(x_train, y_train))
    auto_model.predict(x_train)