fetching the twitter data naturallywe need tweets and their corresponding labels that tell us whether tweet contains positivenegativeor neutral sentiment in this we will use the corpus from niek sanderswho has done an awesome job of manually labeling more than tweets and granted us permission to use it in this to comply with twitter' terms of serviceswe will not provide any data from twitter nor show any real tweets in this insteadwe can use sandershand-labeled datawhich contains the tweet ids and their hand-labeled sentimentand use his scriptinstall pyto fetch the corresponding twitter data as the script is playing nicely with twitter' serversit will take quite some time to download all the data for more than tweets so it is good idea to start it now the data comes with four sentiment labelsxy load_sanders_data(classes np unique(yfor in classesprint("#% % (csum( == ))#irrelevant #negative #neutral #positive we will treat irrelevant and neutral labels together and ignore all non-english tweetsresulting into tweets these can be easily filtered using the data provided by twitter introducing the naive bayes classifier naive bayes is probably one of the most elegant machine learning algorithms out there that is of practical use despite its nameit is not that naive when you look at its classification performance it proves to be quite robust to irrelevant featureswhich it kindly ignores it learns fast and predicts equally so it does not require lots of storage sowhy is it then called naivethe naive was added to the account for one assumption that is required for bayes to work optimallyall features must be independent of each other thishoweveris rarely the case for real-world applications neverthelessit still returns very good accuracy in practice even when the independent assumption does not hold