Giter Club home page Giter Club logo

go-trending's Introduction

go-trending

License GoDoc Build Status codecov

Trending algorithm based on the article Trending at Instagram. To detect trends an items current behavior is compared to its usual behavior. The more it differes the higher / lower the score. Items will start trending if the current usage is higher than its average usage. To avoid items quickly become non-trending again the scores are smoothed.

  • Configurable and simple to use
  • Use your own clock implementation, e.g. for testing or similar
  • Use any time series implementation as backend that implements the TimeSeries interface

Details

Uses a time series for each item to keep track of its past behavior and get recent behavior with small granularity. Computes the Kullback-Leibler divergence between recent behavior and expected, i.e. past, bahavior. Then blends the current item score with its past decayed maximum score to get the final score.

Examples

Creating a default scorer

import "github.com/codesuki/go-trending"

...

scorer := trending.NewScorer()

Creating a customized scorer

Parameters

  • Time series: is used for creating the backing TimeSeries objects
  • Half-life: controls how long an item is trending after the activity went back to normal.
  • Recent duration: controls how much data is used to compute the current state. If there is not much activity try looking at larger duration.
  • Storage duration: controls how much historical data is used. Trends older than the storage duration won't have any effect on the computation. The time series in use should have at least as much storage duration as specified here.
import "github.com/codesuki/go-trending"

...
func NewTimeSeries(id string) TimeSeries {
    // create time series that satisfies the TimeSeries interface
    return timeSeries
}

...

scorer := trending.NewScorer(
    WithTimeSeries(NewTimeSeries),
    WithHalflife(time.Hour),
    WithRecentDuration(time.Minute),
    WithStorageDuration(7 * 24 * time.Hour),
)

Using the scorer

import "github.com/codesuki/go-trending"

...

scorer := trending.NewScorer()

scorer.AddEvent("id", time)
// add more events. maybe using an event stream.

...

trendingItems := scorer.Score()

Documentation

GoDoc is located here

License

go-trending is MIT licensed.

go-trending's People

Contributors

codesuki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-trending's Issues

Compare Probability and Expectation

I have read your code and I have a question:

In item.go file, as I understand, you calculate the value of Expectation in the form of (tags/time) and the value of the probability in the range (0,1).

It leads to the negative value of KL score.

I wonder that we will compare each tag's KL, even we can have negative values of them?

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.