Abstract
As the number of social networks users has increased day by day so has the user’s dependency for communication on the social networks. Social networks enable people to connect with one another in many different ways. Many social networks such as Twitter provide their users the functionality to tag the user’s current location to the post. This geographical information can be used in various information retrieval processes. Currently many methods are present which cluster the tweets using traditional K-means algorithm in which user has to specify the number of clusters to be formed, and if the tweets do not lie within those clusters they are then treated as outliers and discarded. This paper presents a framework which focuses on clustering and indexing of tweets on the basis of its geographical and temporal features. The X-means clustering has been used which does not require the cluster number input from the user but rather it takes input from the index of the specified characteristics created from tweets. The indexing mechanism will not only help in ease of searching but will also aid in many retrieval tasks. The experimental analysis shows that the proposed framework generates improved results over traditional tweet clustering methods.
Introduction
Last few years have seen an exponential growth towards the power of publication of the online media. More and more publications, are shifting their focus from the print media to the online media. And the peer to peer sharing/broadcast of this online media is done through the social networking platforms. These social networking sites provides users ways to share the information among the group of people they know. In addition these Social Networking Sites not only allow the users to share news and other information but are also used to share the content that is generated by the user i.e. user-generated content. In blogs and microblogs the users can share the information with a specific group of people or broadcast it to all of the users, it may be a personal information related to an individual or some information related to the current happenings around the world. A tweet is similar to a microblog post. It also contains vast amount of information either in its body or in its meta-data. Figure 1 represents the characteristics of the tweet which are related to the proposed work.

