Skip to content

Quickstart

Features are calculated based on the config you send to faas.

This config specifies features you want to calculate and locations for which you want to calculate these features.

You can learn more about faas config here, but for now it will be easier to understand with examples.

Apartments within a radius

Let's calculate the average price of apartments within a 500-meter radius from the point with coordinates (30.33, 59.86). Note the order: (longitude, latitude).

import faas_client as fc

config = {
    'points': [
        {
            'id': 1,
            'geopos': {
                'type': 'Point',
                'coordinates': [30.33, 59.86]
            }
        },
    ],
    'features': {
        'apartments_r500': {
            'type': 'circle',
            'dataset': 'ru-pub-households/apartments',
            'limit': 500,
            'field': 'price',
            'agg': 'mean',
        },
    },
}

df = fc.calc(config)

Distance to the nearest station

Let's calculate distance to the nearest metro station within a 1 km radius. Values are calculated separately for each point in a given points dataset.

import faas_client as fc

config = {
    'points': 'client/points',
    'features': {
        'metro_nearest_dist': {
            'type': 'distance',
            'dataset': 'ru-pub-transport/metro',
            'metric': 'dist',
            'limit': 1000,
            'fillna': -1,
        },
    },
}

df = fc.calc(config)

Take competition into account

Now let's suppose we want to know number of households from new buildings that are most likely to visit our stores. To calculate this number we will use huff feature that takes into account competitor stores and implements huff model.

Both our stores and competitor stores are taken from datasets.

We'll assume that only households within 15-minutes walking distance are relevant. To separate new buildings from other buildings we'll filter apartments dataset by year field.

import faas_client as fc

config = {
    'points': 'client/origin',
    'competitors': 'client/competitors',
    'features': {
        'apartments_huff_foot_15': {
            'type': 'huff',
            'dataset': 'ru-pub-households/apartments',
            'metric': 'foot',
            'limit': 15,
            'field': 'households',
            'agg': 'sum',
            'filter': {'year': {'$gte': 2010}},
        },
    },
}

df = fc.calc(config)