Python代写｜MIE 1624 Introduction to Data Science and Analytics
Sentiment Analysis is a branch of Natural Language Processing (NLP) that allows us to determine algorithmically whether a statement or document is “positive” or “negative”.Sentiment analysis is a technology of increasing importance in the modern society as it allows individuals and organizations to detect trends in public opinion by analyzing social media content. Keeping abreast of socio-political developments is especially important during periods of policy shifts such as election years, when both electoral candidates and companies can benefit from sentiment analysis by making appropriate changes to their campaigning and business strategies respectively.
The purpose of this project is to compute the sentiment of text information – in our case, tweets posted recently on Canadian Elections – and answer the research question: “What can public opinion on Twitter tell us about the Canadian political landscape in 2021?” The goal is to essentially use sentiment analysis on Twitter data to get insights into the Canadian Elections. For this project, we’ve pulled tweets regarding the Canadian elections from the announcement of the 2021 election to the day before the election for your analysis.
Central to sentiment analysis are techniques first developed in text mining. Some of those techniques require a large collection of classified text data often divided into two types of data, a training data set and a testing data set. The training data set is further divided into data used solely for the purpose of building the model and data used for validating the model. The process of building a model is iterative, with the model being successively refined until an acceptable performance is achieved. The model is then used on the testing data in order to calculate its performance characteristics.
1) Produce a report in the form of an IPython notebook detailing the analysis you performed to answer the research question. Your analysis must include the following steps: data cleaning, exploratory analysis, model preparation, model implementation, and discussion. This is an open-ended problem: there are countless different ways to approach each part of the analysis and therefore the motivation for each step is just as important as its implementation. When writing the report, make sure to explain (for each step) what it is doing, why it is important, and the pros and cons of that approach. (20 pts)
2) Create 2 slides in PowerPoint (and convert to PDF) describing two key findings from exploratory analysis, model feature importance, or model results. Visuals are key here; avoid excessive amounts of text. (4 pts)
Two sets of data are used for this project. The sentiment_analysis.csv file contains tweets that have had their sentiments already analyzed and recorded as binary values 0 (negative) and 1 (positive).Each line is a single tweet, which may contain multiple sentences despite their brevity. The comma-separated fields of each line are:
0 ID Tweet ID
1 text the text of the tweet
2 label the polarity of each tweet (0 = negative sentiment, 1 = positive sentiment)The second data set, Canadian_elections_2021.csv contains a list of tweets regarding the 2021 Canadian federal elections. The fields of each line are:
0 text the text of the tweet
1 sentiment can be “positive” or “negative”
2 negative_reason reason for negative tweets. NaN for positive tweets Both datasets have been collected directly from the web, so they may contain html tags, hashtags,and user tags.
1.Data cleaning (2 marks):
The tweets, as given, are not in a form amenable to analysis – there is too much ‘noise’.Therefore, the first step is to “clean” the data. Design a procedure that prepares the Twitter data for analysis by satisfying the requirements below. Remember to use the same pipeline for both datasets.
2.Exploratory analysis (2.5 marks):
o Design a procedure that determines the political party (Liberal, Conservative, New Democratic Party (NDP), The People’s Party of Canada (PPC)) of a given tweet and apply this procedure to all the tweets in the Canadian Elections dataset. A suggestion would be to look at and count relevant words and hashtags in the tweets that identify to certain political parties or candidates. What can you say about the distribution of the political affiliations of the tweets? (hint: you may wish to extract the key words before removing the punctuations in Part 1.)
o Present a graphical figure (e.g. chart, graph, histogram, boxplot, word cloud, etc.) that visualizes some aspect of the generic tweets in sentiment_analysis.csv and another figure for the 2021 Canadian Elections tweets. All graphs and plots should be readable and have all axes that are appropriately labelled. Discuss your findings.
3.Sentiment Classification – Model implementation and tuning (12.5 marks):
a) Machine learning models: (5 marks)
b) Deep learning model: (4 marks)
c) Evaluate the trained model with the best performance (considering all models from part a) and part b)) on the Canadian Elections data. How well do your predictions match the sentiment labelled in the Canadian elections data? (0.5 marks)
d) Propose two other evaluation metrics you could use to evaluate the models. In one to two sentences, provide reasoning for each metric. (1 marks)
e) Choose the model that has the best performance and visualize the sentiment prediction results and the true sentiment for each of the 4 parties. From this model, discuss your findings and whether NLP analytics based on tweets is useful for political parties during election campaigns. Explain how each party is viewed in the public eye based on the sentiment value. Suggest one way you can improve the accuracy of this model. (2 marks)
4.Negative Reason Classification – Model implementation and tuning (3 marks):Split the negative Canadian elections tweets into training data (70%) and test data (30%).Use the true sentiment labels in the Canadian elections data instead of your predictions from the previous part. Choose one algorithms from classification algorithms (choose any model from logistic regression, k-NN, Naive Bayes, SVM,decision trees, RF, XGBoost, deep learning model), train multi-class classification models to predict the reason for the negative tweets. Tune the hyperparameters and chose the model with best score to test your prediction reason for negative sentiment tweets.
a) Provide a few reasons why your model may fail to predict the correct negative reasons. Back up your reasoning with examples from the test sets.
b) Suggest one way you can improve the accuracy of your selected model.
c) Feel free to combine similar reasons into fewer categories as long as you justify your reasoning. You are free to define input features of your model using word frequency analysis or other techniques.
Please clearly label each section of your work. Significant marks of each section are allocated to discussion. Use markdown cells as needed to explain your reasoning for the steps that you take. No separate report in addition to your IPython notebook is required.
○ Python version 3.6 or higher is required for this project.
○ Your code should run on the Google Colab cloud.
○ All libraries and built-ins are allowed but here is a list of the major libraries you might consider: Numpy, Scipy, Scikit, Matplotlib, Pandas, NLTK.
○ No other tool or software besides Python and its component libraries can be used to touch the data files. For instance, using Microsoft Excel to clean the data is not allowed.
○ sentiment_analysis.csv: classified Twitter data containing a set of tweets which have been analyzed and scored for their sentiment
○ Candian_elections_2021.csv: Twitter data containing a set of tweets from the 2021 Canadian elections, which needs to be analyzed for this project.
○ The data files cannot be altered by any means. The IPython Notebooks will be run using local versions of these data files.