def test_haversine(es):
    log_latlong_feat = es['log']['latlong']
    log_latlong_feat2 = es['log']['latlong2']
    haversine = ft.Feature([log_latlong_feat, log_latlong_feat2],
                           primitive=Haversine)
    features = [haversine]

    df = ft.calculate_feature_matrix(entityset=es, features=features,
                                     instance_ids=range(15))
    values = df[haversine.get_name()].values
    real = [0, 525.318462, 1045.32190304, 1554.56176802, 2047.3294327, 0,
            138.16578931, 276.20524822, 413.99185444, 0, 0, 525.318462, 0,
            741.57941183, 1467.52760175]
    assert len(values) == 15
    assert np.allclose(values, real, atol=0.0001)

    haversine = ft.Feature([log_latlong_feat, log_latlong_feat2],
                           primitive=Haversine(unit='kilometers'))
    features = [haversine]
    df = ft.calculate_feature_matrix(entityset=es, features=features,
                                     instance_ids=range(15))
    values = df[haversine.get_name()].values
    real_km = [0, 845.41812212, 1682.2825471, 2501.82467535, 3294.85736668,
               0, 222.35628593, 444.50926278, 666.25531268, 0, 0,
               845.41812212, 0, 1193.45638714, 2361.75676089]
    assert len(values) == 15
    assert np.allclose(values, real_km, atol=0.0001)
    error_text = "Invalid unit inches provided. Must be one of"
    with pytest.raises(ValueError, match=error_text):
        Haversine(unit='inches')
def test_haversine(es):
    log_latlong_feat = es['log']['latlong']
    log_latlong_feat2 = es['log']['latlong2']
    haversine = Haversine(log_latlong_feat, log_latlong_feat2)
    features = [haversine]
    pandas_backend = PandasBackend(es, features)
    df = pandas_backend.calculate_all_features(instance_ids=range(15),
                                               time_last=None)
    values = df[haversine.get_name()].values
    real = [0., 524.15585776, 1043.00845747, 1551.12130243,
            2042.79840241, 0., 137.86000883, 275.59396684,
            413.07563177, 0., 0., 524.15585776,
            0., 739.93819145, 1464.27975511]
    assert len(values) == 15
    for i, v in enumerate(real):
        assert v - values[i] < .0001
예제 #3
0
def test_haversine(es):
    log_latlong_feat = es['log']['latlong']
    log_latlong_feat2 = es['log']['latlong2']
    haversine = Haversine(log_latlong_feat, log_latlong_feat2)
    features = [haversine]
    pandas_backend = PandasBackend(es, features)
    df = pandas_backend.calculate_all_features(instance_ids=range(15),
                                               time_last=None)
    values = df[haversine.get_name()].values
    real = [
        0., 524.15585776, 1043.00845747, 1551.12130243, 2042.79840241, 0.,
        137.86000883, 275.59396684, 413.07563177, 0., 0., 524.15585776, 0.,
        739.93819145, 1464.27975511
    ]
    assert len(values) == 15
    for i, v in enumerate(real):
        assert v - values[i] < .0001
예제 #4
0
def test_call_multiple_args():
    primitive = Haversine()
    data1 = [(42.4, -71.1), (40.0, -122.4)]
    data2 = [(40.0, -122.4), (41.2, -96.75)]
    answer = [2631.231, 1343.289]

    for _ in range(2):
        assert np.round(primitive(data1, data2), 3).tolist() == answer
예제 #5
0
class DaskCompatibleHaversine(DaskCompatibleTransformPrimitive):
    stub = Haversine(unit='kilometers')

    name = f'{stub.name}_'
    input_types = stub.input_types
    return_type = stub.return_type

    def fn_pd(self, x1, *args):
        return self.stub.get_function()(x1, args[0])

    def generate_name(self, base_feature_names):
        return self.stub.generate_name(base_feature_names)
예제 #6
0
def test_haversine(es):
    log_latlong_feat = es['log']['latlong']
    log_latlong_feat2 = es['log']['latlong2']
    haversine = ft.Feature([log_latlong_feat, log_latlong_feat2],
                           primitive=Haversine)
    features = [haversine]

    df = ft.calculate_feature_matrix(entityset=es,
                                     features=features,
                                     instance_ids=range(15))
    values = df[haversine.get_name()].values
    real = [
        0., 524.15585776, 1043.00845747, 1551.12130243, 2042.79840241, 0.,
        137.86000883, 275.59396684, 413.07563177, 0., 0., 524.15585776, 0.,
        739.93819145, 1464.27975511
    ]
    assert len(values) == 15
    assert np.allclose(values, real, atol=0.0001)

    haversine = ft.Feature([log_latlong_feat, log_latlong_feat2],
                           primitive=Haversine(unit='kilometers'))
    features = [haversine]
    df = ft.calculate_feature_matrix(entityset=es,
                                     features=features,
                                     instance_ids=range(15))
    values = df[haversine.get_name()].values
    real_km = [
        0, 845.68234976, 1682.80832898, 2502.60659757, 3295.88714394, 0,
        222.42578133, 444.64819005, 666.46354463, 0, 0, 845.68234976, 0,
        1193.82939092, 2362.49490616
    ]
    assert len(values) == 15
    assert np.allclose(values, real_km, atol=0.0001)
    error_text = "Invalid unit inches provided. Must be one of"
    with pytest.raises(ValueError, match=error_text):
        Haversine(unit='inches')