Parts of a tweet.
A microblog is a platform where clients post short messages to convey their opinions or feelings on some particular topic. In microblogs the users usually express thoughts on a topic or examine current social issues and share it with each other instantly due to which large amount of information is present in microblogs. Important and trending issues are extracted from the microblog based on the time of the tweet. Besides time being an important factor the geo-location or spatial features of the post are also important as described by X. Li et al. [1]. Microblogs are like online journals, but there is also a limit on how much a user can share in a single microblog post (e.g. 140-character point of confinement of a tweet in Twitter). Since the launch of Twitter there has been an exponential increase in the number of users of microblogs. Most of the microblog posts that are related to a topic are considered to be relevant if they are within some time scope after which they are considered as irrelevant. Currently time is considered as an important feature in different fields of infromation retrieval. Most common algorithm used for cluster creation is K-means, after which the features can be extracted. T. Mansouri et al. demonstrate a variation of K-means algorithm to show that it can support real time streams for clustering, which is very helpful as it will accommodate all the new posts that arrive in real-time [2].
There are several methods present that cluster the tweets in different ways but they have several drawbacks. Some methods use only time for the clustering process, some methods consider only geo-coordinate for the clustering process, while others use variations of these features. For example, A. Samuel et al. proposed a variation of Lex-Rank algorithm to extract different types of temporal information present in the tweet for summary creation [3]. If more features are included in the clustering process then this will not only improve the results but will also provide results on the basis of multiple features. The motivation of this paper is to develop a framework that includes the temporal features, geo-coordinates and the sentiments of the tweet which will use them to create the clusters from which the index will be created for the event summarization process. Let us assume the clusters based on time and location are created using the traditional clustering algorithm such as K-means. For the clustering process one had to run the clustering algorithm multiple times to obtain the best results as the optimal number of clusters are not known initially and multiple runs of the algorithm are necessary. The proposed framework uses X-means algorithm which itself finds out the optimal value of clusters for the best results. Previous works have provided methods in which the number of clusters to be formed have to be given by the user for cluster formation.
X. Li et al. characterized two types of time-based questions in TREC accumulations that contain news chronicles: one dependably supports the latest archives and the other has pertinent records inside of a particular historical period [1]. To join time data into recovery models, they proposed a period based dialect model utilizing the previous model in light of an exponential or a typical appropriation relying upon the sorts of recency questions. Efron et al. proposed an estimator for the rate parameter of an exponential dispersion that joins the data related to the query [4]. They likewise recommended a period smoothing dialect which uses a period element to appraise the blending parameter for dialect model smoothing. Diaz et al. proposed a worldly question model, indicated P(t|Q), which was characterized as the standardized total of the significant scores of recovered records that are distributed at time t for inquiry Q [5]. They utilized fleeting components for question execution forecast [6] and worldly inquiry order [5] undertakings.
Keikha et al. proposed a period based pertinence model for online journal food recovery, which utilizes the P(t|Q) presented by Diaz et al. [6] as a weight of the terms in the pseudo-significance input setting [7]. Dakka et al. proposed a general system to assess P(t|Q). They organized the top recovered reports into containers and appointed evaluated significance worth to these canisters [8].
Peetz et al. displayed a versatile transient question demonstrating for web journal food recovery, in that they broke down the top recovered reports as far as fleeting histogram to discover the blasts [9]. They utilized reports with the most elevated scores from the blasts for inquiry extension and weighted every input record with the separation from the top that contains most archives.
Massoudi et al. gave an inquiry extension model for microblogs, which chooses terms transiently closer to the question accommodation time [10]. Their model functioned admirably for discovering archives identified with occasions as of now incident in any case, not also for past occasions. Metzler et al. proposed a fleeting inquiry development strategy for microblogs in view of the worldly co-event of terms in a timespan [11]. They initially performed pseudo-important timespan recovery for an occasion inquiry (e.g., tremor) and utilized those timespan for question extension. The transient inquiry development strategy demonstrated that selecting significant timespan is urgent for question extension for microblog archives. In the event that the fleeting question development lives up to expectations for an occasion inquiry, it may be valuable for specially appointed hunt inquiries.
Jones et al. and Kwak et al. attempted to recover applicable as well as crisp reports [5, 12]. Lavernko et al. and Jones et al. considered the other vital transient presumption, i.e., the occasion’s top time point [5, 13]. Jones et al. proposed a strategy to give more weight to these reports around top focuses [5]. Lavernko et al. attempted to consolidate question development on transient variety with recency keeping in mind the end goal to enhance the recovery execution [13].
X. Li et al. proposed a method to figure out how to rank for time-sensitive web look, in any case, there is distinctive strengths in microblog pursuit, and the greater part of their components are not pertinent in the microblog seek any more [1]. The issue of the substantial contrasts among distinctive questions can be tended to by inquiry ward positioning methodologies. There’re distinctive misfortune capacities to utilize the inquiry contrast to enhance the recovery viability, for example, question characterization based methodology [10], question bunching based methodology [11] and closest neighbor-based methodology [14]. With respect to web look, inquiries can be navigational, educational or value-based as described by Peetz et al. in [9]. Then again, the questions in time touchy microblog pursuit may have distinctive examples.
P. Su et al. proposed a method to cluster the data on the hierarchical basis while using different parameters. It provided improved results over existing methods [15]. Demiriz et al. proposed a method to analyse the data on the basis of their spatial and temporal features and used it in the domain of fraud detection using fuzzy rules that provided improved results [16].
Hawking et al. explained a way to reorder the index to the desired state according to certain characteristics such that the index does not lose it’s effectiveness [17]. Huston et al. presented a method for indexing the repeated n-grams in documents which is trivial for infromation retrieval [18]. De Vries et al. demonstrates the technique that is used for the cluster evaluation, and identifies the ineffective clusters formed as they have a high score but they do not have any value as they do not provide any clustering solution [19]. O’Hare et al. presented a method to extract the location using Flicker photos as ground truth and then using the photographs the locations were geo-tagged [20].
One major problem which the previous researchers have not been able to cope up with is the major drawback of the K-means algorithm. K-means is the prominent clustering algorithm which has a serious drawback as one is not able to determine how many clusters will be formed from the dataset, but one of the initial inputs of the K-means clustering algorithm is the number of clusters the user wants to form, which is basically a hit and miss methodology and usually the clusters formed are not the best case scenario. Therefore, this paper presents a framework which overcomes the drawback of traditional clustering algorithms and develops a multi level cluster where level 1 is based on spatial features and the level 2 is based on temporal features. Also tweets can be clustered on the basis of their sentiments. A dictionary is created which contains all the negative and positive sentiment words (approx. 2000 positive and 4800 negative sentiment words). Two clusters are created for negative and positive tweets. If a tweet contains positive sentiment then it is added to the positive sentiment cluster and if a tweet contains negative sentiment then it is added to the negative cluster.
Proposed framework
The proposed framework focuses on creation of clusters and indexing of tweets on the basis of the temporal, geo-locational and sentiment features of the tweets. The previous methods depended on the user for specifying the number of clusters to be formed but the proposed system will automatically evaluate the number of clusters on the basis of the indexes created. The method proposed by Pelleg et al. (X-means) which is an improvement of the K-means clustering algorithm is taken into consideration in the proposed framework, which helps in determining the number of clusters from tweets on the basis of the temporal, geographical and sentiment characteristics of the tweet [21].
A dataset can be defined as D = {d1, d2, d3, …, d n } which contains total of n documents and has a total of m-dimensions and different proxy models M j = {C1, C2, …, C k }, (e.g., for different values of k there are different models present) and the last prospect P (M j | D) using which the scoring of the models will be done. The Schwarz criterion can be used to approximate the posteriors.
The Schwarz criterion is described as follows in Equation 1:
Thus, the loglikelihood of the data is defined in Equation 4 as below:
The number of free parameters p j is k - 1 + dk + 1 = (d + 1) k. X-means globally uses the Schartz criterion to select the best model it encounters and locally to guide the centroid splits. [k min , k max ] represents the range of k. Initially X-means starts with k = k min and continues to add centroids when required until upper limit is reached. For addition of the centroids they are splitted into two in according to the Schwarz criterion. During the process, the centroid set with the best score is recorded as the best run and considered as output.
A tweet can be defined with the help of the following tuples as described in Equation 5:
T ID = TweetID
U = User name
T = Main text body of tweet
T P = Tweet Posting Time
G = Geo-location of tweet
L = Language of tweet
U ID = User ID
H = Hash-tags contained in the tweet
R U = Reply to User name
R T = Re-tweet
N RT = No. of Re-tweet
A tweet has more than 30 characteristics which may or may not be present in a every tweet. For the proposed work only a few characteristics are to be utilized and are considered as important. For example, we take only those tweets that contains the geographical location information (geo-coordinates), other tweets are then removed from the database.
The indexing of the tweets can be done on the basis of many different criteria but taking into consideration the query based method in which the user provides the system with a topic for searching and using that keyword an index is created by the system. Not all the tweets are relevant for the system as many of them are just re-tweets and others may just be in reply to some user and lack original content. So for index creation we will initially pre-process the tweets for noisy data. According to the Pareto’s Principle [22] based on Zipf’s law [23] states that 20% of the user queries represents the 80% of the total requests.
Equation 6 shows that the re-tweets and reply to user tweets are removed from the database as they do not contain original content.
Here, N represents the tweet database, R T represents re-tweets and R U represents the reply to user tweets.
Algorithm 1 removes the ’re-tweets’ and ’reply-to-users’ tweets from the database as it is necessary to not to incorporate those tweets that repeat the information from the same user again and again. For example, if the user re-tweets another persons tweet then the tweet will contain the same information as the original post and will be of no use to us. Also, those tweets which contain a reply to a user are usually comments containing some sort of praise or insult and does not relate to any original content and is useless for us.
Tweet ≠ N
Remove Tweet from N.
where,
N = Total number of Tweets
R U = Reply to User name
R T = Re-tweet
Tweet = Tweet
After the pre-processing the user query (Q) is taken into account. The user query represents the keyword which must relate to the query that must be represented in the search items.
Figure 2 describes the proposed framework for clustering and indexing of tweets based on the temporal and spatial features.

Framework of the proposed system.
All the remaining characteristics are considered as noise and are removed. After that the tweets are normalized using the tweet dictionary which contains the latest lingos and short forms of regular texts used by the twitter users. It is necessary to normalize the tweets as many of the users, due to the character limit of the microblogs, use some sort of short form of the words to effectively relay their message. After the normalization process the stop-words are removed form the tweets. After the stop-word removal the tweets are then tokenized and then stemming is performed on the tweets. The words before and after the tokenization are stored in the database, two data-frames are created. The first data-frame contains all the named entities from the tweets in their normalized from and the second data frame contains the named entities in the stemmed from. These data frames will be a useful tool in creation of the index for the tweets. The query (Q) is then matched with the tweets taken from N. If the word is present in the data frames then the tweet will be added to a new dataset, N
Q
. This new database represents only those tweets that are in accordance to the query given by the user. An initial index is to be created w.r.t. the query given by the user. The initial indexing of the tweets is done according to the number of re-tweets and the similarity measure between the query and tweets. The similarity measure used is related to the cosine distance. Equation 7 determines the similarity between the document and the query:
The creation of an initial index is necessary as the user might not be interested in the geographical and temporal aspect of the tweet and simply wants the tweets that relate to his/her query. Algorithm 2 represents the initial index creation where, T = {t1, …, t n } and Q = {q1, …, q n } and T and Q represents tweet and query respectively.
N RTx is bigger
Move the tweet up in index.
NRTx+1 is bigger
Move the tweet up in index.
where,
N Q = Total number of Tweets in N Q
N RTx = No. of re-tweets of tweet x
NRTx+1 = No. of re-tweets of tweet x+1
Here ‘x’ corresponds to the number of total tweets. After the initial index is created the tweets are then clustered in accordance to their temporal and spatial features. A temporal tagger is applied to obtain any mention of dates from the tweets which is compared to the time of post creation for discovery of relational temporal expression. Now from the G (geo-coordinates) of the tweets, the region of origin of tweets is obtained and distance of the tweet locations of the tweet is calculated based on the variance of the great-circle distance which is derived from Vincenty distance. A distance threshold is set to include the tweets in the cluster.
The number of locations are obtained and this number corresponds to the number of the clusters formed, using the X-means clustering algorithm which is the variation of the K-means algorithm and discovers the optimal number of clusters without user intervention. The X-means obtains the best clusters for the given data and produces much more accurate result.
After the initial clusters formation then the X-means is applied to the cluster on the basis of the date of the creation of the post on it & again the clusters are formed. Then the final clusters are obtained that represent the tweets that emerged from a particular geographical location and within a specified period of time, which can be used to obtain trending topics, peaks, regional interests, story generation, etc. Figure 2 demonstrates the framework of the proposed system.
Equation 8 demonstrates the tweet cluster formation on the basis of the threshold distance and great circle distance formula. Where, T
GCD
is the great circle distance, T
H
is the threshold distance, C
x
is the cluster and the T
c
is the flag which determines whether the tweet belongs to the cluster or not.
Algorithm 3 demonstrates the initial cluster formation process based on the geo-coordinates.
Calculate T GCD
T ← C1
from new cluster from F C
T ← C2
where,
N = Total number of Tweets
φ = Latitude
λ = Longitude
T = Tweet
T GCD = Great circle distance of tweet
T h = Threshold of the tweet (constant)
C1, C2 = Clusters
F C = Data-frame of cluster
In the algorithm described above the clusters are formed on the basis of the geo-coordinates. First the great circle distance is calculated between tweets so as to determine the distance between them.
After the clustering of tweets on the basis of the geo-coordinates a second index (I G ) is created on the basis of the cluster formed. The index is created as follows in Algorithm 4:
N Cx is bigger
Move the cluster up in index.
NCx+1 is bigger
Move the tweet up in index.
N RTy is bigger
Move the cluster up in index.
NRTy+1 is bigger
Move the tweet up in index.
where,
N Q = Total number of Tweets in N Q
C G = Clusters fromed on basis of spatial features
C x , Cx+1 = Clusters in the index
N RTy , NRTy+1 = No. of re-tweets in cluster y
Here ‘x’ corresponds to half of the number of centroids according to the heuristic criterion for how promising they are to split and then split then. After that X-means is run. Equation 9 demonstrates the cluster formation on the basis of the temporal features of the tweet. Where, T P is the time of the post, T C is the cluster time, T c is the tweet flag for determining whether the tweet belongs to the cluster or not and C y is the cluster.
Algorithm 5 demonstrates the final cluster formation process based on the temporal features.
T ← T P
T ← - T P
Discard User Post
T ← C
N Q ← N Q - 1
T ≠ C
Select different cluster
where,
T userpost = User’s posting time
T event = Time of event
T = Tweet
T P = Time of Post
N Q = Total Post
C = Cluster
After the clustering based on the temporal features of the tweet is done on each of the clusters formed by the geographical features, level 2 clusters are obtained within the geographical features w.r.t. time of the post. The index formation of the time based clusters is defined in Algorithm 6.
N Ca is bigger
Move the cluster up in index.
NCa+1 is bigger
Move the tweet up in index.
N RTb is bigger
Move the cluster up in index.
NRTb+1 is bigger
Move the tweet up in index.
where,
N Q = Total number of Tweets in N Q
C T = Clusters fromed on basis of temporal features
C a , Ca+1 = Clusters in the index
N RTb , NRTb+1 = No. of re-tweets in cluster b
Initially Algorithm 3 constructs the clusters on the basis of the city names which are calculated with geopy and the distance is calculated using the great circle distance which is more effective for calculating large distance on an arc. A threshold value is set that will specify the minimum number of tweets that are required to from a cluster and then the outliers are allocated to the closest neighbouring clusters. After that individual clusters are taken and then the clustering on the basis of the time of post is done.
If the user wants to cluster the tweets on the basis of their sentiments then it is also possible. A dictionary is created containing all the negative and positive sentiments & emoticons. Algorithm 7 depicts the cluster formation on the basis of sentiments.
T ← C P
N Q ← N Q - 1
T ← - T
Check for Negative Sentiment
T ← C N
N Q ← N Q - 1
Discard Tweet as Neutral
where,
S D = Sentiment Dictionary
T = Tweet
S D P = Positive Sentiment & Emoticon
S D N = Negative Sentiment & Emoticon
N Q = Total Post
C P = Positive Sentiment Cluster
C N = Negative Sentiment Cluster
Figure 3 shows the code for cluster formation process.

