Utopian-bot: Apply median instead of average

Intro

After read a comment from @elear in this post I noticed that Utopian-bot had some issues with the average of some posts so I decided to check it out.
How Utopian-bot works? The bot check the body length of posts and compare it with the body length average calculated before with all posts in the same category. The problem with this is that there are some huge posts like this one which increase the average disproportionately.

Idea

Apply median instead of average.
The median is a commonly used measure of the properties of a data set in statistics and probability theory. The basic advantage of the median in describing data compared to the mean (often simply described as the "average") is that it is not skewed so much by extremely large or small values, and so it may give a better idea of a "typical" value - Wikipedia

With this we avoid outliers

Code

First I added a function to calculated the median

Then, for each post, we need to push the features we want into a list

After this we can call the median function doing this...
(median)

categoryObj.average_posts_length = median(total_posts_length);

...instead of this...
(average)

categoryObj.average_posts_length = categoryObj.total_posts_length / categoryObj.total_posts;


Conclusion

Doing this we avoid hugh and tiny values, and we can use it in different features e.g. Likes, Images, Links, and so on

Pull request

PS: I am not a JavaScript developer, so if you think something is wrong or if you think this is a bad idea please let me know, I want to read your feedback.


image2 - image3


Open Source Contribution posted via Utopian.io

H2
H3
H4
3 columns
2 columns
1 column
11 Comments