Could you benefit from knowing your Lifelog users favourite locations and predicting their movement between those locations? In this post, Sony’s Master Engineer, Håkan Jonsson, explains how to apply machine learning to location data retrieved from the Sony Lifelog API. Find out about machine learning, clustering, how to access Sony’s Lifelog API and check out Håkan’s own notebook.
Using machine learning and location data, you can create context-aware applications – based on location predictions. For example, a phone app can prepare a call to a frequently used contact when heading for a certain location. We can also use location predictions to detect anomalies; when taking a trip to a new place, a photo album app can detect unusual activity, and could collect photos taken to share as a story.
To determine frequently visited places and predict movement between them, we will apply machine learning.
What is Machine learning and how can you use it?
When you can’t find the right analytical model to simulate or predict outcomes from your data, it’s worth turning to machine learning; a type of artificial intelligence (AI) that provides computers with the ability to learn without being explicitly programmed.
There are two main types of machine learning to get to know, supervised and unsupervised models:
- Supervised models are trained to map input to output. This would be applied to a previously unseen input, as you wouldn’t know the output to make predictions. Prediction in this case means regression or classification, and not necessarily forecasting.
- Unsupervised models are used to find relations in data, often in the form of clusters, i.e. data points that appear to belong together.
You can see how I’ve used those models in this notebook. I initially use unsupervised learning to find personal points of interests (important places) in a location trace. Then I use supervised learning to predict how the user moves between these points of interest.
To learn more about machine learning and the different models, you might want to have a look at this course.
What are Notebooks?
Data Scientists use notebooks for reproducible research. These notebooks allow information to be stored and published, together with code and visualizations, and to be shared for collaboration. This means any models produced can be executed later under the exact same conditions and with the same data. As you can see, this particular notebookis stored on github.comwhich supports the rendering of notebooks.
Why not clone or download the repository, and run it on your own local notebook? Then you can run through the code, chunk by chunk, and experiment with the outcomes with your own data. You can download IPython Notebook here.
Please note that IPython Notebook is being split into a separate IPython and notebook project.
Use the Sony Lifelog API
Sony’s Lifelog API is a REST-based web-service API in which you use endpoints like User Profile, Activities and Locations to get secure access to Lifelog data for a user. The user has full control of the data, and must approve to share it with your app. Using these endpoints as well as machine learning you could create different or more specific use cases for your app.
To run the code in the notebook, you should first download your location data. To do this, you need to do the following:
1. Sign in to a Sony Lifelog account. If you don’t have one, install the app to your Android phone from Google Play.
2. Use the app for a short while to access location data.
3. Access the Lifelog. Sign up here
4. Download the python scripts (credited to Christian Kullander) and do chmod +x get_all_for_user.py.
- Select OAuth 2 from the Authentication menu.
- Login using the same ID as you use for your Lifelog account.
- Select one of the methods / endpoints, for example /users/me/locations
- The second line of the response is the access token
6. Run the python script with the access token you just got: ./get_all_for_user.py –access_token 9xMsOshoAG5IOBX8VXWLui0MInAi –gzip ===========================
7. Unzip and rename the file to “locations.json” and load it into your notebook.
I really appreciate feedback on both this article and the notebook. Please post that here.
- How IFTTT successfully integrated the Lifelog API.
- Test your app using the Sony Remote Device Lab.
- Get support on the StackOverflow forum.