{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## DS4420: In-class exercise on clustering (`BERT` representations of) Trump tweets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "I downloaded all of Trump's tweets for the past year, and ran these through a pre-trained `BERT` model (don't worry; we will cover this later in the semester -- for now it suffices to know that `BERT` is a big neural network that has been 'pre-trained' on a very large dataset and provides useful feature vectors for texts). This means we have 768-dimensional vector representations of each tweet." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Unnamed: 0tweetsvectors
00Always heard that as President “it’s all about...[-0.6935118436813354, -0.3402666747570038, 0.7...
11Be careful and try staying in your house. Larg...[-0.7567042708396912, -0.41789475083351135, 0....
22Nancy Pelosi and some of the Democrats turned ...[-0.7120085954666138, -0.3883921205997467, -0....
33No Amnesty is not a part of my offer. It is a ...[-0.6233459115028381, -0.3593074679374695, -0....
44Nancy Pelosi has behaved so irrationally &...[-0.6446494460105896, -0.32997167110443115, -0...
\n", "
" ], "text/plain": [ " Unnamed: 0 tweets \\\n", "0 0 Always heard that as President “it’s all about... \n", "1 1 Be careful and try staying in your house. Larg... \n", "2 2 Nancy Pelosi and some of the Democrats turned ... \n", "3 3 No Amnesty is not a part of my offer. It is a ... \n", "4 4 Nancy Pelosi has behaved so irrationally &... \n", "\n", " vectors \n", "0 [-0.6935118436813354, -0.3402666747570038, 0.7... \n", "1 [-0.7567042708396912, -0.41789475083351135, 0.... \n", "2 [-0.7120085954666138, -0.3883921205997467, -0.... \n", "3 [-0.6233459115028381, -0.3593074679374695, -0.... \n", "4 [-0.6446494460105896, -0.32997167110443115, -0... " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "df = pd.read_csv(\"trump_bert.csv\")\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def load_tweets_into_matrix():\n", " X = []\n", " for x in df['vectors'].values:\n", " # note: this (use of `eval') is not great \n", " # practice; but did the trick\n", " X.append(np.array(eval(x)))\n", " return np.array(X)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "X = load_tweets_into_matrix()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(7995, 768)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Use $k$-means to cluster the tweets into `n_clusters` (you can use `sklearn`).\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([11, 19, 14, ..., 13, 16, 0], dtype=int32)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n_clusters = 20\n", "from sklearn.cluster import KMeans\n", "kmeans = KMeans(n_clusters=n_clusters, random_state=100).fit(X)\n", "cluster_assignments = kmeans.labels_\n", "cluster_assignments" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is helper to get indices associated with a given cluster (assuming access to a vector cluster assignments)." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def indices_for_cluster(cluster_assignments, k):\n", " ''' Return the indices associated with cluster k. \n", " Assumes cluster_assignments is a vector with dims \n", " equal to number of examples; entry j should give \n", " assignment (number) for tweet j.'''\n", " return np.where(cluster_assignments == k)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['RT @SenJohnThune: My statement on @POTUS’s proposal to end the shutdown: https://t.co/VCO1vwzaC3',\n", " 'A truly great First Lady who doesn’t get the credit she deserves! https://t.co/Wc9bYtoLKq',\n", " 'Deroy Murdock National Review: “We are now exporting oil which is the first time in my lifetime - we are right now the largest producer of oil and gas. This is not good if you’re Vladimir Putin where your chief export is oil. W.H. Agent - Not good for Kremlin.” @TuckerCarlson',\n", " 'The economy is doing great. More people working in U.S.A. today than at any time in our HISTORY. Media barely covers! @foxandfriends',\n", " 'RT @ChatByCC: Strong people stand up for themselves—but stronger people stand up for others.Thank you President @realDonaldTrump for stan…',\n", " 'With Murders up 33% in Mexico a record why wouldn’t any sane person want to build a Wall! Construction has started and will not stop until it is finished. @LouDobbs @foxandfriends',\n", " 'RT @TomFitton: Inside @JudicialWatch: @RealDonaldTrump is first president in a generation to talk honestly about the border crisis. https:…',\n", " 'William Barr is arriving at a Justice Department that desperately needs an infusion of credibility writes @KimStrassel https://t.co/naY9XOxb12 via @WSJ',\n", " 'A must read by @KimStrassel! https://t.co/Gfyrfpy55b',\n", " 'So great being with you both in the Oval Office! https://t.co/9VoIV3NahE',\n", " 'Everyone MUST watch the opening to @TuckerCarlson - A Classic! @foxnews',\n", " 'Very proud of perhaps the greatest golf course anywhere in the world. Also furthers U.K. relationship! https://t.co/3xTzzJH6Iq',\n", " 'RT @IvankaTrump: We have reached 6577623 pledged new career opportunities apprenticeships continuing education and on-the-job training…',\n", " 'RT @TomFitton: .@JudicialWatch exposed that Clinton operation and FBI paying Steele at the same time here: https://t.co/fICH35a59c https:/…',\n", " 'RT @IvankaTrump: Happy International Women’s Day! #IWD2019 #WGDP @USAID @WhiteHouse https://t.co/DOX6vGeCZd',\n", " 'This is just the beginning! https://t.co/PYwFGVGUxX',\n", " 'Will soon be 145 Judges! https://t.co/LoTbT4RFJj',\n", " 'RT @senatemajldr: H.R.1 is a blatant power grab to give Washington bureaucrats control over what American citizens can say about politics…',\n", " 'Mark Morgan Former Border Patrol Chief with great experience in Law Enforcement really understands the subjects of Immigration and the Border. Thank you Mark! @foxandfriends',\n", " 'Bring back @JudgeJeanine Pirro. The Radical Left Democrats working closely with their beloved partner the Fake News Media is using every trick in the book to SILENCE a majority of our Country. They have all out campaigns against @FoxNews hosts who are doing too well. Fox .....',\n", " 'RT @SaraCarterDC: POWELL: Andrew Weissmann\\xa0— The Kingpin Of Prosecutorial Misconduct — Leaves Mueller’s Squad | The Daily Caller https://t.…',\n", " 'RT @JackPosobiec: Why did CNN cut her off after she destroyed their Islamophobia hoax? https://t.co/zYepQbVqn8',\n", " 'Thank you @JesseBWatters could not have said it any better myself! https://t.co/HirL10zwZl',\n", " 'RT @WhiteHouse: Today there are plenty of reasons for that trust. Manufacturing jobs are roaring back. Blue-collar workers are set to make…',\n", " 'RT @keeperofthecup: Hanging out in the Roosevelt Room waiting to head into the oval office. #stanleycup @NHL @WhiteHouse @HockeyHallFame…',\n", " 'RT @ZacharyIvanPor1: @realDonaldTrump Thank you Mr. President🇺🇸 for all of your sacrifice your hard work and your thoughtful leadership.…',\n", " 'On my way to Grand Rapids Michigan right now. See you all very soon! #MAGA https://t.co/JjGAijXlRT',\n", " 'This has been an incredible couple of weeks for AMERICA! https://t.co/bqdB7DFx8P',\n", " 'A huge thanks to @HeatherNauert for serving America at the @StateDept. Great work! I’m proud to have you join the Fulbright board! https://t.co/oq0ZaA3MID',\n", " 'The First Step Act proves that our Country can achieve amazing breakthroughs when we put politics aside and put the interests of ALL Americans FIRST. https://t.co/dTKubkIBQn https://t.co/kILIFjXglO',\n", " 'RT @VP: The struggle in Venezuela is between dictatorship and democracy and freedom has the momentum. Nicolas Maduro is a dictator with no…',\n", " 'Will be speaking today at the Republican Jewish Coalition (@RJC) meeting in Las Vegas Nevada. See everyone soon! https://t.co/RvNBLMC2nI',\n", " 'A Fake Story by Politico. Made up sources. Thank you Mount Vernon! https://t.co/Pf60zBy6Sw',\n", " 'Love people who are great under pressure. What a fantastic life comeback for a really great guy! https://t.co/41MtJtYEjq',\n", " 'RT @WSJ: Opinion: Trump’s adversaries have spent more than two years trying to dodge accountability writes @kimstrassel https://t.co/NXW4k…',\n", " 'As I have been saying all along NO COLLUSION - NO OBSTRUCTION! https://t.co/BnMB5mvHAM',\n", " 'When there is not an underlying crime with regard to Collusion (in fact the whole thing was a made up fraud) it is difficult to say that someone is obstructing something. There was no underlying crime.” @marthamaccallum @FoxNews',\n", " 'The Washington Post and New York Times are in my opinion two of the most dishonest media outlets around. Truly the Enemy of the People! https://t.co/AG3vccsJvg',\n", " 'If @MittRomney spent the same energy fighting Barack Obama as he does fighting Donald Trump he could have won the race (maybe)! https://t.co/p5imhMJqS1',\n", " 'RT @seanhannity: Prior Reporting Confirmed That Some FBI Agents Were FED UP With Comey https://t.co/xKVZMVnOQI',\n", " 'So true - thanks @SteveHiltonx @NextRevFNC! https://t.co/2UK8RgzRQL',\n", " 'Thank you @MarkLevinShow! #MAGA https://t.co/kff84hFgKP',\n", " 'RT @realDonaldTrump: How do you impeach a Republican President for a crime that was committed by the Democrats? MAKE AMERICA GREAT AGAIN!',\n", " 'RT @DevinNunes: Byron York: For some Dems breaking up with dossier is hard to do \\u2066@ByronYork\\u2069 https://t.co/aVdNgcGv4m',\n", " 'RT @DevinNunes: Victor Davis Hanson: Mueller Probe Could Backfire on Those Who Fabricated Russia-Collusion Narrative - YouTube https://t.co…',\n", " 'THANK YOU @NRA! #NRAAM https://t.co/SWkpe1eFhT',\n", " 'RT @ro18007212: @dbongino I have fire fighter friends and they support Trump.',\n", " 'RT @jcoreybates: @dbongino 👈🏼 This career firefighter will not be voting for any Democrat on the ticket. I will be voting for @POTUS again.',\n", " 'RT @Daniel4SCBoone: @dbongino I bet if someone did a fireman’s poll President Trump would win by a landslide.',\n", " \"RT @JCryptoseed: @dbongino Never Supporting a Fireman's Ball again...\",\n", " 'RT @RealDanKida: @dbongino The Unions have become Corporations representing themselves Our President represents the people. #MAGA @realDon…',\n", " 'I am continuing to monitor the situation in Venezuela very closely. The United States stands with the People of Venezuela and their Freedom! https://t.co/rtGfjQjc1u',\n", " 'As we unite on this day of prayer we renew our resolve to protect communities of faith – and ensure that ALL of our people can live pray and worship IN PEACE. #NationalDayOfPrayer https://t.co/1a7zphaE6z',\n", " 'RT @WhiteHouse: President @realDonaldTrump is fixing American trade to bring our steel and manufacturing jobs back HOME!https://t.co/PjD6…',\n", " 'As the great people of IA IL & MO continue to confront the devastating flooding know we are here for you and ready to help! My team remains in close contact with @IAGovernor @GovParsonMO @GovPritzker and the local officials managing the impacts of the destructive flooding.',\n", " 'Mike has been a fantastic Senator! https://t.co/WKSAfbeARz',\n", " 'RT @DailyCaller: Trump Cuts Off States From Skimming Medicaid Payments For Big Labor https://t.co/nWI8A8tomB',\n", " 'RT @DailyCaller: DOJ Asks Courts To Lighten Up On Qualcomm As It Battles China For 5G Supremacy https://t.co/6CEMpAwJZF',\n", " 'RT @TeamTrump: BIG NEWS: Nearly HALF of @realdonaldtrump’s 2020 campaign contributions this year have come from WOMEN donors.#WomenForTru…',\n", " 'Big crowds in Panama City Beach Florida. See everyone in 30 minutes! @FoxNews @TuckerCarlson @SeanHannity https://t.co/57tngL1W2i',\n", " '“We have been engaged in an unfair relationship with China for a long time. They have reneged on the commitments they made to the WTO particularly around intellectual property.” Carly Fiorina @MariaBartiromo',\n", " 'RT @TomFitton: FBI Official: Barack Obama\\'s White House Was A \"Repository\" For Hillary Clinton\\'s Emails - @JudicialWatch https://t.co/8bONh…',\n", " \"RT @kimguilfoyle: Nolte: Trump's Job Approval Booms to Highest Mark Since Inauguration https://t.co/QtySKQ9OrP via @BreitbartNews\",\n", " 'RT @GOP: “This is crazy... China not being a threat? [Biden is] so out of touch.” -@kayleighmcenany https://t.co/wlpYxS7wTS',\n", " 'I met Marine Sgt. John Peck a quadruple amputee who has received a double arm transplant at Walter Reed in 2017. Today it was my honor to welcome John (HERO) to the Oval with his wonderful wife Jessica. He also wrote a book that I highly recommend “Rebuilding Sergeant Peck.” https://t.co/eiNnHcEU7x',\n", " \"RT @WhiteHouse: “America’s last major overhaul of our legal admissions policy was 54 YEARS ago. Think of that. So a major update and that'…\",\n", " '.@BilldeBlasio is the worst Mayor in the history of New York City - he won’t last long! https://t.co/NyYntsX573',\n", " 'New Fox Poll: 58% of people say that the FBI broke the law in investigating Donald J. Trump. @foxandfriends',\n", " 'The Mainstream Media hates to cover this! https://t.co/EMhAVWCjVf',\n", " 'See you tonight at 7:00 P.M. Eastern Montoursville Pennsylvania! #MAGA https://t.co/Ij2AjXfRZa',\n", " 'RT @realDonaldTrump: Megan King who is running for Superior Court Judge in the Pennsylvania election has my Full and Total Endorsement. S…',\n", " 'RT @realDonaldTrump: Fred Keller of the Great State of Pennsylvania has been an outstanding State Representative. Now he is running as the…',\n", " 'I want to welcome you all to the @WhiteHouse as we award our very bravest law enforcement officers and firefighters our nation’s highest public safety award – The Medal of Valor...https://t.co/68EeQk8ZHr',\n", " 'We will never forget our fallen HEROES. It was our great honor to be with you today! #FlagsIn https://t.co/Z6OvQUr8lT',\n", " 'RT @AviBerkow: Congrats \\u2066@IvankaTrump\\u2069 on receiving the Internet Association’s 2019 Internet Freedom Award this evening. https://t.co/dE6Zh…',\n", " '71% of Voters rate the Economy as Excellent or Good. The highest number in more than 18 years! @QuinnipiacPoll',\n", " 'Thank you @JPN_PMO @AbeShinzo! #POTUSinJapan🇺🇸🇯🇵 https://t.co/fWToB1XotG',\n", " '.@GovMikeDeWine just updated me on the devastation from the many tornadoes that struck Ohio early this morning. My Administration fully supports the people of the great State of Ohio as they begin the cleanup and recovery.',\n", " 'Emmet Flood who came to the White House to help me with the Mueller Report will be leaving service on June 14th. He has done an outstanding job – NO COLLUSION - NO OBSTRUCTION! Case Closed! Emmet is my friend and I thank him for the GREAT JOB he has done.',\n", " \"RT @DavidBrodyCBN: Trump's approval rating hits highest point in two years https://t.co/TT09Ovd5r8\",\n", " 'THE TRUTH! The Witch Hunt is dead. Thank you @marcthiessen. https://t.co/myKaSEnbs7',\n", " 'RT @RoyalFamily: The President and The Prince of Wales inspect a Guard of Honour formed by Nijmegen Company Grenadier Guards. #USStateVisi…',\n", " 'RT @RoyalFamily: The Queen President Trump and the First Lady view a display of items from the Royal Collection illustrating the enduring…',\n", " 'Thank you @Theresa_May!🇺🇸🇬🇧 https://t.co/zFJj47UuHO',\n", " '.@FLOTUS Melania and I send our deepest condolences to President Reuven Rivlin and the entire State of Israel upon the passing of Mrs. Nechama Rivlin. Mrs. Rivlin represented her beloved country with grace and stature. We will miss her along with all those who knew her.',\n", " 'RT @IngrahamAngle: For my full interview with \\u2066@realDonaldTrump from Normandy\\u2069 tune in tonight #IngrahamAngle \\u2066@FoxNews\\u2069 10pET https://t.c…',\n", " 'RT @realDonaldTrump: MEXICO HAS AGREED TO IMMEDIATELY BEGIN BUYING LARGE QUANTITIES OF AGRICULTURAL PRODUCT FROM OUR GREAT PATRIOT FARMERS!',\n", " 'RT @larryelder: The Trump-hating media/dems now face a YUGE dilemma--how NOT to give @realDonaldTrump credit.#MexicoCavesAfterTariffThrea…',\n", " 'New book just out “The Real Deal My Decade Fighting Battles and Winning Wars With Trump” is really wonderful. It is written by two people who are very smart & know me well George Sorial & Damian Bates as opposed to all the books where the author has no clue who I am. ENJOY!',\n", " 'RT @bopinion: European landmarks have a question they desperately need answering: How do you stop the tourists from coming? https://t.co/7R…',\n", " 'Michael Whatley has been with us right from the beginning. A great Leader and @NCGOP Chairman! https://t.co/XQvnK9LD8R',\n", " 'Our Farmers deserve this they are GREAT! https://t.co/0dFkx0vUkl',\n", " 'RT @FLOTUS: This Administration remains committed to the fight against the opioid epidemic. Thank you to all who participated in this week’…',\n", " '“The latest Polls find 51% of Americans approve of President Trump’s Job Performance. Last month a Democrat Pollster said President Trump’s approval rating has been the most steady of any President in history!” @OANN',\n", " 'He is a national disgrace who is destroying the City of London! https://t.co/l3qcUS17jh',\n", " 'Thank you PM @Netanyahu and the State of Israel for this great honor!🇺🇸🇮🇱 https://t.co/OUcf6s98UX',\n", " 'So nice! https://t.co/oraaFoPByj',\n", " 'One size doesn’t fit all - I support West Virginia Schools. Keep up the great work @WVGovernor Big Jim Justice - I am with you! https://t.co/EomFLcBjlz',\n", " 'On no issue are Democrats more extreme – and more depraved – than when it comes to Border Security. The Democrat Agenda of open borders is morally reprehensible. It is the great betrayal of the American Middle Class and our Country as a whole! #Trump2020 https://t.co/f9RJhpp50J',\n", " 'It was my great honor to host Canadian Prime Minister @JustinTrudeau at the @WhiteHouse today!🇺🇸🇨🇦 https://t.co/orlejZ9FFs',\n", " 'RT @GOP: Under @realDonaldTrump’s leadership Florida is THRIVING! Read more from Pam Bondi— former AG of Florida⬇️https://t.co/pLNpaO4…',\n", " 'RT @EricTrump: This isn’t a campaign this is a movement! Thank you Orlando - we love you! #Florida #KeepAmericaGreat 🇺🇸🇺🇸🇺🇸 https://t.co/M…',\n", " 'RT @EricTrump: The crowds and the spirit outside the Amway Center waiting for @realDonaldTrump is absolutely incredible! #Orlando #2020 #Ma…',\n", " 'RT @JudicialWatch: Hillary Clinton is not above the law yet she has a record of contempt for the rule of law. Our leaders are bound by the…',\n", " 'Just departed for the #G20 Summit in Osaka Japan!🇺🇸🇯🇵 https://t.co/IdAYUOiWqf',\n", " 'Thank you @MSNBC real professionals! @chucktodd @maddow https://t.co/7ZCkcUQ4yA',\n", " 'Thank you #G20OsakaSummit https://t.co/9FCqSuR5Bp',\n", " '....In the meantime our teams will be meeting to work on some solutions to very long term and persistent problems. No rush but I am sure we will ultimately get there!',\n", " 'Thanks Ari! https://t.co/WOOzufbzOL',\n", " 'RT @PressSec: Incredible to see all in attendance to hear our @POTUS speak & celebrate our great nation’s Independence Day! 🇺🇸 https://t.co…',\n", " 'Our Country is the envy of the World. Thank you Mr. President! https://t.co/2h8mvu16YX',\n", " 'A massive crowd that Fake News & some Dems didn’t want to Report! https://t.co/RiRTP2hEJc',\n", " 'After a wonderful dinner at the @USTreasury last night with the Amir of Qatar @TamimBinHamad it was my great honor to welcome him to the @WhiteHouse this afternoon! https://t.co/SB9DGA7dgo',\n", " 'The Dems Witch Hunt continues! https://t.co/jHEPN84IGK',\n", " 'Democrats had to quickly take down a tweet called “Kids In Cages Inhumane Treatment at the Border” because the horrible picture used was from the Obama years. Very embarrassing! @foxandfriends',\n", " \"RT @USCG: Thank you to @POTUS and all who came out yesterday to our Nation's Capital #IndependenceDay celebration. Happy 243rd Birthday Ame…\",\n", " 'RT @IvankaTrump: #WGDP is proud to work w/ @USAID to advance women’s economic empowerment. Thank you @USAIDMarkGreen for your commitment to…',\n", " 'RT @DonaldJTrumpJr: My latest OpEd read and RT🇺🇸Donald Trump will win the Democratic Party civil war | TheHill https://t.co/NhftUC975e',\n", " 'RT @JudicialWatch: Hillary Clinton is not above the law yet she has a record of contempt for the rule of law. Our leaders are bound by the…',\n", " 'RT @usminority: Thank you to @realDonaldTrump for your incredible acknowledgment & support of #WalkAway back in October. #WalkAway turns 1…',\n", " 'RT @Jbrc4E: @usminority Thank you for loving America.',\n", " 'If you come after the President the Country the Flag - he’s going to defend himself. What the squad doesn’t like is that Donald Trump is enforcing the very laws that are on the books that were put there by Congress.” Jason Chaffetz. Also buy Jason’s great new book POWER GRAB!',\n", " 'See you tonight North Carolina! #MAGA2020 https://t.co/rqOwEkTtqQ',\n", " 'THANK YOU Greenville North Carolina! #MAGA2020 https://t.co/3ou3JzHsQX',\n", " 'RT @realDonaldTrump: Think what it would be without the 3 year Witch Hunt and Fake News Media in partnership with the Democrats! https://t…',\n", " 'As you can see I did nothing to lead people on nor was I particularly happy with their chant. Just a very big and patriotic crowd. They love the USA! https://t.co/6IVKEffNnq',\n", " 'You can add 10% or 15% to this number. Economy doing better than EVER before! https://t.co/o59vI5tzXn',\n", " 'RT @GOP: “Women’s issues are American issues.” -@LaraLeaTrump https://t.co/ha9DhzTakM',\n", " 'TRUTH IS A FORCE OF NATURE!',\n", " 'THE WITCH HUNT IS OVER! @SeanHannity https://t.co/OUoIm4onJt',\n", " 'Mark Levin will be on @foxandfriends now! Great guy.',\n", " 'Mark Levin on @foxandfriends now! Great guy.',\n", " 'RT @IvankaTrump: Today is the 1-year anniversary of our #PledgetoAmericasWorkers!!!We have reached 12 MILLION (!!!!) commitments to trai…',\n", " 'Thanks @JudgeJeanine! https://t.co/chj7JPbWo1',\n", " 'The real Collusion the Conspiracy the Crime was between the Clinton Campaign the DNC Fusion GPS Christopher Steele.....(and many others including Comey McCabe Lisa Page and her lover Ohr and his wonderful wife and on and on!). @replouiegohmert',\n", " 'It is the 25th Anniversary of a GREAT Organization run by people who truly love our Country @JudicialWatch. On behalf of all Americans I thank them! @TomFitton https://t.co/aXv47spgjS',\n", " 'Beautiful evening in Cincinnati Ohio tonight — with GREAT American Patriots! #KAG2020 https://t.co/wDN5B4Gp87',\n", " \"RT @cvpayne: While the media is fixated on tweets and fear mongering here's are some employment stats for Black American in July.284000 r…\",\n", " 'RT @ChatByCC: Strong people stand up for themselves—but stronger people stand up for others.Thank you President @realDonaldTrump for stan…',\n", " 'Check out what @Google is up to for the 2020 election! #KAG2020 https://t.co/roM2WNmUSP',\n", " 'RT @senatemajldr: As we commemorate #DDay75 let us give thanks for the valiant Allied soldiers who helped turn the tide of the Second Worl…',\n", " 'We love you Dayton Ohio! https://t.co/IaCZAdyuzL',\n", " 'The people I met today in Dayton are the finest anywhere! https://t.co/sBxKZWExcR',\n", " 'My time spent in Dayton and El Paso with some of the greatest people on earth. Thank you for a job well done! https://t.co/TNVDGhxOpo',\n", " 'RT @TrumpWarRoom: Joe Biden: “Poor kids are just as bright and just as talented as white kids.” https://t.co/YhDSMnoRce',\n", " 'Thank you John you are a special guy! https://t.co/yAtCFcNeDL',\n", " 'Put it back up. We are living with a Rigged & Fake Media! https://t.co/ZhanbGCxuX',\n", " 'RT @WhiteHouse: The Trump Economy is delivering incredible results for the blue-collar workers who need it most. In case you missed it: h…',\n", " \"RT @Lrihendry: Democrats also boycotted Lincoln's inauguration bc he had this radical idea of ending slavery. Let that sink in. #TrumpInaug…\",\n", " 'RT @WhiteHouse: In September 2018 the unemployment rate in New Hampshire reached its LOWEST POINT since 1988 at 2.4—and remained there for…',\n", " 'A great evening with incredible people in New Hampshire! https://t.co/XvqQCgorIW',\n", " 'RT @TopDogB24: @CLewandowski_ @realDonaldTrump the best President in history!',\n", " 'RT @thebradfordfile: America --Get ready for a campaign the likes of which has never been seen in American history. President @realDona…',\n", " 'Thank you @TedCruz I couldn’t agree more! https://t.co/MGq0xXin0s',\n", " 'RT @RealOmarNavarro: I love @realDonaldTrump. He’s the only President in my lifetime who stands for our country.',\n", " 'I promise not to do this to Greenland! https://t.co/03DdyVU6HA',\n", " 'The Fake and Corrupt Media is sooo bad for our Country The Enemy of the People! https://t.co/GPiklem0u1',\n", " 'RT @WhiteHouse: Wall construction is underway near Otay Mesa California! 👷 https://t.co/45C0tu3WxT',\n", " 'On my way to the Great Commonwealth of Kentucky to deliver remarks at the @AMVETSHQ 75th Annual National Convention. Look forward to being with all of my friends! #AMVETS75th https://t.co/088PYGlFnu',\n", " '.@NATO very unfair to the United States! https://t.co/YIgmTkpScU',\n", " 'Check out a FANTASTIC new book “STILL WINNING – Why America Went All In On Donald Trump-And Why We Must Do It Again” by the great writer @CharlesHurt. An excellent read. Thank you!',\n", " 'RT @MariaBartiromo: Another informant the FBI decided to turn on. Unbelievable. \\u2066@MorningsMaria\\u2069 \\u2066@FoxBusiness\\u2069 Former Overstock CE…',\n", " 'RT @WhiteHouse: Because of you America is safe. Because of you America is strong. Because of you America is free. And because of y…',\n", " 'RT @SaraCarterDC: Talking about the BREAKING release of Bruce Ohr 302s tonight on @seanhannity with @Jim_Jordan and @jsolomonReports https:…',\n", " 'RT @MZHemingway: The Democratic Party Is Becoming Unsalvageable – Tablet Magazine https://t.co/JMjMZOPZLp',\n", " 'RT @USAmbIsrael: Please read my attached statement with regard to the decision of the Government of Israel to deny entry to BDS activists…',\n", " 'This despite the Fake News and Polls! https://t.co/DksmF8hTr7',\n", " 'USMCA make it bipartisan. Everybody wants it! https://t.co/lloDwZr4iN',\n", " 'Just wrapped up a great meeting with my friend Prime Minister @NarendraModi of India at the #G7Summit in Biarritz France! https://t.co/q0NOnEcjFO',\n", " 'RT @KellyannePolls: Messy. John Kerry’s son cut business ties with Hunter Biden over Ukrainian oil deal https://t.co/HQGYWOrD8q',\n", " 'A made up Radical Left Story about Doral bedbugs but Bret Stephens is loaded up with them! Been calling me wrong for years along with the few remaining Never Trumpers - All Losers! https://t.co/KlzzMC40Vt',\n", " 'RT @NOAASatellites: Watch as the eye of #HurricaneDorian2019 begins to form in this 1-minute visible loop from NOAA\\'s #GOESEast. \"Dangerous…',\n", " 'Thanks @RepDougCollins - TRUE! https://t.co/o49tPKdWct',\n", " 'I am monitoring Hurricane Dorian and receiving frequent briefings and updates. It is important to heed the directions of your State and Local Officials. This is an extremely dangerous storm please prepare and be safe! @FEMA @NWS @NOAA @Readygov @FLSERT https://t.co/Fee9EB1wQk',\n", " 'RT @SenatorTimScott: A very happy birthday to the United States Marine Corps Reserve! We are truly honored to have such outstanding men and…',\n", " 'RT @SenateGOP: On this day 99 years ago the 19th Amendment was adopted to our Constitution securing for women the right to vote. Today…',\n", " 'RT @senrobportman: Today I saw firsthand the critical and innovative research and ground tests for the international space community being…',\n", " 'RT @realDonaldTrump: The Great State of North Carolina has EARLY VOTING for a very important Congressional (Ninth) race. Please vote early…',\n", " 'RT @NHC_Atlantic: Here are the 5 AM EDT Saturday August 31 Key Messages for Hurricane #Dorian. A prolonged period of storm surge and hurr…',\n", " 'Enjoy the low gas prices over the Labor Day weekend! My energy policies have made America energy independent while keeping prices low just like a Tax Cut. The Democrats “green” policies will raise your price of gas! https://t.co/iBS1UQul7A',\n", " '“The vindication belongs to the President for firing James Comey. It was clearly the right thing to do. You don’t want an FBI Director with Jim Comey’s ethics.” Jason Riley Wall Street Journal',\n", " 'This is only the beginning! https://t.co/mFrtBPtCcO',\n", " 'RT @GovRonDeSantis: Thank you @USACEHQ. Our administration continues to work around the clock with all of our federal and local partners…',\n", " 'RT @KTLA: Rescue operation underway near Santa Cruz Island involving at least 30 people on a 75-foot boat per @USCGLosAngeleshttps://t.co…',\n", " 'RT @53rdWRS: Our aircrew has just landed from another mission into hurricane #Dorian! Here they are rolling in.🇺🇸 ✈️⛈🌪🌊 #ReserveCitizenA…',\n", " 'RT @realDonaldTrump: The Great State of North Carolina has EARLY VOTING for a very important Congressional (Ninth) race. Please vote early…',\n", " 'RT @NHC_Atlantic: Here are the 11 am EDT key messages on Hurricane #Dorian. The latest full advisory is always available at https://t.co/t…',\n", " 'Great interview of Sarah Sanders by @foxandfriends. She is a terrific person with a great future!',\n", " 'The Washington Post’s @PhilipRucker (Mr. Off the Record) & @AshleyRParker two nasty lightweight reporters shouldn’t even be allowed on the grounds of the White House because their reporting is so DISGUSTING & FAKE. Also add the appointment of MANY Federal Judges this Summer! https://t.co/7d33tzKxXq',\n", " 'Congratulations to @JudgeJeanine Pirro on having again the Number One Best Selling Book!',\n", " 'To every one of the HEROES we recognized today — THANK YOU and God Bless You All! https://t.co/JWKwylpdiO',\n", " 'Received an update on Air Force One at MCAS Cherry Point in North Carolina regarding damage caused by Hurricane Dorian. https://t.co/ogQRJ3iLmr',\n", " 'RT @Scavino45: 🚨Happening Now—@POTUS @realDonaldTrump departing the @WhiteHouse for North Carolina.... https://t.co/HtreybGIAc',\n", " 'The Wall is going up very fast despite total Obstruction by Democrats in Congress and elsewhere! https://t.co/2nFIEFppho',\n", " 'RT @realDonaldTrump: The two big Congressional wins in North Carolina on Tuesday Dan Bishop and Greg Murphy have reverberated all over th…',\n", " 'All based on NOTHING! The Dems can’t get anything positive done and probably don’t want to. https://t.co/FuWI3XP6jm',\n", " 'This afternoon at the @WhiteHouse it was my great honor to present our nation’s highest civilian honor the Presidential Medal of Freedom to American baseball legend @MarianoRivera. Congratulations on this extraordinary achievement Mo! https://t.co/nzOeqFNb3C',\n", " 'One my way to New Mexico — see you all shortly at the @StarCenter! #KAG2020 https://t.co/cW7EK6V229',\n", " 'If you want to stop the drug smugglers human traffickers and vicious MS-13 gang members from threatening our communities and poisoning our youth you have only one choice — you must elect more REPUBLICANS! #KAG2020 https://t.co/L4neBV2SEo',\n", " 'As Corey Lewandowski stated very clearly yesterday in front of the House Judiciary Committee President Trump didn’t do anything wrong or illegal. But they all know that. The Democrats are hurting our Country and getting nothing done. Shameful! @CLewandowski_ @foxandfriends',\n", " 'RT @IngrahamAngle: Totally agree—a sign of weakness would be a trigger-happy reaction to the drone strike. @realDonaldTrump’s right. https…',\n", " 'RT @RepMarkMeadows: Twitter friends: give a follow to the newest conservative member of Congress from North Carolina: @RepGregMurphy!',\n", " 'RT @MariaBartiromo: https://t.co/RC7kZDCN1i some sanity from @RepDougCollins @MorningsMaria @FoxBusiness',\n", " 'IIhan Omar a member of AOC Plus 3 will win us the Great State of Minnesota. The new face of the Democrat Party! https://t.co/aQFEygSa4D',\n", " \"RT @SteveHiltonx: 'when President Trump took office 1.9m more unemployed than job openings''now: 1.2m more job openings than unemployed'…\",\n", " 'RT @WhiteHouse: Our history is filled with the stories of courageous men and women who went beyond the call of duty to protect and defend.…',\n", " 'This is the real and only story! https://t.co/4z8eOcm6PA',\n", " 'The USA Loves India! https://t.co/xlfnWafxpg',\n", " 'Thank you @JennaEllisRives -- totally agree! https://t.co/n3GDdAHLWh',\n", " 'Thank you @LouDobbs and @JudgeJeanine! https://t.co/LdfGFvAJNF',\n", " 'RT @DonaldJTrumpJr: Are you saying the Democrats started an all out move towards impeachment without even seeing the transcript? https://t.…',\n", " 'RT @DonaldJTrumpJr: KASSAM: Trump Transcript Shows Him Trying To Stop Corruption Nothing Else https://t.co/nEgLq8pITV via @dailycaller',\n", " 'Will be a GREAT and very accurate show tonight by @seanhannity on @foxnews (9:00 PM). Will play my full statement from Air Force One!',\n", " 'They are trying to stop ME because I am fighting for YOU! https://t.co/xiw4jtjkNl',\n", " 'RT @RNCResearch: Sen. Scott slams Democrats on impeachment: “the evidence does not matter” to Democratshttps://t.co/j8H1ZJBpX5 https://t.c…',\n", " 'RT @RNCResearch: Sen. Cruz: Congressional Dems “are angry about the 2016 election…angry at the voters”https://t.co/fwMnnRl9pO https://t.co…',\n", " 'RT @RNCResearch: NH voter slams Dems on impeachment: “Should just get back to doing their job”https://t.co/5bv3IKRaN0 https://t.co/8AKlzGV…',\n", " 'RT @RNCResearch: Rep. Turner calls out Adam Schiff for just making up “fiction” conversationhttps://t.co/vvEDqbX8e7 https://t.co/SPIxLgKHXz',\n", " '....If the Democrats are successful in removing the President from office (which they will never be) it will cause a Civil War like fracture in this Nation from which our Country will never heal.” Pastor Robert Jeffress @FoxNews',\n", " 'It was my Great Honor to attend this mornings Welcome Ceremony for the 20th Chairman of the Joint Chiefs of Staff General Mark Milley! https://t.co/CXoDPnimgz',\n", " 'BIG NEWS by @Hyundai @Kia and @Aptiv on a 4 BILLION DOLLAR joint venture to develop autonomous driving technologies in the USA. That’s a lot of $$ and JOBS! Great jobs coming back to America!!',\n", " 'Book is doing really well. A study in unfairness to a potentially great Justice! https://t.co/i6GwghuEsU',\n", " 'Great time at The Villages in Florida today. Sorry we couldn’t get everybody in. I will be back soon! https://t.co/ia87A0sEue',\n", " 'Thank you @JennaEllisRives really well done! https://t.co/N2VsQ8y0rb',\n", " '...blowing MASSIVE holes inside of the theory the narrative that Chairman Schiff has been providing to the public. @RepLeeZeldin https://t.co/CUJhiKZfgr',\n", " 'RT @JesseBWatters: “Just because Joe Biden is running against President @realdonaldtrump doesn’t mean he’s above the law.” #TheFive https:/…',\n", " 'The Do Nothing Democrats don’t have time to get it done! https://t.co/2cwyMtT3Gu',\n", " 'RT @GreggJarrett: It seems as if Congressman Schiff has fabricated so many stories that he cannot remember his part of the newest script...…',\n", " 'No Kevin Jeff Flake is better! https://t.co/IyENBffEjp',\n", " 'RT @JohnCornyn: San Francisco made a choice to tolerate vagrancy and encourage drug use. It made the problems worse writes @HMDatMi https:…',\n", " 'The Do Nothing Democrats are being exposed! https://t.co/Z5G5oEQOqs',\n", " 'Thank you @HeyTammyBruce! https://t.co/WYtJQmWv26',\n", " \"RT @KimStrassel: Kimberley Strassel on Dems' 'mystifying' impeachment push: Americans will see the 'double standard' https://t.co/aAYlcTcY1…\",\n", " 'Adam should be Impeached! https://t.co/q7YRUWsJxy',\n", " 'RT @CLewandowski_: Great to be on with @LouDobbs reminding the American people of the Promises Made Promises Kept by @realDonaldTrump http…',\n", " '.....good health at my request Pastor Brunson who had many years of a long prison term remaining. Also remember and importantly that Turkey is an important member in good standing of NATO. He is coming to the U.S. as my guest on November 13th. #ENDENDLESSWARS',\n", " 'The U.S. Border is SECURE! https://t.co/h9EPUPL1uS',\n", " 'He should be Impeached for Fraud! https://t.co/lu3xKFQaON',\n", " 'They don’t have a clue but I do. The USA is doing great despite the Fed! https://t.co/85aW2YGehY',\n", " 'The hardest thing I have to do as President... https://t.co/6bzwh78I00',\n", " 'WOW THANK YOU Minneapolis Minnesota — on my way! #KAG2020 https://t.co/Czl6GbCCxN',\n", " 'RT @MariaBartiromo: USMCA passage China deal should be ‘a one-two punch’: Rep. Tom Reed https://t.co/WcBsEjjir3 @MorningsMaria @FoxBusiness',\n", " 'The Do Nothing Democrats. Thanks Vicky! https://t.co/WEZgrvobs3',\n", " 'RT @IvankaTrump: We are striving to ensure all hard-working Americans have access to high-quality affordable childcare. Thank you \\u2066@GovPa…',\n", " 'We love you @MinneapolisPD THANK YOU! #LESM https://t.co/fkOL8dCNP2',\n", " 'LOUISIANA — Tomorrow you will head to the polls and VOTE to REPLACE Liberal Democrat John Bel Edwards with a great new REPUBLICAN Governor! Get out and vote for either @DocAbraham or @EddieRispone (BOTH GREAT)! https://t.co/Qyu6z9nZXr',\n", " '“Serial killers get more Due Process than the Democrats give to the President of the United States.” @marklevinshow',\n", " 'The Democrat Party has hijacked the House of Representatives... @MarkLevinShow https://t.co/SZhfmhzec2',\n", " \"It doesn't speak for the FULL HOUSE because the FULL HOUSE hasn't spoken. The Democrat Party is pushing this Impeachment. This is a Democrat Party Impeachment as I have been saying a silent COUP effort. @MarkLevinShow https://t.co/sA9EgI2yBL\",\n", " 'The House gone rogue! I want to remind you a little bit about the ring leader in this whole rogue operation against the President of the United States... @MarkLevinShow https://t.co/EkXsaR9GPh',\n", " 'RT @CLewandowski_: Great new book just released by \\u2066@RandPaul\\u2069. The Case Against Socialism - Rand Paul - Hardcover. Pick up your copy today…',\n", " 'Do you think they like me? https://t.co/TDmUnJ8HtF',\n", " 'This is the real story. Thank you Jim! https://t.co/VqJrsUJdiX',\n", " 'My warmest condolences to the family and many friends of Congressman Elijah Cummings. I got to see first hand the strength passion and wisdom of this highly respected political leader. His work and voice on so many fronts will be very hard if not impossible to replace!',\n", " 'RT @SarahAMatthews1: Dallas Texas crowd is getting ready for @realDonaldTrump with a little YMCA ‼️ https://t.co/9muhNZqGvZ',\n", " 'Thank you Dallas Texas - I love you! #TrumpRallyDallas #KAG2020 https://t.co/meWpesDYeM',\n", " 'RT @badluck_jones: Free Beacon Reminds Us of Lefty Double Standard Between Brewer Pelosi Finger Wags https://t.co/R7c5kPzk6m',\n", " '“I don’t see anything that constitutes an Impeachable offense - Nothing here rises to the level of Impeachment. The Democrats are making a mistake with this secrecy.” Kenn Starr former Special Prosecutor',\n", " 'RT @GOPChairwoman: “The people of this country know what the Dems are doing. They’re tired of it.” - @PressSec https://t.co/PbXGSD8Cpu',\n", " 'RT @GOPChairwoman: Everything is bigger in Texas – even a @realDonaldTrump rally! Awesome crowd!https://t.co/rj15fMyHyF',\n", " 'It is ONLY about this! https://t.co/ZB5xPDKs4b',\n", " 'Adam Schiff is a Corrupt Politician! https://t.co/16aSrqjwu2',\n", " 'RT @RepAnnWagner: As a cosponsor of the resolution to censure Rep. Adam Schiff I was disappointed Nancy Pelosi did not even allow a vote o…',\n", " 'RT @JuddPDeere45: .@RepKevinBrady @virginiafoxx & @repgregwalden: \"We can lower drug prices for seniors workers and families to help th…',\n", " 'It was my great honor to deliver the keynote address at the 2019 Second Step Presidential Justice Forum hosted by the 20/20 Bipartisan Justice Center in South Carolina and my true honor to receive the Bipartisan Justice Award thank you! https://t.co/uF9IWnI1pH',\n", " 'I appreciate the support of Senator @LindseyGraham @SenateMajLdr Mitch McConnell and their Great Senate Republican colleagues on the resolution condemning the Do Nothing Democrats for their Witch Hunt Impeachment inquiry behind closed doors....',\n", " 'RT @marklevinshow: My appearance on Hannity last nighthttps://t.co/whO7qmrkB7',\n", " 'RT @CNNPolitics: JUST IN: Trump administration suspends US commercial flights to 9 destinations in Cuba except for Havana https://t.co/KPPQ…',\n", " '...Thank you @foxandfriends! Hopefully this is just the beginning of a massive story of injustice and treason. You will never learn this from the corrupt LameStream Media who get Pulitzer Prizes for reporting the story totally wrong. The ones who report it right get only RESPECT!',\n", " '....Our Republican candidate @EddieRispone is a successful conservative businessman who will stand with me to create jobs and protect your Second Amendment. GET OUT AND VOTE for Eddie the next Governor of the GREAT State of Louisiana!',\n", " 'As Diwali commences @FLOTUS Melania and I wish those observing the Festival of Lights a blessed and happy celebration! #HappyDiwali https://t.co/LGXkUzMJiI',\n", " 'RT @WhiteHouse: Thank you to the service members military leaders and agency officials who were critical to the success of this mission.…',\n", " \"RT @StateDept: Last night the United States brought the world's number one terrorist leader to justice. President @realDonaldTrump address…\",\n", " 'So nice thank you! https://t.co/UjgDeHSK7C',\n", " 'The only crimes in the Impeachment Hoax were committed by Shifty Adam Schiff when he totally made up my phone conversation with the Ukrainian President and read it to Congress together with numerous others on Shifty’s side. Schiff should be Impeached and worse!',\n", " 'RT @DevinNunes: Congratulations to \\u2066@LeeSmithDC\\u2069 on his new book “The Plot Against The President” \\u2066@foxandfriends\\u2069 https://t.co/7iRZeDmuDw',\n", " 'We will be having a big rally for Governor @MattBevin on Monday night in Kentucky. Get your tickets today! https://t.co/uoPhCLGHpH',\n", " 'The Democrats have been on this path for 3 years. The first headline I saw...before the President was sworn in was that the Impeachment process was beginning...so this is just further evidence that this is what they had in mind from the very beginning. @senatemajldr https://t.co/scFWSh47Bq',\n", " 'The Do Nothing Democrats have gone Crazy. Very bad for USA! https://t.co/3zApgOOA7I',\n", " '.....to any President of either party again. Laura @IngrahamAngle',\n", " 'Thank you Matt. https://t.co/vDZqYIrgBy',\n", " \"RT @AriFleischer: Joe Biden Repeatedly Asked Agencies To Do What Son's Clients Wanted https://t.co/J96lmY8xcv\",\n", " 'RT @IngrahamAngle: Heroin addict drags NYPD cop with his car — and wins $11 million in court https://t.co/jWsRXdljBj via @nypmetro',\n", " 'The home of Nancy Pelosi. I can’t believe her voters can be happy with the job she and the Do Nothing Democrats are doing! San Francisco has really gone down hill. So sad! https://t.co/z0Tms6gkDy',\n", " 'But the Crooked Democrats don’t want people to know this! Thank you to Tim Morrison for your honesty. https://t.co/1AxrArFJ6c',\n", " '....Our Republican candidate @EddieRispone is a successful conservative businessman who will stand with me to create jobs and protect your Second Amendment. GET OUT AND VOTE for Eddie the next Governor of the GREAT State of Louisiana!',\n", " 'RT @1k_kilgore: Someone feeling a bit left out? https://t.co/VDsy93Blft',\n", " 'RT @EricTrump: At #UFC244 - chanting “Donald Trump Donald Trump... USA USA” https://t.co/hiqKCw3cS9',\n", " '....Matt has been a GREAT Governor. Kentucky (I Love You!) please be sure to vote for Matt Bevin on TUESDAY. Matt will never let you down and we have to send a strong signal to Nancy Pelosi and the Radical Left Democrats. See you on Monday night VOTE TUESDAY!!!',\n", " 'RT @TrumpWarRoom: \"We support protect and defend the Constitution\"\"We stand with the incredible heroes and warriors of law enforcement.…',\n", " 'Thank you so much CLUB 45. You are truly Great Americans. See you in Florida! https://t.co/0NuayEXEPn',\n", " 'Just returned to the @WhiteHouse after a great evening in Monroe Louisiana with a massive turnout of Great American Patriots. With early voting underway until Sat find your polling location below & go vote for your next #LAgov @EddieRispone! #GeauxVote➡️https://t.co/0rnhb4z3HU https://t.co/VLqgd5SOEc',\n", " 'Good luck Vince this will be great! https://t.co/084GASJN6e',\n", " 'RT @BobEwashington: Jesse Watters nails Joe Bite Me and John Kerry in one Monologue#TheFive https://t.co/bthgI2QQq9',\n", " 'RT @ericbolling: Great day.. great game .. great reception for @FLOTUS and @realDonaldTrump The south knows what’s what! https://t.co/3vy…',\n", " '.@NikkiHaley is out with a new book “With All Due Respect” this week. Make sure you order your copy today or stop by one of her book tour stops to get a copy and say hello. Good luck Nikki! https://t.co/uHKAAlVuLt',\n", " 'Schiff and the Dems have created this whole thing they reverse engineer it. They’ve been vowing to impeach for three years. Why should we listen to them? Why should we want to?” @greggutfeld @FoxNews',\n", " 'The Democrats have stacked the deck against President Trump and the Republicans. They have leaked out everything. @SteveDoocy @foxandfriends',\n", " 'RT @WhiteHouse: \"They\\'re trying to stop me because I\\'m fighting for you. And I\\'ll never let that happen.\" — President @realDonaldTrump htt…',\n", " 'Thank you @FranklinGraham. It is a time of “shame” for our Country. The Democrats know what they are doing is wrong! https://t.co/O32ybh04vc',\n", " 'RT @RepSmucker: No matter how hard the media and the Democrats try to spin the hearings these are the facts... #ImpeachingHearings #FactsM…',\n", " 'A new Republican Star is born. Great going @EliseStefanik! https://t.co/9QH4oUa2eg',\n", " 'Mr. Chairman Joe Biden may be Sleepy and Very Slow but he is not a “rabid dog.” He is actually somewhat better than that but I am the only one who can get you where you have to be. You should act quickly get the deal done. See you soon! https://t.co/kO2k14lTf7',\n", " 'RT @RepDanCrenshaw: Coming soon...A new #HeresTheTruth with @RepGregWalden debunking Pelosi’s drug pricing scheme. https://t.co/u9a8YBmb6o',\n", " 'Paul Krugman of @nytimes has been wrong about me from the very beginning. Anyone who has followed his “words of wisdom” has lost a great deal of money. Paul just concede the game say I was right and lets start a brand new game! https://t.co/O6bw61vcHL',\n", " 'RT @RepMarkGreen: .@SpeakerPelosi and @RepAdamSchiff are trying to reverse a national election out of fear and hatred of something they don…',\n", " 'RT @RepSmucker: What is crystal clear during these #ImpeachmentHearings are the FACTS ARE ON THE PRESIDENTS SIDE!Nothing has changed. Not…',\n", " 'RT @RepMarkGreen: I will speak up for my constituents in Tennessee who have had enough of this impeachment charade and want Congress to act…',\n", " 'MARK LEVIN ON IMPEACHMENT HYSTERIA! https://t.co/sFT4qGqajO',\n", " 'Thank you @EliseStefanik and @SteveScalise GREAT JOB! https://t.co/K8qQbCAXbj',\n", " 'RT @TeamTrump: .@LaraLeaTrump and @parscale bring Team Trump to Oregon and Arizona to rally supporters!Arizona is ready to stay red in 20…',\n", " 'This is the real story behind the Do Nothing Democrats! https://t.co/4tPTICdSR1',\n", " 'The Unspoken Truth: What Impeachment Exposed About Trump and 2020 https://t.co/pYTYBcD55I',\n", " 'RT @AndrewPollackFL: The California Supreme Court is the only piece of government in the state that has any common sense left.President T…',\n", " 'This is a great and well reseached book on Justice K. The Ruth Marcus book is a badly written & reseached disaster. So many incorrect facts. Fake News just like the @washingtonpost! https://t.co/i6GwghuEsU',\n", " 'GOD BLESS THE U.S.A.! #MAGAhttps://t.co/CYkQGHAgcx',\n", " 'Thank you to @BuckMcNeely1 and Oliver North for the nice words and thoughts in an excellent interview. Best wishes!',\n", " \"RT @thehill: JUST IN: Top Judiciary Republican calls on committee to expand list of impeachment witnesses ahead of next week's hearing http…\",\n", " 'Nancy Pelosi won’t put it up for a vote. Has delayed it for 6 months. See you in #2020! https://t.co/lOrWm9u10r',\n", " 'Not only did I see it @Doks_Art I think it is fantastic. You are a wonderful artist never give up your dream! https://t.co/LVVCUJz5CW',\n", " 'RT @Jim_Jordan: \"Jordan: Democrats didn\\'t admit they were wrong about Russia just moved on to Ukraine\"@TuckerCarlson https://t.co/l9tUFo…',\n", " 'RT @RepDougCollins: Prof. Turley: “Impeachments have to be based on proof not presumptions.” https://t.co/sl06UHs5ju',\n", " 'GREAT JOBS REPORT!',\n", " 'RT @RepMarkMeadows: Washington Democrats are counting impeachment votes. President Trump is counting 266000 new jobs and a 50-year record…',\n", " 'The United States will not rest until we bring every American wrongfully detained in Iran and around the world back home to their loved ones! https://t.co/2kWgJhvrtY',\n", " 'RT @DanHenninger: Pelosi’s decision to open the impeachment dam is starting to look like a blunder. Rather than let voters decide Trump’s f…',\n", " 'Congratulations to @TitoOrtiz on tonight’s huge WIN a Great American Patriot! https://t.co/m4tJpfzVte',\n", " 'RT @OANN: One America News presents an in-depth report on corruption by former Vice President Joe Biden and his family. Join @NeilWMcCabe…',\n", " 'RT @JennaEllisEsq: The Dems are desperately searching for grounds of impeachment and they have LOST. They have NOTHING.But they ARE afrai…',\n", " 'RT @WarRoom2020: Canada Just Lost the Equivalent of 650000 Jobs as Trump’s Economy Roars #WarRoomImpeachment https://t.co/gZK03BpIca',\n", " 'RT @WarRoom2020: Guardian: Nancy Pelosi is Bungling the Impeachment Inquiry #WarRoomImpeachment https://t.co/mNkYGagdkJ',\n", " 'RT @DailyCaller: Joe Biden Claims Ignorance On His Son’s Conflicts Of Interest With Burisma https://t.co/wH8ZJElF4p',\n", " 'RT @RepSmucker: The USMCA is a big win for Pennsylvania and the people of my district!Thanks to @realDonaldTrump and Republican policies…',\n", " 'RT @RoyBlunt: 🚨🚨🚨 @POTUS and House Democrats have announced an agreement to move #USMCA forward. My statement here ⤵️ https://t.co/Age7TDWf…',\n", " 'RT @RepArrington: After a year of needless delay by @SpeakerPelosi & Democrat leadership we are finally ready to deliver a win for America…',\n", " 'RT @TeamTrump: Overflow crowd outside of the Giant Center in Hershey PA on this cold and rainy night! 👀🇺🇸#TrumpRallyHershey https://t.co…',\n", " 'RT @kimguilfoyle: So much appreciation for the 10s of thousands of great Americans who show up rain or shine to support @realDonaldTrump. T…',\n", " 'RT @DonaldJTrumpJr: IG Report Confirms Schiff Memo Media Praised Was Riddled With Lies https://t.co/CEKpngAVX0',\n", " \"RT @RepAndyBiggsAZ: ➡️ There's BIPARTISAN opposition to impeachment.➡️ Contrary to the Democrats' claims there's no COMPELLING reason to…\",\n", " 'They were just upset that I demanded they pay their fair share for NATO. Their countries are delinquent. I raised $530 Billion more from NATO countries! Thank you Charles. https://t.co/1klX5GtK8r',\n", " 'The News Media in our Country is FAKE and in many cases totally CORRUPT! https://t.co/hj9plf0GMC',\n", " 'RT @EricTrump: I will be on the @IngrahamAngle at 10pmET!!! I have no doubt it will be quite the show tonight! 🇺🇸🇺🇸🇺🇸 #FoxNews https://t.co…',\n", " 'RT @KellyannePolls: Horowitz Report Reveals the Steele Dossier Was Always a Joke – Rolling Stone https://t.co/CKl3aKo64d',\n", " 'RT @RepMattGaetz: \"This is about one basic fact: the Democrats have never accepted the will of the American people.\" -@Jim_Jordan #impeachm…',\n", " 'RT @WhiteHouse: 🚨 The blue-collar middle-class Trump Boom demolished “expert” predictions... AGAIN! https://t.co/GbMXPPqYgu https://t.co/K…',\n", " 'RT @KimStrassel: Read it all here folks: https://t.co/VnLr0ilB3i via @WSJ',\n", " 'RT @JimPressOffice: \"Sensenbrenner: Democrat Impeachment ‘Weakest Case in History’\" https://t.co/R7RJoVjDkR',\n", " '....trampled on our Constitution and they have done irreparable harm to our Republic. The American people are going to speak up and speak out about this. I think this guarantees Trump’s re-election in 2020.” @Jason_Meister',\n", " 'On my way to the #ArmyNavyGame in Philadelphia Pennsylvania! https://t.co/tWnDNRFyO1',\n", " 'It was my Great Honor to attend the 120th Army-Navy game today in Philadelphia Pennsylvania! @NavyFB @ArmyWP_Football @ArmyNavyGame https://t.co/HipWiZKmiP',\n", " 'Thank you for your honesty Jeff. All of the Democrats know you are right but unlike you they don’t have the “guts” to say so! https://t.co/OUc46HUwPq',\n", " 'RT @KimStrassel: And I should say it is only because of @AndrewCMcCarthy deep knowledge and analysis that we understand it all! https://t.c…',\n", " 'A PERFECT phone call. “Can you do us (not me. Us is referring to our Country) a favor.” Then go on to talk about “Country” and “U.S. Attorney General.” The Impeachment Hoax is just a continuation of the Witch Hunt which has been going on for 3 years. We will win! #MAGAKAG #2020',\n", " '....impeaching him. They hate the fact above all that this president is delivering. Substantial policy results for the working Americans who put him in the White House and they can’t beat him in a fair fight next year.” @NextRevFNC @SteveHiltonx Thank you Steve!',\n", " '....impeaching him. They hate the fact above all that this president is delivering. Substantial policy results for the working Americans who put him in the White House and they can’t beat him in a fair fight next year.” @NextRevFNC @SteveHiltonx Thank you Steve!',\n", " 'RT @ChatByCC: Strong people stand up for themselves—but stronger people stand up for others.Thank you President @realDonaldTrump for stan…',\n", " \".@Buddy_Carter is a BUSINESSMAN first. He takes care of our Vets and Troops and is leading the fight to SLASH drug prices! Buddy's 100% pro-Wall & 100% pro-jobs. He will KEEP AMERICA GREAT and has my total Strong Endorsement!\",\n", " 'RT @GreggJarrett: Comey: FISA Abuse Not as Bad as My Other Screw Ups https://t.co/njd2Ck4uMg',\n", " 'RT @GreggJarrett: IG Horowitz hearing exposes deliberate FBI misconduct in investigating Trump campaign 👇https://t.co/XljdjMImaw',\n", " 'Thank you Michigan I am on my way. See everybody soon! #KAG https://t.co/GP9SbH67CN',\n", " 'RT @RepLeeZeldin: 🚨 BREAKING NEWS!!!Donald Trump is still your President. 🇺🇸👍💪',\n", " 'RT @SenatorFischer: From the day President Trump was elected Democrats have wanted to impeach and remove him from office. Today’s vote was…',\n", " 'RT @ScottAdamsSays: If the impeachment is shit the Senate must acquit. #Shampeachment',\n", " 'RT @JoeySalads: The Democrats impeached Trump for crimes committed by Joe Biden.Honestly I am impressed.',\n", " \"RT @CBSEveningNews: Pres. Trump lauds Rep. Jeff Van Drew during Oval Office meeting Thursday after freshman lawmaker's switch to the Republ…\",\n", " 'RT @DanScavino: 🚨HAPPENING NOW #DemDebate #Trump2020Landslide #KAG https://t.co/5GaS0QVW12',\n", " 'RT @TheRyanNYC1: @realDonaldTrump @greggutfeld @FoxNews Greatest president of my life time!',\n", " 'We are getting MS-13 gang members and many other people that shouldn’t be here out of our Country! https://t.co/Cfk4iIBVTQ',\n", " 'To The Extraordinary Men and Women of the United States Military: https://t.co/luDyPVKgfY',\n", " 'BIG thank you to Mac Thornberry (@MacTXPress) for a GREAT Defense Deal! Mac has been a champion for our Military and Vets his whole career and now he can add Space Force to his accomplishments. Look forward to another great defense bill next year Mac! @HASCRepublicans',\n", " 'The great Democrat disgrace. But we are winning! https://t.co/45mtfzKbA2',\n", " 'RT @GOPLeader: The FBI broke into President Trump’s campaign spied on him then tried to cover it up.This is a modern-day Watergate. htt…',\n", " 'RT @nealshact: On the second anniversary of the passage of the Tax Cuts and Jobs Act our economic predictions have been vindicated write…',\n", " 'RT @TrumpWarRoom: \"We believe our country should be a sanctuary for law-abiding Americans not for criminal aliens.\"The open borders agen…',\n", " 'Speaker Pelosi and Chuck Schumer’s drive to try and rig the trial against the President is misplaced. There is no factual basis for the Articles of Impeachment that passed the House. This President will be exonerated.” William McGinley @foxandfriends',\n", " 'He made same prediction in 2016. Nobody ever said Michael was stupid! https://t.co/XDEzsTS1Pt',\n", " 'The Wall is funded & being built! https://t.co/84BOxKr2Eo',\n", " 'The anti-Semitic attack in Monsey New York on the 7th night of Hanukkah last night is horrific. We must all come together to fight confront and eradicate the evil scourge of anti-Semitism. Melania and I wish the victims a quick and full recovery.',\n", " 'How is the Paris Accord doing? Don’t ask! @parisac https://t.co/9N0yibmDkj',\n", " 'RT @heatherjones333: 🔥🔥🔥🔥🔥Lindsey Graham: Trump Has World on Notice ‘There Will Be No Benghazis on His Watch’ https://t.co/4yfHKlZlV9',\n", " 'RT @TeamTrump: ⚡️ With 2019 behind us we look back on the fantastic accomplishments of President @realDonaldTrump for Americans (so far).…',\n", " \"RT @DanScavino: “Trump list shows 319 'results' and promises kept in three years”#MAGA🇺🇸#KAG🇺🇸 #HNY2020🎉 https://t.co/HPdYZEXfCC\",\n", " 'RT @USEmbBaghdad: تنبيه أمني - سفارة الولايات المتحدة في بغداد، العراق، 3 كانون الثاني 2020Security Alert – U.S. Embassy Baghdad Iraq J…',\n", " 'RT @TravelGov: #Iraq: Due to heightened tensions in Iraq and the region we urge U.S. citizens to depart Iraq immediately. Due to Iranian-b…',\n", " 'This is a great book a must read! https://t.co/bwpNVi5hpY',\n", " 'RT @DineshDSouza: Neither were the Iranians and for pretty much the same reason https://t.co/M1LSVjsFVO',\n", " 'RT @SecPompeo: Iraqis — Iraqis — dancing in the street for freedom; thankful that General Soleimani is no more. https://t.co/huFcae3ap4',\n", " 'RT @WhiteHouse: At the direction of the President the U.S. military has taken decisive defensive action to protect U.S. personnel abroad b…',\n", " 'RT @abigailmarone: 🚨MUST WATCH🚨Congressman lists every single high crime and misdemeanor committed by President Trump! Unbelievable! http…',\n", " 'RT @TuckerCarlson: San Francisco\\'s left-wing government has turned the city into an \"American Dystopia\" - Our shocking & exclusive 5-part s…',\n", " 'RT @JudgeJeanine: .@RepMarkMeadows joined me to talk about the latest on Iran take a look: https://t.co/H7abiJHyEe',\n", " 'RT @RepMarkMeadows: I think the vast majority agree killing 600+ Americans is well beyond justification to say: enough is enough. And yet…',\n", " 'I agree. Jovita will do a great job! https://t.co/3uwI4NUxBn',\n", " 'We will get this done for our great Miners! https://t.co/8x3WwEo0eV',\n", " 'The powerful Trump Wall is replacing porous useless and ineffective barriers in the high traffic areas requested by Border Patrol. Illegal crossing are dropping as more and more Wall is being completed! #BuildingTheWall https://t.co/2kdHNSMM04',\n", " 'I hope the House and Senate Democrats in particular watch this. It is a classic. Thank you to @JudgeJeanine Pirro! https://t.co/O8P9J0CArF',\n", " 'RT @SenTomCotton: The future of our Iran policy is critical to the global competition that will determine America’s safety and position in…',\n", " 'RT @BiggZie_VT: People just now realizing how crazy and destructive Nancy is to America better yet the world. I pity those that still supp…',\n", " 'RT @SenateGOP: .@SpeakerPelosi’s “urgent” impeachment will come to the Senate tomorrow. Now…it’s our turn. https://t.co/7zSWxBsKLD',\n", " 'RT @heytana: \"Look! Up in the sky! It\\'s a bird! It\\'s a plane! 🦅✈️🇺🇸 no it’s a massive .@realDonaldTrump banner at the #DemocraticDebate #KA…',\n", " 'Now up to 187 Federal Judges and two great new Supreme Court Justices. We are in major record territory. Hope EVERYONE is happy! https://t.co/ymEQljJyib',\n", " 'I agree with him on this 100%. But why would anyone vote Democrat? We are setting all time records with the economy! https://t.co/trTemE8iUz',\n", " 'RT @DailyCaller: Van Jones:“There was nothing I saw tonight that would be able to take Donald Trump out.”https://t.co/cj8e5JkYqW',\n", " 'RT @MarshaBlackburn: Tennesseans care about serious issues: trade relations border security and lasting tax relief. Democrats care abou…',\n", " 'This is a total disgrace but just another reason that I’m going to win Michigan again! https://t.co/XrqveOvYcG',\n", " 'RT @WhiteHouse: President @realDonaldTrump caps off an incredible week by welcoming the Louisiana State University Tigers! 🏈 https://t.co/h…',\n", " 'A great day at the White House for our National Champions the LSU Tigers! https://t.co/0sbotFsMO7',\n", " 'If you listened to the flawed advice of @paulkrugman at the @nytimes a newspaper that was going broke until I came along you would have entirely missed the RECORD BREAKING Stock Market (and other) numbers produced since Election Day 2016. Sorry those are the FACTS....',\n", " 'If you listened to the flawed advice of @paulkrugman at the @nytimes a newspaper that was going broke until I came along you would have entirely missed the RECORD BREAKING Stock Market (and other) numbers produced since Election Day 2016. Sorry those are the FACTS....',\n", " 'If you listened to the flawed advice of @paulkrugman at the @nytimes a newspaper that was going broke until I came along you would have entirely missed the RECORD BREAKING Stock Market (and other) numbers produced since Election Day 2016. Sorry those are the FACTS.....'],\n", " dtype=object)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "indices = indices_for_cluster(cluster_assignments, 3)\n", "tweets_from_cluster = df[\"tweets\"].values[indices]\n", "tweets_from_cluster" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### For each cluster, find the most representative tweet." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "on cluster 0\n", "on cluster 1\n", "on cluster 2\n", "on cluster 3\n", "on cluster 4\n", "on cluster 5\n", "on cluster 6\n", "on cluster 7\n", "on cluster 8\n", "on cluster 9\n", "on cluster 10\n", "on cluster 11\n", "on cluster 12\n", "on cluster 13\n", "on cluster 14\n", "on cluster 15\n", "on cluster 16\n", "on cluster 17\n", "on cluster 18\n", "on cluster 19\n" ] } ], "source": [ "centers = kmeans.cluster_centers_\n", "reps = []\n", "for k in range(n_clusters):\n", " print(\"on cluster {}\".format(k))\n", " min_dist, best_idx = np.inf, -1\n", " cluster_indices = indices_for_cluster(kmeans.labels_, k)\n", " for idx in cluster_indices[0]:\n", " x = X[idx]\n", " dist = np.sum((x-centers[k])**2)\n", " if dist < min_dist:\n", " best_idx = idx\n", " min_dist = dist\n", " reps.append(best_idx)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'n_clusters' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mrandom\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn_clusters\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"--- cluster {} ---:\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'tweets'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mreps\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'n_clusters' is not defined" ] } ], "source": [ "import random \n", "\n", "for k in range(n_clusters):\n", " print(\"--- cluster {} ---:\".format(k))\n", " print(df['tweets'].values[reps[k]])\n", " print()\n", " print(\"random sample from same\")\n", " \n", " cluster_indices = indices_for_cluster(kmeans.labels_, k)[0]\n", " ex_indices = np.random.choice(cluster_indices, 5, replace=False)\n", " print(df['tweets'].values[ex_indices])\n", " print(\"\\n\\n\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Try out a few different values of $k$. \n", "* Try out different random seeds." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What about `dbscan`?" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'X' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0msklearn\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcluster\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mDBSCAN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdbs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDBSCAN\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mdbs\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlabels_\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mNameError\u001b[0m: name 'X' is not defined" ] } ], "source": [ "from sklearn.cluster import DBSCAN\n", "dbs = DBSCAN().fit(X)\n", "dbs.labels_" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "23" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.max(dbs.labels_)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{-1,\n", " 0,\n", " 1,\n", " 2,\n", " 3,\n", " 4,\n", " 5,\n", " 6,\n", " 7,\n", " 8,\n", " 9,\n", " 10,\n", " 11,\n", " 12,\n", " 13,\n", " 14,\n", " 15,\n", " 16,\n", " 17,\n", " 18,\n", " 19,\n", " 20,\n", " 21,\n", " 22,\n", " 23}" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "set(dbs.labels_)" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['RT @JerryMoran: This proposal which incorporates provisions similar to legislation I introduced earlier this month with @SenRobPortman in…'\n", " 'RT @GOPChairwoman: The @realDonaldTrump re-election campaign has reported more female donors than any other candidate – and it’s not even c…'\n", " 'RT @RepMattGaetz: Democrats are trying to use the natural advantage they have with the mainstream media to have secret interviews and selec…'\n", " 'RT @KimStrassel: Democrats lecture about dirt-digging even as they abuse their surveillance powers to demand phone records to smear politi…']\n" ] } ], "source": [ "indices = indices_for_cluster(dbs.labels_, 9)\n", "tweets_from_cluster = df[\"tweets\"].values[indices]\n", "print(tweets_from_cluster)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }