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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file colocationship-0.0.1.tar.gz.

File metadata

  • Download URL: colocationship-0.0.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for colocationship-0.0.1.tar.gz
Algorithm Hash digest
SHA256 37ff95c894b298b05d72eb882875cddf3f1f660e3c2626c0a8a34bebb6d846cd
MD5 81b751d36b8cb5a306b37134819f7cd7
BLAKE2b-256 4eea95a2b25c380a7287d1096f1de30a4509e60f8ba574da4c2ea00c527e82d0

See more details on using hashes here.

File details

Details for the file colocationship-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: colocationship-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for colocationship-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 689f556b0df301f8e8ba3f3b497bc920b77e24a7ae42e86813e5161ffc53122a
MD5 1fbc473aa30a678536932890cfd775dc
BLAKE2b-256 523864bd98291eabfa00807542c2212258164966745434bb744873f87b61af81

See more details on using hashes here.

Supported by

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