Skip to main content

A light package for build and analyse co-locationship

Project description

co-locationship

"Co-locationship" as an Alternative to Social Ties in Predictability of Human Mobility.

The code was tested on Python 3.6.

Install

The dependencies package are shown in requirements.txt, also, you can run

pip install -r requirements.txt

After installing all dependencies clone the repository and do (inside the top directory):

pip install . 

This will install a copy of the code as a package. If you want to install a package that links to the cloned code, run

pip install --editable .

This makes changes to the source files in the cloned directory immediately available to everything that imports the package.

Anywhere on the system you can then import the package:

import colocationship as cl

Dataset

All processed datasets (Weeplaces, BrightKite, Gowalla) we used in this repo can be found in Google Drive.

Usage

Build a Co-Locationship Network

df_checkin = pd.read_csv("../dataset/weeplace_checkins.csv")
co_locationship = cl.Co_Locationship(df_checkin,
                                     mins_records=150,
                                     missing='-')
# generate placeid sequence
co_locationship()

# calculate basic information of co-locationship network
co_locationship.calculate_info()

# network filter, including minimum both quality control and contribution control, and minimum 10 alters requirement and ranking.
co_locationship.network_control(quality=True, 
                                contribution=True, 
                                num_alters=10, 
                                by=['userid_x', 
                                    'meetup',
                                    'N_previous'], 
                                ascending=[True, 
                                           False, 
                                           True],
                                N_previous=150)

# calculate details of co-locationship network, including cumulative cross-entropy and cumulative cross-predictability
co_locationship.calculate_network(verbose=False, filesave=True)

The code in Line 6, Line 9, Line 24 may takes a long time, so it is better to run them separately, and save these interim results.

Social relationship network

The similar code for social relationship, just slight differences.

df_friend = pd.read_csv("../dataset/weeplace_friends.csv")
social_relationship = cl.Social_Relationship(df_checkin,
                                             df_friend,mins_records=150,
                                             missing='-')

# given the same time unit, we can just the placeid sequence generated by co-locationship, otherwise, also run `social_relationship()` to generate placeid sequence again.
social_relationship.placeidT = placeidT

social_relationship.calculate_info()

srn_filtered = social_relationship.network_control(
                                contribution=True, 
                                num_alters=10, 
                                by=['userid_x', 
                                    'meetup',
                                    'N_previous'], 
                                ascending=[True, 
                                           False, 
                                           True],
                                N_previous=150,
                                freq='H')
# calculate details of co-locationship network, including cumulative cross-entropy and cumulative cross-predictability
social_relationship.calculate_network(verbose=False, filesave=True)

Similarly, the code in Line 9, Line 23 may takes a long time, so it is better to run them separately, and save these interim results.

Comparison of co-locationship and social relationship

# Create a comparsion class to compare these two networks
compare_v2 = cl.ComparisonNetwork([co_locationship,
                                   social_relationship],
                                  ['co-locationship',
                                   'social relationship'])

# print the number of shared users in both networks
compare_v2()

# Histogram plot comparison
compare_v2.plot_CE(l=8,w=5)

# RCCP comparison based on ranking
compare_v2.plot_errorbar(target='RCCP', l=8,w=5)

# Local similarity comparison
compare_v2.plot_similarity(local=True, l=5,w=5)

# Global similarity comparison
compare_v2.plot_similarity(local=False, l=5,w=4)

# Monotonicity statistical test
compare_v2.stats_test_monotonicity(target='RCCP')

# Consistency statistical test
consistency_test = compare_v2.stats_test_consistency(target='RCCP')

Details

Details please refer to example/example_weeplaces.ipynb.

Contributing

PRs accepted.

License

MIT © Zexun Chen

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colocationship-0.0.1.tar.gz (14.8 kB view hashes)

Uploaded Source

Built Distribution

colocationship-0.0.1-py3-none-any.whl (19.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page