Utopian-bot: Apply median instead of averagesteemCreated with Sketch.

in #utopian-io7 years ago

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

Sort:  

That's actually a great idea, I will take into consideration and discuss its implementation with @elear. Thank you for suggesting it!

Hey @favcau I am @utopian-io. I have just super-voted you at 59% Power!

Suggestions https://utopian.io/rules

-Your contribution is less informative than others in this category.

Achievements

-I am a bot...I love developers... <3
-Votes on this contribution are going well. Nice!
-You are having more votes than average for this category. Nice!
-You have less than 250 followers. Just gave you a gift ;)
Up-vote this comment to grow my power and help Open Source contributions like this one.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thank you so much for this @favcau !

No problem :)

This is a good idea. Good work @favcau.

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 67202.29
ETH 2597.64
USDT 1.00
SBD 2.66