Coder Social home page Coder Social logo

anshul1004 / tweetsclustering Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 4.0 3.4 MB

Clustering similar tweets using K-means clustering algorithm and Jaccard distance metric

Python 100.00%
twitter tweets tweet-clustering clustering k-means k-means-clustering k-means-implementation-in-python python python3 jaccard-similarity

tweetsclustering's Introduction

TweetsClustering

Twitter provides a service for posting short messages. In practice, many of the tweets are very similar to each other and can be clustered together. By clustering similar tweets together, we can generate a more concise and organized representation of the raw tweets, which will be very useful for many Twitter-based applications (e.g., truth discovery, trend analysis, search ranking, etc.)

Here, the tweets are clustered using Jaccard distance metric and K-means clustering algorithm.

Jaccard Distance

The Jaccard distance, which measures dissimilarity between two sample sets (A and B). It is defined as the difference of the sizes of the union and the intersection of two sets divided by the size of the union of the sets.
Dist(A, B) = 1 - |A intersection B|/|A union B|

For example, consider the following tweets:
Tweet A: the long march
Tweet B: ides of march
|A intersection B | = 1 and |A union B | = 5, therefore the distance is 1 โ€“ (1/5)

Jaccard Distance Dist(A, B) between tweet A and B has the following properties:

  1. It is small if tweet A and B are similar.
  2. It is large if they are not similar.
  3. It is 0 if they are the same.
  4. It is 1 if they are completely different (i.e., no overlapping words).

Dataset Used

https://archive.ics.uci.edu/ml/datasets/Health+News+in+Twitter

Tweets Preprocessing

Firstly, the tweets are preprocessed using the following steps:

  • tweet ids and timestamps are removed
  • words that starts with the symbol '@', e.g., @AnnaMedaris, are removed
  • hashtag symbols are removed, e.g., #depression is converted to depression
  • any URL are removed
  • every word is converted to lowercase

K-Means Clustering Algorithm

K-means clustering algorithm is implemented from scratch, without using any machine learning libraries

Output results on one of the datasets is provided in "Report.pdf".

Steps To Run

  1. If the system don't have python Installed in it, first install python (version greater than or equal v3.7)

  2. The code uses the following python native libraries - random

    • re
    • math
  3. In the root directory of the project, execute the given command from command line:

    • "python main.py"
  4. Output from a sample run is also stored in a file named "output.txt" for the reference.

Notes : a) The code uses "bbchealth.txt" by default for the tweets data. - A user can change the url path to another data file as desired from the given files.

b) The code uses, "3 clusters" by default and performs "5 experiments" one after another. - Each experiment increases the number of clusters being used from the previous experiment by 1. - A user can change the default value of intial clusters (k) and number of experiments to be performed.

c) The program returns the value of SSE (sum of squared error) and size of each cluster after every experiment.

d) A user can also print tweets in each cluster by uncommenting certain part of code written in the main.

tweetsclustering's People

Contributors

anshul1004 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.