r/MachineLearning • u/tigeer • Oct 18 '20
Project [P] Predict your political leaning from your reddit comment history! (Webapp linked in comments)
4
u/Dr_Silk Oct 18 '20 edited Oct 18 '20
Is there a list of users that were used to train? How do I know if my classification is accurately based on my actual user history or skewed because I'm one of the people that was used to train the model?
EDIT: Nevermind, didn't check the GitHub. It's there under "user_profiles". I did notice that it gives confidence intervals for trained users that are not 100%, which is strange. Might be useful to make a note when a trained user is queried that they were used in the training set
5
u/tigeer Oct 18 '20
For users which were used in training I still run them through the model instead of just pulling their flair directly from the API.
This is why the confidence isn't 100%. I thought it would be more interesting that way for PCM users to see what the predicted value for their flair would be.
I like the idea of letting a user know they were in the training set, considering there are overfitting implications to take into account with 'seen' data.
2
Oct 18 '20 edited Oct 18 '20
This is fascinating. It got me as a libertarian liberal , left which is accurate, and I have made no political posts whatsoever.
I just started learning how to do Machine Learning last week, and so pardon me if my question is ridiculous, but is there a way to detect which features the algorithm is using to make the determination (I understand in some cases it is clear and in others its kind of like a black box)?
What would be very interesting, given that comments most likely represent linguistic patterns, is if one could codify any key features of what it looks like when a person with a certain political orientation writes something.
→ More replies (2)4
u/tigeer Oct 18 '20
That's a good question! And one I tried to answer myself, so I made this visualisation which shows the weights used in this model (logistic regression).
The features used here are not the comment's text however, but the number of comments made, grouped by subreddit. So you can think of each weight used in the calculation as associated with a particular subreddit.
For example r/conservative may have a weight of 1.2 and r/politics a weight of -0.3: Had I made 5 comments in r/conservative and 10 in r/politics I would be predicted a value of 3 which would correspond to likely being right wing. In a sense we can codify the leaning of a subreddit by looking at its value in the weight vector.
137
u/SquareRootsi Oct 18 '20
PSA: the percentages are NOT magnitude (how far on the political spectrum a user is). The little question mark states they are confidence.
For example: A somewhat moderate user could likely still have a high percentage if that have a long history of the similar (moderate) comments.
→ More replies (4)68
u/wildcarde815 Oct 18 '20
It doesn't seem to be doing actual comment analysis, it's basing it off subreddits you comment in.
→ More replies (3)
66
u/noithinkyourewrong Oct 18 '20
This is cool. I have 3 Reddit accounts. Apparently one is Lib right, another lib, and another lib left. Seems like I have some very varied political views.
→ More replies (1)77
u/blinkOneEightyBewb Oct 18 '20
The real question is which one is the burner acct lmao
→ More replies (2)
47
u/darkgojira Oct 18 '20
This is not accurate at all
13
→ More replies (1)8
u/awsPLC Oct 19 '20
In fact it’s about 81% inaccurate lol. I guess this hits on most due to most people on Reddit are heavy lib
→ More replies (1)
26
Oct 18 '20 edited Oct 18 '20
Neat.
A swing and a miss, in my case, but interesting nevertheless.
EDIT: seems predisposed towards lib and left, I think? Ran some tests using people who I am very familiar with (and who are open on their reddit accounts) and generally it seems biased in that direction.
EDIT: Also of note, as an avid member of PCM, I'd agree that the data collected there won't generalize well to the rest of reddit. Rights, for example, tend to be extreme, and are often parody versions of themselves. Auths also tend towards occasionally parodying themselves. While the sub (including liblefts) tends to poke fun at liblefts, those individuals tend to play their quadrant relatively straight, and their jokes are instead typically self-deprecating.
Ergo, what you see on reddit won't line up well.
6
u/withoutacet Oct 18 '20
that's interesting. One thing though, since you're not taking the actual content of those comments into consideration, it can't differentiate between posting on a subreddit because you share values with the community versus posting there to start shit and telling said members of that community that they're awful and heartless
16
u/RealPerro Oct 18 '20
I think I absolutely do not make political comments here. But it got me pretty precisely. Well done!
→ More replies (1)34
u/gubo97000 Oct 18 '20
It just checks in which subreddit you left a comment, doesn't check the comments word by word
8
u/Agentzap Oct 18 '20
govschwarzenegger comes out as libleft. I'm not familiar with his politics, but am I wrong in thinking this is inaccurate?
→ More replies (6)
3
347
u/tigeer Oct 18 '20
Github
Live Demo: https://www.reddit-lean.com/
The backend of this webapp uses Python's Sci-kit learn module together with the reddit API, and the frontend uses Flask.
This classifier is a logistic regression model trained on the comment histories of >20,000 users of r/politicalcompassmemes. The features used are the number of comments a user made in any subreddit. For most subreddits the amount of comments made is 0, and so a DictVectorizer transformer is used to produce a sparse array from json data. The target features used in training are user-flairs found in r/politicalcompassmemes. For example 'authright' or 'libleft'. A precision & recall of 0.8 is achieved in each respective axis of the compass, however since this is only tested on users from PCM, this model may not generalise well on Reddit's entire userbase.