Cluster formation code.
The configuration of the system used for experimental purposes is as follows: a) Processor:- Intel Core i7 (5th Gen, 3.2 GHz), b) HDD:- 1 TB, c) RAM:- 16 GB (DDR3, 1600 MHz), d) GPU:- Nvidia Geforce GT960M (3840 MB, approx. 1960 cores). The Twitter data is obtained using Fire-hose API, which results in getting all the tweets. There are 134,538 tweets that contain the geographical location. The data was collected during Feb’ 2016 and May 2016. Tweets which were in English were only taken into consideration. The database and framework used was Pandas. The two data frames are created for searching and indexing process.
The maximum tweets obtained contained the following G’s: 1:- (28.6538100, 77.2289700) 2:- (19.0728300, 72.8826100)
which corresponds to Delhi and Mumbai respectively using the geopy library.
The distance is to be calculated between the two locations so as to be certain that the locations fall within the threshold value as set by the user. If the tweet is outside the threshold value then a separate cluster is fromed of the tweet. The distance between two geo-coordinates is calculated using the special case of Great-Circle distance based on Vincenty fromula [24] as in Equation 10:
where,
φ1, λ1 = Latitude and Longitude of Point 1
φ2, λ2 = Latitude and Longitude of Point 2
Δφ, Δλ = Absolute difference of Latitudes and Longitudes
Δσ = Central Angle between the Points
After using both co-ordinates in the equation the resultant distance between the two locations is obtained which comes out to be 1154 Kms or 717 Miles. Calculating the distance between the tweets and using the given threshold value the clusters are formed.
Now the clusters are obtained based on the geo-location of the tweets. The clusters are labelled on the basis of the maximum number of tweets from a location. Now within the clusters the tweets are again clustered on the basis of the date of posting the tweet. Again this is done using the X-means clustering but this time the temporal aspect of the tweets is taken into consideration. Finally, clusters are obtained based on the date of the creation of the post.
The clusters obtained are first geographically clustered and then those clusters are again clustered using the time of creation of the post. Figure 4 depicts the clusters formed on the basis of the geo-coordinates.

