The MidTerms on Twitter

Antonio Lopardo
Nov 5, 2018 · 12 min read

Intro


Search

Image for post
Image for post
\"French Hill\" OR @RepFrenchHill OR @ElectFrench
TRUMP OR REPS OR REPUBLICANS OR REPUBLICAN OR MCCCONNELL OR \'MIKE PENCE\' OR \'PAUL RYAN\' OR #REPUBLICANS OR #REPS OR @realDonaldTrump OR @SpeakerRyan OR @senatemajldr OR @VP OR GOP OR @POTUS
Image for post
Image for post
Approximation of PA-10
PA-10-a 40.03392360399664,-76.78482055664064,16.274661km
PA-10-b 40.19594518732199,-77.05535888671876,16.238963km
PA-10-c 40.28752567143796,-76.73475783783944,14.080184km
PA-10-d 40.53970542053963,-76.78781683556737,16.456645km
PA-10-e 40.395718433470364,-76.94387265946717,6.962575km

Analyze

def pre_process(text):
text = text.lower()
text = re.sub(r"http\S+", "", text)
text = re.sub('[^a-zA-z0-9\s]','',text)
text = remove_stop(x)
return text
embed_dim = 128 
lstm_out = 256
lstm_out2 = 64
model = Sequential()
model.add(Embedding(max_features,
embed_dim,
input_length = X.shape[1]))
model.add(Dropout(0.5, noise_shape=None, seed=None))
model.add(LSTM(lstm_out, dropout=0.3, recurrent_dropout=0.3, return_sequences=True))
model.add(LSTM(lstm_out2, dropout=0.3, recurrent_dropout=0.3, return_sequences=False))
model.add(Dense(2,activation='softmax'))
model.compile(loss = 'categorical_crossentropy',
optimizer="adam",
metrics = ['accuracy'])
print(model.summary())
@RealJamesWoods I love the idea of this clown thinking about a White House Run! This is the dementia of the democrats. They don’t see their insanity. Bring it on @SenBooker! Most republicans would love to watch you run! You are a very entertaining comedian!#MAGA
1 0.9939819
When I tweet angrily, it’s because I have to keep my mouth shut at family gatherings. Because the people I’m related to who did vote for Trump:
Don’t see why it was a bad idea (still)
Aren’t actually bad people (much as some would like to believe)
Are people I still love
0 0.84874254
@FrankDangelo23 @realDonaldTrump I Was Going To Be A Liberal For Halloween But My Head Wont Fit Up My Ass.
1 0.9390376
.@BryanSteilforWI, we’ve been calling on you to pledge not to make any cuts to Social Security or Medicare for days now. You’ve been silent.I’ll ask again. House Republicans have proposed cutting Social Security and Medicare by $541 billion. Will you promise to oppose this cut? https://t.co/at0wA3xuPh
0 0.94953746
Tip:
If you’re being nominated for a nonpartisan position as a neutral arbiter on the Supreme Court, attacking “the left,” “Democrats,” “the Clintons” and “the media” in your opening statement while noting there will be reprisal for years to come is, well, disqualifying.
1 0.93661255
Click on the link above to try it yourself
Image for post
Image for post
5 districts in the validation set
Image for post
Image for post
the other 5 districts in the validation set
NM-01

Dems_norm:0.5557900385507956
Reps_norm:0.4442099614492045

CT-05

Dems_norm:0.5721007363126642
Reps_norm:0.4278992636873358

IN-02

Dems_norm:0.4447068405173887
Reps_norm:0.5552931594826113

SC-05

Dems_norm:0.4015876176502325
Reps_norm:0.5984123823497676

AZ-06

Dems_norm:0.43360491050856204
Reps_norm:0.5663950894914379

CA-16
Dems_norm:0.7917015628237059
Reps_norm:0.2082984371762941

PA-06

Dems_norm:0.6304941713408859
Reps_norm:0.3695058286591141

TX-22
Dems_norm:0.27420907089758767
Reps_norm:0.7257909291024123

CA-07

Dems_norm:0.6539088862820972
Reps_norm:0.3460911137179028

NC-05

Dems_norm:0.486334897720096
Reps_norm:0.5136651022799039

Visualize

Image for post
Image for post
Image for post
Image for post
The map is available at http://www.twitterpoliticalsentiment.com/USA/

P.S.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store