\chapter{The role of user profiling in detecting functional areas in cities}\label{chap:urban-computing-fa}
{

\begin{quote}
\textit{It would be very difficult even for a resident to characterise the social dynamics of a city and to reveal to foreigners the evolving activity patterns which occur in its various areas. To address this problem, however, large amount of data produced by location-based social networks (LBSNs) can be exploited and combined effectively with techniques of user profiling. The key idea introduced in this Chapter is to improve city areas and venues classification using semantics extracted both from places and from the online profiles of people who frequent those places. Results of this methodology are presented in LiveCities,
%\footnote{A video of the application is available at this url:\\ \url{http://vimeo.com/miccunifi/livecities}}, 
a web application which shows the hidden character of several italian cities through clustering and information visualisations paradigms. In particular in-depth insights are given for the city of Florence, IT, for which the majority of the data in the dataset have been collected. The system provides personal recommendation of areas and venues matching user interests and allows the free exploration of urban social dynamics in terms of people lifestyle, business, demographics, transport etc. with the objective to uncover the real `pulse' of the city. We conducted a qualitative validation through an online questionnaire with 28 residents of Florence to understand the shared perception of city areas by its inhabitants and to check if their mental maps align to our results. Our evaluation shows how considering also contextual semantics like people profiles of interests in venues categorisation can improve clustering algorithms and give good insights of the endemic characteristics and behaviours of the detected areas.
\footnote{This Chapter has been previously published as \dquote{User Profiling for Urban Computing: Enriching Social Network Trace Data} in \textit{Proceedings of the 3rd ACM Multimedia Workshop on Geotagging and Its Applications in Multimedia, 2014}~\cite{ferracani01}.}
%\footnote{\textit{Acknowledgments:}~this work was partially supported by Sport System Europe srl, Bologna, Italy.}
}
\end{quote}


\section{Introduction}

An analysis capable to convey to a realistic and truthful representation of a city and of the activities that take place in its areas must necessarily take into account not only human mobility but also users' socio-economic characteristics and interests distribution. Emerging social realtime systems offer an opportunity for the computation in the field of spatial data mining due to the huge amount of geo-localised data they continuously produce and that can be considered real human sensor data. 

There exist a considerable number of works addressing geographical modelling of information derived from widespread LBSNs like Twitter and Foursquare. Some recent studies analyse social media streams to obtain contextual semantics for city zones and venues whilst others focus more on human mobility. In \cite{hon} user's positions are observed predicting the locations of new tweets.  A sparse modelling approach is exploited which uses global, regional and user dependant topics and terms distribution in order to geo-reference topics on areas. Resources detected from geo-localised Twitter messages are also utilized to infer transient representation of volatile events happening at venues in \cite{can}. Foursquare places categories are used to create footprints of areas and users in \cite{nou} by means of spectral clustering. At the other hand, as regard to more focused works on urban computing, in \cite{che} check-ins are used to understand mobility patterns and how these are influenced by users' social status, sentiment and geographic constraints. In the Livehoods project Cranshaw et al. \cite{cran} cluster Foursquare venues using spatial and social proximity introducing a new user-based `bag-of-chekins' similarity algorithm. Although their approach is effective in capturing the social dynamics of cities according to people movements, it is completely lacking in considering who those people are and which are their motivations.

The key idea we propose in LiveCities instead is that city venues are characterisable both by static features, i.e. categories assigned by LBSNs on the basis of their type of service, and by dynamic features, i.e. the distribution of the interests of the people who checked-in there, which can change over time. To accomplish this we extract users' profiles of interests and users' geo-localised media automatically from Facebook, then we categorise detected venues using Foursquare APIs and, finally, we weights these features on the basis of semantic similarities and interests distribution. The main contribution of the work is to present our clustering module for city areas identification and classification based on our features selection approach and to show the web application developed for clusters visualisation and venues recommendation.



\section{The System}

\subsection{Dataset}

Through a Facebook app we have collected and gained access to 8839 user profiles, from which we extracted 124790 checkins and identified 52767 venues. Location information is available on Facebook from 2010. Facebook Places started out as a mobile application for people to check into business locations, then it was integrated in Facebook featuring a location tagging tool. People on Facebook can tag specific locations in status updates, image posts, or video posts. Others members can also tag their Facebook friends in specific locations within their updates and posts. Since the most part of the people registered in the application is resident of Florence and its surroundings we chose to conduct our evaluation on this city. The data used for the tests consists of 24031 check-ins and 5321 venues in Florence. Considered that Florence population counted 366443 in January 2013\footnote{\url{http://demo.istat.it/bilmens2013gen/index.html}. Istat data, January 2013} this is a large amount of information. Places were identified in updates, post and events in which the users participated and photographs they were tagged in. Each place has been categorised using the Foursquare API to assign a static label representing the venue's macro-category.
As for profiling, users' interests were extracted by retrieving the categories of Facebook pages for which users expressed a `like'. There are total 398884 `likes' distributed in 216 Facebook categories. User's data is the main reason for which we chose the Facebook APIs to build our dataset instead of the Foursquare or Twitter APIs, commonly used by works in the field\cite{qu} \cite{can} \cite{hon} \cite{cran}  \cite{che}. In this respect we can say that Facebook offers, in addition to check-ins data, a higher degree of contextual awareness and an `environment' exploitable to enrich check-ins semantics.
%\columnbreak
\subsection{Clustering module}


\begin{figure*}
 \centering
\includegraphics[width=\textwidth]{./figs/livecities-biglabel.jpg}
\caption{LiveCities clusters visualisation of Florence, IT. The figure shows a comparison between the clustering visualisation based on Foursquare categories and the results of our methodology that considers people interest distribution (Socially aware clustering).}\label{fig:1}
\end{figure*}

LiveCities uses \emph{k}-means clustering to partition the venues dataset into \emph{k} groups. We run the algorithm on the features selected on the basis of the main idea of this work that people semantics and semantic distances can be exploited to refine places categorisation. Clustering was performed for each city with similarity distances based on different features: 
\begin{itemize}
\vspace{-5pt}
\item \textbf{Geographic}: latitude and longitude; 
\vspace{-4pt}
\item \textbf{Foursquare based}: latitude, longitude, Foursquare venue's category; 
\vspace{-4pt}
\item \textbf{Socially aware}: latitude, longitude, Foursquare venue's category, a weighted vector of interests of the users who checked-in.
\vspace{-5pt}
\end{itemize} 
These three modalities of features selection have been essential in order to conduct the evaluation and to measure the improvements of our approach (i.e. socially aware). 
One of the very first problem we have to tackle in our data is that Facebook `likes' categories show an unbalanced distribution. The reason is that some interests like ``music'' or ``sport'' are more commonly shared between users than others and that Facebook pages in these categories are more widespread.% and therefore it is obvious that somehow the data are skewed.

To solve this issue, we calculate the weight of a category of `likes' on a venue considering three factors: 1) percentage of `likes' in each category for all the people who checked-in, 2) probability of a generic `like' to belong to a category, 3) semantic distance between each `likes' category and the assigned Foursquare category.
Formally, supposing we have a vector $F$ of $i_F$ Facebook places and also a set of $L$ users' `likes' for each venue, denoting as $c$ a `likes' category, we can compute the weight $w$ for each $c \in i_F$ as follows: \begin{eqnarray*}
\mathrm{w}(c, i_F) = \mathrm{percentage}(c, i_F) \cdot \log_{10}\left(\frac{10}{P(c)}\right) \cdot \mathrm{correlation}(c, i_F) 
\end{eqnarray*}

The function uses \emph{de facto} a TF-IDF approach. With $P(c)$ we mean the probability in 2) calculated and normalised on the basis of the distribution of the category `likes' in all the dataset `likes'. The correlation function instead uses a semantic distance to compute the affinity between `likes' categories and the Foursquare venues. Distances are pre-calculated and obtained using the Wikipedia Link-based Measure (WLM) by Milne et al. \cite{mil}. WLM is a measure for the estimation of the semantic relatedness of two Wikipedia articles through the comparison of their links. In our dataset there is a total number of 216 Facebook categories  for pages and 397 types of Foursquare venues, this means that it was necessary to calculate 85752 correlations. To accomplish this, every resource (Facebook category or venue type) has been associated to a corresponding Wikipedia article. We experimented two approaches: 1) manual association, 2) using the MediaWiki API to retrieve possible articles' matching titles and filtering the results using Latent Semantic Analysis (LSA). Both gave almost the same accuracy. There are two version of the WLM algorithm, the first considers in-bound links and is modeled after the Normalized Google Distance, and the other uses out-bounds links and is defined by the angle between the 
vectors of the links found within the two articles calculated with the cosine similarity. In LiveCities we re-implemented the algorithm in the latter version because less computationally expensive. To improve the correlation measure, we also observed that when two resources have an high semantic relatedness, often one of the two article contains a link to the other. When this condition occurs, we add a \emph{bonus} to the correlation value.

\subsection{User interface, personalization and recommendation}

LiveCities features a web application based on the principles behind visual analytics for dynamically exploring time-varying, localised and multivariate attribute data relative to city venues and venues customers. LiveCities provides a map based interface and exposes advanced visual components intended to maximise 1) explorative data analysis and 2) service targeting and personalisation. 

The application provides two main views, a search view and a clusters view. The search view has been designed as a traditional geographic search interface for venues and it allows users to efficiently filter data by categories or by people interests on the map. The cluster view instead visualises the results of the \emph{k}-means algorithm. There are three types of visualisation on the basis of three different features selections: 1) geographic, 2) Foursquare-based, 3) socially aware (our approach which takes into account people interests and semantic distances), cfr. Fig. \ref{fig:1}. Clusters can be visualised as typed squared icons or as set of points. The squared based visualisation uses icons as representative of the `centers of mass' of the detected clusters and allows a less bulky visual access to the information, whilst the points based view show on the map all the venues in the dataset. 

\begin{figure}
 \centering
\includegraphics[width=1\columnwidth]{./figs/tooltip.jpg}
\caption{1) Insights of a cluster, showing the histogram of venues categories and 2) the distribution of people interests on a venue.}\label{fig:2}
\end{figure}

Clusters are characterised by different colors, each one corresponding to 9 general Foursquare categories. Points transparency is directly proportional to the computed semantic affinity of the venue category to the cluster classification. In this way colour information is exploited in order to effectively depict points distribution \emph{per} cluster. Clusters boundaries are visualized on user interaction hovering with the mouse over the map, and are calculated using the convex hull algorithm. Users can have statistic insights  on clusters and venues through an interactive tooltip, cfr. Fig. \ref{fig:2}. In particular cluster's insights present the histogram of venues categories in the cluster and, for each column, the actual geo-referenced venue's place. Venue's insights show the distribution of interests of people who checked-in and provide address details and routing. Stars (from 1 to 3) on columns and venues represent recommended resources. LiveCities provides Facebook Login and it profiles users evaluating their Facebook `likes' on pages, obtained with the Facebook APIs.
Recommendation of areas and venues in LiveCities tries to maximise an objective function 
\vspace{-3pt}
\begin{eqnarray*}
\vspace{-15pt}
\max\limits_{p \in places} \mathrm{f}(p, logged\_user)
\end{eqnarray*}
\vspace{-5pt}

The $f$ estimates the correlation between the user profile of interests and the characteristics of city areas and venues. The semantic relatedness is computed using the WLM measure and weighting suggestions on the basis of users affinity with area's categories and individual venues. 

\section{Results and evaluation}
\label{sect:results}
A preliminary estimation of the results has been conducted for the city of Florence comparing outputs from the three different clustering procedures. We created an online questionnaire with the intent of receiving feedback from city residents about how they perceive the different areas of the city. The questionnaire shows users a map of the city, divided into 15 numbered cells. For each cell, we asked the users to assign labels, according to their mental maps, selecting up to three different categories among those used by LiveCities. %TODO non sono sicuro di questa costruzione inglese
We collected answers from 28 users, among 20 and 56 years old and for the most part affirming to have sufficient, good or excellent knowledge of the city (only 4\% of the interviewed declared to have an insufficient knowledge).
Since clusters shapes are irregular, a single cell can comprehend one or more clusters. On this basis we evaluate how interviewed people labeling of city areas aligns with detected clusters measuring the displacement in the weights of its venues categories.
Let $A_{n}$ be the area of predefined cells adopted in the questionnaire, with $n\in[1, 15]$, we consider the set of clusters $OC_{n}$ that have some overlapped area with $A_{n}$. Formally, for each geographical cluster $C_{i}$ with $i \in [1, K]$, where $K$ is the number of output clusters of \emph{k}-means algorithm, $C_{i} \in OC_{n}$ only if  $A_{n} \cap C_{i} \neq \varnothing$. Clusters are described with a multi-dimensional vector formed by weights $w_{cat}$ for every category of the system, with $0 \le w_{cat} \le 1$. We define the vector that describe $OC_{n}$ by computing mean values of the clusters contained in $OC_{n}$. We use the data obtained by the questionnaire, represented as a vector of categories weights for every area $A_{n}$, as testing data. We can so calculate the Mean Squared Error ($MSE$) between the expected values (weights in $A_{n}$) and the predicted values (weights in $OC_{n}$). As an example, figure \ref{fig:result} shows intra-categories $MSE$ of each of the three clustering methods for the cell $A_{14}$.
We repeat those steps for every $n$ in order to obtain a global $MSE$ of every clustering method (i.e. geographical, foursquare based and socially aware). The results are the following:
%\begin{itemize}
%\item$MSE_{geo} = 0.059$
%\item$MSE_{foursquare} = 0.062$
%\item$MSE_{social} = 0.046$
%\end{itemize}

%\begin{table*}[h]
\begin{center}
\vspace{-3pt}
  \begin{tabular}{lcr}
    $MSE_{geo}$  & 0.059 \\
    $MSE_{foursquare}$ & 0.062 \\
    $MSE_{social}$ & 0.046
  \end{tabular}
\end{center}

Results show that the $MSE$ in the socially aware clustering approach is lower than with the other ones. Even if the conducted study is still preliminary, results may suggest that our method tend to reflect more correctly the perception that inhabitants have about the characteristics of city areas. 



%\end{table*}

\begin{figure}[!htb]
%\vspace{-8pt}
\centering
\includegraphics[width=0.45\textwidth]{./figs/graph2.png}
\caption{Comparison of the $MSE$ in every category for each clustering approach in a case study area of the city.}
\label{fig:result}
%%\vspace{-12pt}
\end{figure}

%We conduct a qualitative validation through an online questionnaire with 28 residents of Florence, IT to understand the real perception of city areas by its inhabitants. 

\section{Conclusions}
LiveCities is a web application designed to provide users with a dynamic view of the social patterns characterising city areas and to facilitate resident and visitors in finding places and zones likely to be of interest. Urban computation can have a lot of applications, from marketing to trade area analysis,  buildings design, urban planning, demographics, entertainments, or simply citizens' life practice. LiveCities offers pictorial depictions of cities and exploits information visualisation techniques in order to shed new light on cities inner workings and on the relationship between people and the environments which they inhabit. In turn it can help to reveal the real `fabric' cities are woven out. 
In this demo we showed our methodology for features selection and clustering.  We use \emph{k}-means in order to group venues on the basis both of topological and sociological features. With sociological features we mean that venues are somehow representable not only by their static category assigned by LBSNs but also by the `bag-of-interests' of the people who checked-in. We also presented the web interface as well as the recommendation and personalisation module. Finally we conducted a preliminary evaluation through an online questionnaire. Results are encouraging and show that our approach deserves to be deepened and that LiveCities can be an useful web tool to suggest to users how to enjoy the best of the places in which they live.