Level 1 cluster fromed on the basis of the geo-location of the tweets (Red ’X’ represents the center of the cluster).
Figure 5 depicts the clusters fromed on the basis of the time of the tweets in location 1 cluster.

Level 2 cluster fromed on the basis of the time of the tweets in location 1.
The evaluation is done using two methods: Davies - Bouldin Index and Silhouette Coefficient.
n = Number of clusters,
c x = Centroid of cluster x,
σ x = Average distance between elements in x w.r.t. c x ,
d (c i , c j ) = Distance between centroids c i and c j .
DBI relates the average distance of elements of each cluster to their respective centroids to the distance of the centroids of the two clusters.
Since algorithms that produce clusters with low intra-cluster distances (high intra-cluster similarity) and high inter-cluster distances (low inter-cluster similarity) will have a low DBI, the clustering algorithm that produces a collection of clusters with the smallest DBI is considered the best algorithm based on this criterion.
Silhoette coefficients (as these values are referred to as) near +1 indicate that the sample is far away from the neighbouring clusters. A value of 0 indicates that the sample is on or very close to the decision boundary between two neighbouring clusters and negative values indicate that these samples might have been assigned to the wrong cluster as shown in Equation 12.
Which can be also written as in Equation 13:
For each datum i, let a(i) be the average dissimilarity of i with all other data within the same cluster. a(i) represents as how well i is assigned to its cluster (the smaller the value, the better the assignment). Then define the average dissimilarity of point i to a cluster c as the average of the distance from i to all points in c. Let b(i) be the lowest average dissimilarity of i to any other cluster, of which i is not a member. The cluster with this lowest average dissimilarity is said to be the ’neighbouring cluster’ of i because it is the next best fit cluster for point i.
For s(i) to be close to 1 a(i) ⪡ b(i) required. As a(i) is a measure of how dissimilar i is to its own cluster, a small value means it is well matched. Furthermore, a large b(i) implies that i is badly matched to its neighbouring cluster. Thus an s(i) close to one means that the datum is appropriately clustered. If s(i) is close to negative one, then by the same logic i would be more appropriate if it was clustered in its neighbouring cluster. An s(i) near zero means that the datum is on the border of two natural clusters.
The average s(i) over all data of a cluster is a measure of how tightly grouped all the data in the cluster are. Thus the average s(i) over all data of the entire dataset is a measure of how appropriately the data has been clustered. If there are too many or too few clusters, as may occur when a poor choice of k is used in the clustering algorithm, some of the clusters will typically display much narrower silhouettes than the rest. Thus silhouette plots and averages may be used to determine the natural number of clusters within a dataset.
Table 1 shows the cluster evaluation of the different methods M1 by Morchid et al. [27], M2 by Khan et al. [28], M3 by Kalee et al. [29], M4 by Doulamis et al. [30] and the proposed method. Three different runs on different numbers of tweets have been performed. In all different scenarios the proposed system performs better than the existing clustering systems.
Cluster evaluation
The index created in accordance to the user query is as described below. First the query word given is ‘kejriwal’ and the tweets are then first collected and then initial index is created by removing the re-tweets and reply to posts. Table 2 shows the initial index (I i ) created.
Initial index (I i )
After the level 1 clusters are formed for each cluster the indexing is done on the basis of the similarity of the query and the text and the number of re-tweets. Here the indexing is done in cluster with geo-coordinates for Mumbai.
After the level 2 clusters are generated the index is created based on the basis of the temporal features. The keyword taken here is ‘kejriwal’ and the tweet is indexed on the basis of the time of the post.
Tables 3 and 4 represents the clusters formed The complexity of the proposed framework is O (N log K), which means that the execution time of the proposed method is directly proportional to the logarithm of the input data. The method does not have to use all the data. Whereas on the other hand the complexity of the k-means method is O (ndk+1 log n), which means that the run time of the algorithm depends on the number of factors such as n which is the number of items to be clustered, k which is the number of clusters to be formed and d which is the dimensions. This shows that the proposed method is less complex than the traditions tweet clustering algorithms.
Index created on the basis of spatial features (I G )
Index created on the basis of temporal features (I T )
In this paper a framework has been presented that forms the clusters from the tweets on the basis of the temporal features, geographical location and the sentiment of the tweets. The proposed framework gives a way to cluster the tweets that belong to a particular location, a particular time period or belonging to a particular sentiment that can be searched by the user as per the query. Two indexes are created before the clustering using the proposed framework, one is for non-stemmed keywords and another for stemmed keywords, which will not only aid in the searching process but also in the summarization process. The clusters that are created using this framework will not only decrease the effort needed to search the tweets but the search time will be decreased. In future, the proposed work can be extended in the following directions: the database can taken as dynamic i.e. real-time, both internal and external evaluation is needed for improved validation as no gold standard exists, the authenticity of the tweet can be evaluated and finding a way to normalize the non geo-tagged tweets to nearest geo-location.
