CS1026A YouTube Emotions

能源管理基于MATLAB的企业最大需量预测模型:月内峰值追踪与超限风险模拟分析系统设计 项目介绍 MATLAB 企业最大需量预测|月内峰值追踪与超限场景模拟 内容概要:本文介绍了一个基于MATLAB R2025b的企业最大需量预测项目,旨在通过构建月内峰值追踪与超限风险识别模型,实现对企业电力负荷的精细化管理。项目综合考虑时间周期、环境温度、生产强度、特殊日期及随机扰动等因素,构建模拟数据集,并采用装袋回归树和岭回归等机器学习模型进行负荷预测。通过滚动峰值追踪机制,系统动态整合历史真实值与未来预测值,生成月内最大需量趋势曲线,并结合预设阈值实现超限预警。同时支持多场景模拟,如增产、高温、设备集中启动等,评估不同工况下的超限风险,为企业错峰生产、储能调度等决策提供量化支持。项目注重实用性与兼容性,输出形式包括可视化图表、风险等级标识和多格式数据文件,适用于能源管理教学、工业负荷研究及智能用电原型开发。; 适合人群:具备一定MATLAB编程基础,从事能源管理、电力系统分析、工业自动化或智能制造领域的科研人员、工程师及高校师生,尤其适合工作1-3年、希望深入理解负荷预测与企业用电成本控制的技术人员。; 使用场景及目标:①实现企业月内最大需量的动态预测与滚动追踪,提前识别超限风险;②通过多因素场景模拟评估不同生产与环境条件下对需量的影响;③为错峰生产、设备启停优化、储能调度等能源管理决策提供数据支撑;④构建可复现、可扩展的负荷预测分析框架,服务于实际电能管理系统开发。; 阅读建议:此资源以模拟数据为基础,重点在于模型架构设计与管理应用逻辑,建议读者结合提供的代码实例,在MATLAB环境中动手复现数据生成、模型训练、峰值追踪与可视化全过程,并尝试调整特征参数或引入真实数据以深化理解。 立即下载

CS1026A Fall 2024 

Assignment 3: YouTube Emotions 

Important Notes: 

• Read the whole assignment document before you begin coding. This is a more 

complex speciffcation than in past assignments and the examples and templates 

near the end of this document will be important in solving this assignment. 

• Assignments are to be completed individually. Use of tools to generate code, 

working with another person, or copying from online resources are not allowed and 

will result in a zero on this assignment regardless of how much was copied. 

• A code template is given in Section 6 (on page 17) for your main.py and 

emotions.py ffles. We highly recommend using these as a starting point for your 

assignment. The code is also attached to the assignment on OWL. 

Change Log: 

• Nov. 4

th

: The comments.csv ffle attached to Brightspace had an unexpected 

unicode character in one of the comments the changed the outcome of some of the 

examples given in this document. comments.csv has now been corrected and the 

examples in this document to match. 

• Nov. 13

th

: A type-o was found in the example for make_report() in section 5. This has 

now been corrected. The output shown at the end of the document in section 7 was 

still correct. This change has no impact on the autograder (it was marking correctly). 

1. Learning Outcomes 

By completing this assignment, you will gain skills relating to 

• Functions 

• Dictionaries and lists 

• Complex data structures 

• Text processing 

• Working with TSV and CSV ffles 

• File input and output 

• Exceptions in Python 

• Simple module use 

• Writing code that adheres to a given speciffcation 

• Working with real world problem 

 2. Background 

With the emergence of social media sites such as YouTube, Facebook, Reddit, Twitter (also 

known as X), LinkedIn, and WhatsApp, more and more data is being produced and made 

accessible online in a textual format. This textual data, such as YouTube comments, 

Tweets, or Facebook posts, can be hard to process but is incredibly important for 

organizations as it offers a current snapshot of the public’s emotions (affinity) or sentiment 

about a topic at a current point in time. Having a live view of your customer’s current affinity 

towards your products or the public’s view of your political campaign can be critical for 

success. 

Much work has been done towards the goal of creating large datasets of word affinity or 

sentiment. One such effort is the National Research Council (NRC) Emotion Lexicon which 

is a list of English words and their associations with eight basic emotions (anger, fear, 

anticipation, trust, surprise, sadness, joy, and disgust) and two sentiments (negative and 

positive). 

Our goal in this assignment is to use a simpliffed version of the NRC Emotion Lexicon to 

classify YouTube comments based on one of the following emotions anger, joy, fear, trust, 

sadness, or anticipation. Based on the emotion contained in each comment for a particular 

video we then want to generate a report that details the most common emotions YouTube 

users have towards that video based on their comments. 

3. Datasets 

Your Python program will deal with two datasets, a keywords data set that contains a 

simpliffed version of the NRC Emotion Lexicon (this dataset will remain the same for all 

tests of your program) and a Comma-Separated Values (CSV) ffle that contains the 

comments for a particular YouTube video (this dataset will change for each test of your 

program). 

3.1 Keywords Dataset (TSV File) 

The keywords.tsv ffle attached to this assignment contains a simpliffed version of the NRC 

Emotion Lexicon. This is a Tab-Separated Values (TSV) ffle in which each line of the ffle 

contains a single word and its emotional classiffcation based on six emotions (anger, joy, 

fear, trust, sadness, and anticipation). Each word in the ffle may be classiffed as having one 

or more emotions. The following is an example of the ffrst 10 lines of this ffle where tab (\t) characters are 

represented by arrows (→): 

abacus→0→0→0→1→0→0 

abandon→0→0→1→0→1→0 

abandoned→1→0→1→0→1→0 

abandonment→1→0→1→0→1→0 

abbot→0→0→0→1→0→0 

abduction→0→0→1→0→1→0 

abhor→1→0→1→0→0→0 

abhorrent→1→0→1→0→0→0 

abolish→1→0→0→0→0→0 

abominable→0→0→1→0→0→0 

Each line starts with a keyword and is followed by a score (0 or 1) for each emotion in this 

order: anger, joy, fear, trust, sadness, and anticipation. If a 1 is present it means that 

keyword is related to that emotion. If a 0 is present the keyword is unrelated to that 

emotion. 

For example, according to the above the word “abacus” is related to the emotion of trust 

and no other emotions. The word “abandon” is related to the emotions fear and sadness 

and no other emotions. 

All words in the dataset will be related to at least one emotion. This ffle’s contents will 

remain the same for all tests but may be given a different fflename based on the users input 

(e.g. it could be named keys.tsv or words.tsv rather than keywords.tsv). 

3.2 Comments Dataset (CSV File) 

The user will provide a Comma-Separated Values (CSV) ffle that contains a set of YouTube 

comments for a particular video. The name of this ffle will change based on the user’s input 

but will always end in .csv and have the same format. 

The following is an example of a possible line from this ffle (the ffle may contain one or 

more lines). Note that this document wraps the line on to multiple lines but in the ffle this is 

one line ended by a line break (\n): 

2,PixelPioneer24,brazil,The excavation scenes in the movie were 

excellent but the unnecessary derision of the hero's motives seemed 

unfair. His eventuality of success was not adequately showcased. Each line of this ffle will contain four values separated by a single comma character (,). The 

values will always be in the following order: 

Comment ID, Username, Country, Comment Text 

Comment ID is a unique positive integer identiffer for the comment. Username is the 

username of the user who posted the comment. Country is the user’s home country, and 

comment text is the text the of the comment posted by the user. 

No value will contain a line break or a comma character. The capitalization of country 

names could be different for each line even if it is for the same country, but the country will 

always be spelled the same. 

Space characters will only occur in the comment text or country name. 

4. Tasks 

In this assignment, you will write two Python ffles, emotions.py and main.py, that will 

attempt to determine the most common emotion expressed in a YoutTube video’s 

comments. You will create a number of functions (as speciffed in the Functional 

Speciffcation in Section 5) that will perform simple sentiment analysis on the YouTube 

comments. 

To accomplish this, you will need to do the following: 

1. Accept input from the user: The user will specify the ffle names of the keywords 

and comments data sets as well as the name of the report ffle your program will 

create. The user will also input the name of the country they wish to fflter the 

comments by. 

2. Read. Your program will read in the keyword and comments datasets and store 

them in the formats described in the functional speciffcation (in Section 5). 

3. Clean. The text of the comments will be cleaned to remove any punctuation and 

convert them to all lowercase letters. 

4. Determine Emotion. You will use the keyword’s dataset to determine the overall 

emotion expressed in each comment. 

5. Generate Report. Based on your analysis of each comment, you will create a report 

ffle that contains a summary of the most common emotion expressed as well as 

how common each emotion was (as speciffed in Section 5). Additionally, you must follow the functional speciffcation presented in Section 5 and the 

rules and requirements in Section 8. 

5. Functional Speciffcation 

5.1 emotions.py 

The functions described in this section should be present in your emotions.py ffle and must 

be used in some way in your program to read, clean, process, analyze, or report on the 

comments in the given dataset. Each function and its parameters must have the same 

name and spelling as speciffed below: 

clean_text(comment) 

This function should have one parameter, comment, which is a string that contains the 

text of a single comment from the comments dataset. The function should clean this 

text by replacing any characters that are not letters (A to Z) and replacing them with 

space characters. It should also convert the comment’s text to all lower case. 

This function should return the cleaned text as a string. 

Example: 

clean_text("This4is-an example. It's a b*t silly.") 

will result in this output: 

this is an example it s a b t silly 

make_keyword_dict(keyword_file_name) 

This function should read the Tab-Separated Values (TSV) keywords ffle as described in 

Section 3.1. keyword_ffle_name is a string containing the name of the keywords ffle. 

This function can safely assume that this ffle exists, is in the current working directory, 

and is properly formatted. Checks on the ffle’s existence will be done in the main.py ffle 

described later in this document. 

The function should return a dictionary with keys for each word in the ffle and the values 

of this dictionary should be a new dictionary for each keyword that contains a value for 

each emotion (anger, joy, fear, trust, sadness, and anticipation). Example: 

Assuming that keywords.tsv contains the following three lines (where → is a tab 

character): 

abacus→0→0→0→1→0→0 

abandon→0→0→1→0→1→0 

abandoned→1→0→1→0→1→0 

then calling 

make_keyword_dict("keywords.tsv") 

should result in the following nested dictionary data structure: 

{'abacus': {'anger': 0, 

 'joy': 0, 

 'fear': 0, 

 'trust': 1, 

 'sadness': 0, 

 'anticipation': 0}, 

 'abandon': {'anger': 0, 

 'joy': 0, 

 'fear': 1, 

 'trust': 0, 

 'sadness': 1, 

 'anticipation': 0}, 

 'abandoned': {'anger': 1, 

 'joy': 0, 

 'fear': 1, 

 'trust': 0, 

 'sadness': 1, 

 'anticipation': 0} 

} Note that to pass the Gradescope tests this function must return a dictionary and not 

another collection such as a list, the keyword keys must be spelled exactly as listed in 

keywords.tsv, and the emotions must be spelled correctly and in lower case. 

Hint: You may find a number of the Python string methods helpful when creating this 

function. 

make_comments_list(filter_country, comments_file_name) 

This function should read the Comma-Separated Values (CSV) file as described in 

Section 3.2. comments_file_name is a string containing the name of the CSV file and 

filter_country is a string containing either a country name or the string “all”. This 

function should read the CSV file and return a list containing only comments for the 

given country listed in filter_country (or all countries if the string “all” is given). 

The list should contain one element for each comment in the file that matches the 

country in the filter (or all comments if “all” is given). Each element in the list should be a 

dictionary that contains a key for the Comment ID, Username, Country and Comment 

Text. The keys should be named 'comment_id', 'username', 'country', and 'text' 

respectively. 

The comment text should be stripped of any leading and trailing whitespace. 

Example 1: 

Assuming that comments.csv only contains the following two lines (note that the line is 

wrapped in this document and in the .csv file this is only two lines): 

1,RetroRealm77,united states,I was a bit disappointed with the 

film's portrayal of childhood heroism. It felt like the classic 

elements were just concealed under layers of unnecessary savagery 

and violence. 

2,PixelPioneer24,brazil,The excavation scenes in the movie were 

excellent but the unnecessary derision of the hero's motives seemed 

unfair. His eventuality of success was not adequately showcased. 

then calling 

make_comments_list("all", "comments.csv") 

should result in the following nested list and dictionary data structure: [ {'comment_id': 1, 

 'username': 'RetroRealm77', 

 'country': 'united states', 

 'text': 'I was a bit disappointed with the film's portrayal of 

childhood heroism. It felt like the classic elements were just 

concealed under layers of unnecessary savagery and violence.'}, 

 {'comment_id': 2, 

 'username': 'PixelPioneer24', 

 'country': 'brazil', 

 'text': 'The excavation scenes in the movie were excellent but 

the unnecessary derision of the hero's motives seemed unfair. His 

eventuality of success was not adequately showcased.'} ] 

Example 2: 

Given the same contents of comments.csv as in Example 1, if the following function call 

with the country name brazil was made: 

make_comments_list("brazil", "comments.csv") 

then the only element in the returned list would be: 

[ {'comment_id': 2, 

 'username': 'PixelPioneer24', 

 'country': 'brazil', 

 'text': 'The excavation scenes in the movie were excellent but 

the unnecessary derision of the hero's motives seemed unfair. His 

eventuality of success was not adequately showcased.'} ] 

 Example 3: 

Given the same contents of comments.csv as in Example 1, if the function was called 

with a country name that was not present in the file such as: 

make_comments_list("not a real country", "comments.csv") 

then the resulting list would be empty: 

[] 

Note that to pass the Gradescope tests this function must return a list and not another 

collection such as a set or dictionary, the values of each list element must be a 

dictionary, and the keys used in that dictionary must match the spelling and lowercase 

capitalization given in this section. 

classify_comment_emotion(comment, keywords) 

This function takes the text of a comment and the keywords dictionary created by the 

make_keyword_dict function as parameters and classifies the comment as one of the 

possible emotions (anger, joy, fear, trust, sadness, and anticipation), returning the 

emotion as a string. 

A comment is classified by first cleaning the text (using the clean_text function) and 

then checking each word in the comment against the keywords dictionary. A total for 

each possible emotion should be kept with each word in the comment matching a 

keyword adding to the totals (based on the values in the keywords dictionary). 

Example: 

For the comment: 

The excavation scenes in the movie were excellent but the 

unnecessary derision of the hero's motives seemed unfair. His 

eventuality of success was not adequately showcased. 

the text should be first cleaned using clean_text to get: 

the excavation scenes in the movie were excellent but the 

unnecessary derision of the hero s motives seemed unfair his 

eventuality of success was not adequately showcased then each word should be checked against the keywords dictionary and the totals for 

each emotion kept. Words not matching any words in the dictionary (shown in black 

above) do not add to the scores. For example, using the full keywords.tsv dataset the 

words shown in blue above have matches in the keyword dataset and would result in 

the following totals: 

Word anger joy fear trust sadness anticipation 

excavation 0 0 0 0 0 1 

excellent 0 1 0 1 0 0 

derision 1 0 0 0 0 0 

hero 0 1 0 1 0 1 

unfair 1 0 0 0 1 0 

eventuality 0 0 1 0 0 1 

success 0 1 0 0 0 1 

Total: 2 3 1 2 1 4 

Therefore, this comment would be classified as having the emotion of anticipation and 

the string “anticipation” should be returned by the function as it as the highest score. 

In the event of a tie, the emotions should be given priority in this order: 1) anger, 2) joy, 3) 

fear, 4) trust, 5) sadness, and 6) anticipation. 

Hint: You may find the string split method useful for looping through words rather than 

characters. 

make_report(comment_list, keywords, report_filename) 

This function takes the comment_list (created by the make_comments_list function), 

the keywords dictionary (created by the make_keyword_dict function), and a string 

containing the file name of the report to generate (report_filename) as parameters. 

A new file should be created with the file name in report_filename and it should contain 

the name of the most common emotion classification in the comment_list dataset as 

well as a count of the number of comments classified as each emotion. In the event of a 

tie the emotions should be given priority in this order: 1) anger, 2) joy, 3) fear, 4) trust, 5) 

sadness, and 6) anticipation. 

 The format of the report should match the following example which is based on the 

attached comments.csv and keywords.tsv with a country filter of “all”: 

Most common emotion: anger 

Emotion Totals 

anger: 5 (33.33%) 

joy: 2 (13.33%) 

fear: 1 (6.67%) 

trust: 3 (20.0%) 

sadness: 3 (20.0%) 

anticipation: 1 (6.67%) 

The emotion totals should occur in the same order (regardless of the counts) but the 

values would be different depending on the comment_list and keywords dictionary 

passed to the function. 

All percentages should be rounded to two digits and all six emotions should always be 

listed even if their count is zero. Important: in your report file each percentage must be 

written with one or two decimal places. A value such as 20.000% or 6.6700% would be 

wrong even though it is technically rounded as there are too many decimal places. Your 

output must be formatted exactly as shown in the example above including the spacing 

and line breaks. 

 Return 

The function should return the name of the most common emotion; in this example it 

would be “anger”. 

Exception 

In the event that the comment_list contains no comments (i.e. it is an empty list), the 

function should raise a RuntimeError containing the text “No comments in dataset!”. 

Reminder: The report should be saved to a file and not output to the screen or returned 

by the function. Only the name of the most common emotion should be returned. 

 5.2 main.py 

The program in main.py should ask the user for the file names of the keyword file and 

comments file that the data will be read from, as well as the name of the report file that will 

be created. It must use the functions defined in the emotions.py file to perform the tasks 

described in Section 4 and write the final report. 

Your main.py file must contain the following two functions (ask_user_for_input and main) 

as specified: 

ask_user_for_input() 

This function takes no parameters but asks the user to input the file names of the 

keywords TSV file, the comments CSV file, the country to filter by, and the file name of the 

report to be generated. These three filenames and the country name are returned in a 

tuple in this order: 1) keyword filename, 2) comment fflename, 3) country name 

(converted to lower case), and 4) report filename. 

Example (of valid input): 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): Canada 

Input the name of the report file (ending in .txt): report.txt 

User input is shown in green and input prompts in black. Note that the filenames and 

country are based on the user’s input and can not be hardcoded to one set value. This 

means that the filenames could be different depending on the values input by the user. 

In this case the following tuple would be returned: 

('keywords.tsv', 'comments.csv', 'canada', 'report.txt') 

Note that the country name was converted to all lowercase. 

Exceptions 

Your ask_user_for_input() method must complete the following checks on the user input. 

If the input does not pass a check, an Exception should be raised causing the function to 

exit immediately. Exceptions should be raised as soon as the invalid input is given. For example, if the 

keyword file does not exist, an exception should be raised before asking the user to input 

the comments file name. 

Check 1: File Extension 

For each of the three filenames, if the user inputs a filename ending in the wrong file 

extension (.csv, .tsv, or .txt) the function should raise a ValueError exception with a 

message stating that the file extension is incorrect such as “Keyword file does not end in 

.tsv!”. The text of this message must be exactly the following for each file: 

• Keyword File: “Keyword file does not end in .tsv!” 

• Comments File: “Comments file does not end in .csv!” 

• Report File: “Report file does not end in .txt!” 

Check 2: Files Exist 

For the keyword and comment files you must check if the file exists using the 

os.path.exists function. If it does not, your function must raise a IOError exception with 

text explaining that the function does not exist. The message should have the text “<file 

name> does not exist!” where <file name> is replaced with the filename such as 

“keywords.tsv does not exist!", where keywords.tsv is the missing file. 

For the report file, if the file already exists, an IOError should be raised with text stating 

that “<file name> already exists!” where <file name> is the name of the report file. For 

example “report.txt already exists!” where the report file is named report.txt. This is to 

help prevent accidentally overwriting any files. 

Check 3: Valid Country 

Lastly you must check that the country input is either “all” or one of the following 

countries: 'bangladesh', 'brazil', 'canada', 'china', 'egypt', 'france', 'germany', 'india', 'iran', 

'japan', 'mexico', 'nigeria', 'pakistan', 'russia', 'south korea', 'turkey', 'united kingdom', or 

'united states'. If any other country or word is input, a ValueError should be raised with 

the text “<country> is not a valid country to filter by!” where <country> is the country the 

user input. This subset of countries was chosen as they tend to occur in the datasets, we are using 

more than others. In more realistic scenario you would likely want to include all valid 

country names in this list, but this assignment limit to the above-mentioned countries. 

Keep in mind that this only limits the countries a user can filter by, it does not limit what 

country names can occur in the dataset. 

main() 

This function handles calling the other functions in main.py and emotions.py to perform 

the tasks listed in Section 3. It should check for any exceptions being raised by the 

ask_user_for_input function, output the error message contained in the exception (this 

can be done by simply printing the exception with print()), and ask the user to input the 

values again if any exception is raised. 

Once valid input has been received, it should call the functions from emotions.py 

required to analyze the comments and generate the report. 

Lastly it should output to the screen the most common emotion in the comment data set. 

This should be displayed as “Most common emotion is: <emotion name>” where emotion 

name is the name of the emotion such as “Most common emotion is: anger” if the 

emotion is anger. 

If the make_report function raises a RuntimeError exception (e.g. the comment list was 

empty), it should output the message contained in that error. 

Example 1: 

For the values in the attached keywords.tsv and comments.csv files: 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): all 

Input the name of the report file (ending in .txt): report.txt 

Most common emotion is: anger 

User input is shown in green and the contents of the outputted report.txt file is: 

Most common emotion: anger 

Emotion Totals 

anger: 5 (33.33%) joy: 2 (13.33%) 

fear: 1 (6.67%) 

trust: 3 (20.0%) 

sadness: 3 (20.0%) 

anticipation: 1 (6.67%) 

Example 2: 

For the same values in keywords.tsv and comments.csv but a country of “Canada”: 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): Canada 

Input the name of the report file (ending in .txt): report_cad.txt 

Most common emotion is: sadness 

 And the contents of report_cad.txt would be: 

Most common emotion: sadness 

Emotion Totals 

anger: 1 (16.67%) 

joy: 0 (0.0%) 

fear: 0 (0.0%) 

trust: 2 (33.33%) 

sadness: 3 (50.0%) 

anticipation: 0 (0.0%) 

Example 3: 

In this example invalid inputs are given, and the user is asked to input them again. 

Input keyword file (ending in .tsv): not_a_real_file.tsv 

Error: not_a_real_file.tsv does not exist! 

Input keyword file (ending in .tsv): real_file_wrong_extension.txt 

Error: Keyword file does not end in .tsv! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): not_a_real_file.csv 

Error: not_a_real_file.csv does not exist! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): bad_file_extension.tsv 

Error: Comment file does not end in .csv! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): c.csv 

Input a country to analyze (or "all" for all countries): Duck 

Error: duck is not a valid country to filter by! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): c.csv 

Input a country to analyze (or "all" for all countries): Belgium 

Error: belgium is not a valid country to filter by! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): c.csv 

Input a country to analyze (or "all" for all countries): FrAnCe 

Input the name of the report file (ending in .txt): report.txt 

Error: report.txt exists, the report file can not already exist! 

Input keyword file (ending in .tsv): keys.tsv 

Input comment file (ending in .csv): c.csv 

Input a country to analyze (or "all" for all countries): FrAnCe 

Input the name of the report file (ending in .txt): report_france.txt 

Error: No comments in dataset! 

Note that the above is one run of the program. It should keep asking for input again if an 

exception occurs in the ask_user_for_input function. Also note that in this example, 

keys.tsv and c.csv are valid files that exist and the file report.txt already exists. “Belgium” 

is not in the list of valid countries so it is rejected and “FrAnCe” is accepted despite it’s 

odd capitalization as the ask_user_for_input function should convert it to lowercase. 

In this example, the c.csv file contained no comments for France, so the exception “No 

comments in dataset!” was raised by make_report function. 

 6. Templates 

This section gives some starter code you should use in your program. You may not alter the 

names of any function or the parameters the functions take (this includes adding or 

removing parameters). You may not import any libraries or modules not included in the 

template code and all code you add should be inside a function (adding code outside of a 

function may cause the Gradescope tests to fail). You may add additional helper functions 

as needed. 

emotions.py 

# add a comment here with your name, email, and student number 

# you can not add any import lines to this file 

EMOTIONS = ['anger', 'joy', 'fear', 'trust', 'sadness', 'anticipation'] 

def clean_text(comment): 

 # add your code here and remove the pass keyword on the next line 

 pass 

def make_keyword_dict(keyword_file_name): 

 # add your code here and remove the pass keyword on the next line 

 pass 

def classify_comment_emotion(comment, keywords): 

 # add your code here and remove the pass keyword on the next line 

 pass 

def make_comments_list(filter_country, comments_file_name): 

 # add your code here and remove the pass keyword on the next line 

 pass 

def make_report(comment_list, keywords, report_filename): 

 # add your code here and remove the pass keyword on the next line 

 pass 

main.py 

# add a comment here with your name, email, and student number. 

# do not add any additional import lines to this file. 

import os.path 

from emotions import * 

VALID_COUNTRIES = ['bangladesh', 'brazil', 'canada', 'china', 'egypt', 

 'france', 'germany', 'india', 'iran', 'japan', 'mexico', 

 'nigeria', 'pakistan', 'russia', 'south korea', 'turkey', 

 'united kingdom', 'united states'] 

def ask_user_for_input(): 

 # add your code here and remove the pass keyword on the next line 

 pass 

def main(): 

 # add your code here and remove the pass keyword on the next line 

 pass 

if __name__ == "__main__": 

 main() 

Note About Imports 

It is important to import the files in the correct order and from the correct files. Main.py 

should import emotions.py as shown in the template above and not the other way around. 

7. Extra Example 

The files keywords.tsv and comments.csv should be attached to this assignment on 

OWL. The result of running them with the following countries is given below: 

Example 1: Country of “All” 

Input/Output: 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): all 

Input the name of the report file (ending in .txt): my_report.txt 

Most common emotion is: anger 

Contents of my_report.txt: Most common emotion: anger 

Emotion Totals 

anger: 5 (33.33%) 

joy: 2 (13.33%) 

fear: 1 (6.67%) 

trust: 3 (20.0%) 

sadness: 3 (20.0%) 

anticipation: 1 (6.67%) 

Example 2: Country of “brazil” 

Input/Output: 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): brazil 

Input the name of the report file (ending in .txt): report_brazil.txt 

Most common emotion is: fear 

Contents of report_brazil.txt: 

Most common emotion: fear 

Emotion Totals 

anger: 0 (0.0%) 

joy: 0 (0.0%) 

fear: 1 (50.0%) 

trust: 0 (0.0%) 

sadness: 0 (0.0%) 

anticipation: 1 (50.0%) 

Example 3: Country of “germany” (there are no comments for this country in the data set) 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): germany 

Input the name of the report file (ending in .txt): report.txt 

Error: No comments in dataset! 

 Example 4: Invalid Inputs (these files do not exist or have the wrong extension) 

Input keyword file (ending in .tsv): badfile.pizza 

Error: Keyword file does not end in .tsv! 

Input keyword file (ending in .tsv): this_file_does_not_exist.tsv 

Error: this_file_does_not_exist.tsv does not exist! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): badcsvfile.duck 

Error: Comment file does not end in .csv! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): not_a_real_csv_file.csv 

Error: not_a_real_csv_file.csv does not exist! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): not_a_real_country 

Error: not_a_real_country is not a valid country to filter by! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): JaPaN 

Input the name of the report file (ending in .txt): badreportfile.exe 

Error: Report file does not end with .txt! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): JAPAN 

Input the name of the report file (ending in .txt): already_exists.txt 

Error: already_exists.txt exists, the report file can not already exist! 

Input keyword file (ending in .tsv): keywords.tsv 

Input comment file (ending in .csv): comments.csv 

Input a country to analyze (or "all" for all countries): jApAn 

Input the name of the report file (ending in .txt): new_report_file.txt 

Most common emotion is: anger 

 8. Non-Functional Specification 

In addition to the other tasks and specifications given in this document, your program must 

also fulfill the following requirements: 

1. Your code must be written for Python 3.10 or newer. 

2. You may not use any modules or third-party libraries not described in this 

document. Standard built-in functions such as the String, file, and math functions 

are fine. You should not have to import anything other than your emotions.py and 

the os.path module. TAs may manually remove marks from your Gradescope test if 

you violate this rule. 

3. You must document your code with brief comments. Each file should contain a 

comment at the top of the file with your name, western e-mail, student number, and 

a brief description of what is contained in that file. At least one comment should 

also be given for each function that describes its purpose, parameters, and values 

returned. You should also include any additional comments to document any lines 

that may be unclear to the reader. 

4. Your program must be efficient and terminate within a reasonable time limit. All 

gradescope test cases (including any hidden cases) must terminate within the 

autograder’s time limit. 

5. Assignments are to be done individually and must be your own original work. You 

may not show or otherwise share your code for this assignment with others or use 

tools to generate your code for you. Software will be used to detect academic 

dishonesty (cheating). If you have any questions about what is or is not academic 

dishonesty, please consult the document on academic dishonesty and ask any 

questions to your course instructor before submitting this assignment. 

6. You must follow Python style and coding conventions and good programming 

techniques, for example: 

a. Meaningful variable and function names. 

b. Use a consistent convention for naming variables, constants, and functions 

(snake case is recommended). 

c. Readability: indentation, white space, consistency. 

7. All of your code should be contained in the files main.py and emotions.py. Only 

submit these files and no others and ensure the filenames match exactly. It is your 

responsibility to ensure you have submitted the correct files. 

8. All function names and outputs should follow the specifications given in this 

document exactly. Not following the specifications may lead to test cases failing. It is your responsibility to ensure you have followed them correctly and your tests are 

passing. 

9. Hardcoding or any other attempt to fool Gradescope’s autograder will result in a 

zero grade for that test being manually assigned and possibly additional penalties. If 

you have any doubts about what is or is not hardcoding, please ask your instructor 

by posting to the course forums. 

10. Frequently backup your work remotely (e.g. using OneDrive) in a way that is secure 

and private. No extension will be given for lost or corrupted files or submitting 

incorrect files. 

9. Marking and Submission 

9.1 Submission 

You must submit the 2 files (main.py and emotions.py) to the Assignment 3 submission 

page on Gradescope. There are several tests that will automatically run when you upload 

your files. The result of each test with be displayed to you, but not necessarily the exact 

details of the test. It is your responsibility to ensure all tests pass before the 

assignment due date. 

It is recommended that you create your own test cases to check that the code is working 

properly for a multitude of different scenarios (some example datasets have been provided 

for you with this document on OWL). 

Assignments will not be accepted by email or by any other form other than a Gradescope 

submission. 

9.2 Marking 

The assignment will be marked as a combination of your auto-graded tests (both visible 

and hidden tests) and manual grading of your code logic, comments, formatting, style, etc. 

Marks will be deducted for failing to follow any of the specifications in this document 

(both functional and nonfunctional), not documenting your code with comments, using 

poor formatting or style, hardcoding, or naming your files incorrectly. 

 Marking Scheme: 

• Autograded Tests: 24.5 points 

• Header comment including your name, student ID, course info, creation date, and 

description of file: 1.5 points 

• Descriptive in-line comments throughout code: 1 point 

• Meaningful variable names: 1 point 

Total: 28 points 

9.3 Late Submissions 

Late assignments will only be accepted up to 3 days late and only if you have enough late 

coupons remaining (at least one for each day late). If you submit one day late, you will need 

to use 1 late coupon. 2 days late, 2 late coupons. And 3 days late, 3 late coupons. If you 

have insufficient late coupons remaining or submit more than 3 days late, you will receive a 

zero grade on this assignment. 

It is your responsibility to track your late coupon use. Any values shown on OWL should be 

considered an estimate and may not be accurate or up to date. 

Unlimited resubmissions are allowed, but the late penalty will be determined by the 

date/time of your most recent (last) resubmission. This means if you resubmit past the 

deadline, your assignment will be considered late. 

Matlab实现使用遗传算法的混合能源系统优化.rar 立即下载

相关推荐

压液氧(LOX)火箭发动机涡轮泵级建立了一条自动化的基于模型的系统工程(MBSE)与多学科设计优化(MDO)流水线.rar

压液氧(LOX)火箭发动机涡轮泵级建立了一条自动化的基于模型的系统工程(MBSE)与多学科设计优化(MDO)流水线.rar

【FDE知识库】(1):AI 编程时代开发语言选型分析,云使用go,企业用java,算法python,底层c

AI 编程时代,开发语言选型需综合考量AI适配度、编译速度、跨平台与学习成本。Python以海量语料和即时执行成首选,适用于AI/ML与原型开发;TypeScript凭借类型系统与秒级构建,成为前端及应用层主流;Go以极速编译与统一风格,契合AI代理高效迭代需求。Rust/C++虽性能强,但编译慢、学习成本高,不适于快速试错。综合推荐:优先选Python、TypeScript、Go,兼顾效率与生态,实现最优AI协作体验。

freewebsys的专栏 658

在加性高斯白噪声和瑞利衰落信道上,针对BPSK_QPSK的误码率性能的MATLAB仿真,并扩展了相位优化的可重构智能表面辅助链路对比.rar

在加性高斯白噪声和瑞利衰落信道上,针对BPSK_QPSK的误码率性能的MATLAB仿真,并扩展了相位优化的可重构智能表面辅助链路对比.rar

DXF、DWG工程制图文件查看器

DXF、DWG工程制图文件查看器。 可以在界面中进行测量(包括距离、面积、角度等等) 无需版权,放心使用。

python 操作海康威视工业相机资源例子--ParametrizeCamera_LoadAndSave.zip

python 操作海康威视工业相机资源例子--ParametrizeCamera_LoadAndSave

数字农业与乡村振兴行业可信数据空间应用规划方案(专项申报版).pptx

数字农业与乡村振兴行业可信数据空间应用规划方案(专项申报版).pptx

含分布式电源的配电网可靠性评估研究(Matlab代码实现)

内容概要:本文围绕含分布式电源的配电网可靠性评估展开研究,基于Matlab代码实现相应的评估模型。研究内容涵盖分布式电源接入对配电网运行特性的影响,采用序贯蒙特卡洛模拟法等可靠性评估方法,对系统在不同运行场景下的供电可靠性指标进行量化分析。通过构建典型配电网模型,仿真分析分布式电源的位置、容量及出力特性对系统可靠性的影响机制,进而为提升配电网韧性与供电质量提供理论支撑和技术手段。研究不仅关注理论建模,还注重实际仿真流程的可操作性与结果的可视化呈现。; 适合人群:具备电力系统基础知识,从事配电网规划、运行与可靠性分析等相关领域的科研人员及工程技术人员,尤其适合研究生及从事新能源并网研究的1-3年工作经验的专业人员。; 使用场景及目标:①掌握含分布式电源的配电网可靠性评估基本理论与方法;②学习并复现主流可靠性评估算法(如蒙特卡洛模拟)的Matlab编程实现;③分析分布式电源接入对系统可靠性的影响规律,支撑配电网优化规划与运行决策。; 阅读建议:建议读者结合电力系统可靠性教材与本文Matlab代码同步学习,重点关注模型构建逻辑与算法实现细节,动手调试代码以加深对评估流程的理解,并尝试在不同网络结构和电源配置下进行仿真对比分析。

Python 列表、元组、集合实验报告:切片删除陷阱、可哈希判定与保序去重

Python 列表、元组、集合实验报告:切片删除陷阱、可哈希判定与保序去重

具有PWM控制VSC-HVDC链路的IEEE30总线传输系统(Simulink仿真实现)

内容概要:本文详细介绍了在Simulink环境中构建和仿真一个集成PWM控制的电压源换流器型高压直流输电(VSC-HVDC)链路的IEEE30节点电力传输系统的研究工作。该模型聚焦于利用PWM技术实现对VSC的高效、精确控制,以提升电力系统的传输效率、动态响应能力和运行稳定性。研究涵盖了系统整体建模、关键设备参数设计、PWM控制策略的实现、以及在标准IEEE30节点系统上的集成方法。通过一系列仿真测试,包括系统在正常运行、负载突变及故障条件下的动态响应,全面分析了VSC-HVDC链路对改善电网电压稳定性、优化潮流分布和增强系统可靠性的具体作用,充分验证了所提方案的有效性和工程应用价值。; 适合人群:具备电力系统分析、高压直流输电技术基础理论知识及Simulink/MATLAB仿真软件操作能力的高校研究生、科研机构研究人员和电力行业工程师。; 使用场景及目标:①作为教学案例,帮助学生深入理解VSC-HVDC的工作原理、控制策略及其在复杂电网中的集成应用;②为电力系统规划与运行人员提供一种可靠的仿真工具,用于评估新型输电技术对现有电网性能的影响,支持电网升级改造决策;③推动VSC-HVDC技术在远距离大容量输电、新能源并网和智能电网建设等领域的创新应用。; 阅读建议:建议读者在学习过程中,结合电力系统稳态与暂态分析的相关理论,重点关注PWM控制模块和VSC的建模细节,动手复现并调试所提供的Simulink模型,通过改变系统参数和运行工况来观察仿真结果的变化,从而深化对VSC-HVDC系统动态特性的理解。

T03_eVTOL低空经济低空无人机AI识别自动处理图像项目设计方案_决策评审版.pptx

T03_eVTOL低空经济低空无人机AI识别自动处理图像项目设计方案_决策评审版.pptx

基于斜坡补偿的Buck电路峰值电流+电压电流双闭环控制【附说明文档】(Simulink仿真实现)CSDN首页发布文章CSDN同步助手LLC谐振变换器开环+闭环软启动仿真设计(Simulink

内容概要:本文围绕三电平VIENNA整流器的双闭环控制与中点电位平衡问题展开仿真研究,提出了一种基于上下电容电压差值补偿的中点电位平衡策略。该策略在传统电压电流双闭环PI控制的基础上,引入电容电压差值作为反馈信号,通过SVPWM调制中冗余小矢量的时间分配实现中点电荷的定向调节,从而在不改变主控制结构的前提下有效抑制中点电位偏差。仿真结果表明,该方法不仅确保直流母线电压稳定跟踪800V给定值,还能显著提升上下电容电压的均衡度,同时保持输入电流低谐波水平,验证了控制策略的可行性和有效性。; 适合人群:电力电子、电气自动化及相关专业的研究生、科研人员及工程技术人员,具备一定的MATLAB/Simulink仿真基础和电力电子拓扑知识背景者更佳。; 使用场景及目标:①掌握三电平VIENNA整流器的工作原理与中点电位波动的成因;②理解电压电流双闭环PI控制的设计要点与参数整定原则;③学习基于差值补偿的中点电位平衡控制策略及其与SVPWM的协同机制;④应用于充电桩、航空电源、通信电源等中大功率单向整流场合的控制系统设计与优化。; 阅读建议:建议结合文中提供的仿真模型与参数设置进行动手实践,重点关注中点电位平衡投入前后电容电压波形的变化,对比分析不同工况下的系统动态响应,深入理解控制策略的作用机理。同时可进一步探索在电网不平衡、轻载等复杂工况下的控制性能,以拓展应用场景。

基于变频控制的多相交错LLC谐振变换器闭环仿真(Simulink仿真实现)

内容概要:本文详细介绍了基于变频控制的多相交错LLC谐振变换器的闭环仿真设计,重点阐述了其在Simulink环境下的建模与控制策略。通过多相交错技术有效降低输出纹波电流,提升系统效率与功率密度,并采用变频控制(PFM)实现对谐振变换器输出电压的精确调节。文中构建了完整的闭环控制系统,包含电压外环与电流内环,确保系统在负载变化或输入波动等扰动工况下仍能稳定运行。同时,配套提供了仿真模型、参数设计计算书及参考文献,帮助读者深入理解系统设计流程与关键技术细节,具有较强的工程复现价值。该资源适用于电力电子、新能源变换器等相关领域的仿真研究与教学实践。; 适合人群:具备电力电子基础知识,熟悉Simulink仿真工具,从事电源变换器设计、新能源系统研发或相关专业的研究生及工程技术人员。; 使用场景及目标:①掌握多相交错LLC谐振变换器的工作原理与变频控制机制;②学习并实现基于Simulink的闭环控制系统建模与仿真;③理解谐振参数设计、软开关实现及系统稳定性分析方法;④为科研项目、毕业设计或产品原型开发提供可复用的技术参考与仿真平台。; 阅读建议:建议读者结合提供的仿真模型与计算书,逐步完成系统搭建与参数整定,重点关注变频控制逻辑与闭环响应特性。在仿真过程中,可通过调整负载、输入电压等条件,观察系统的动态响应与稳态性能,加深对多相交错与谐振控制优势的理解。同时推荐参考相关文献,拓展对LLC变换器前沿控制策略的认识。

自适应多机器人编队规划,以包围和跟踪具有运动和可见性约束的目标(Matlab代码实现)

内容概要:本文针对“自适应多机器人编队规划,以包围和跟踪具有运动和可见性约束的目标”开展研究,提出一种基于Matlab的仿真方法,实现多机器人在动态环境中对移动目标的协同包围与持续跟踪。该方法综合考虑了机器人的运动学约束与传感器的视线(visibility)限制,设计了分布式控制策略与自适应编队算法,能够在复杂环境下有效维持编队结构的稳定性和任务执行的鲁棒性。研究详细阐述了系统建模过程、控制律设计原理、编队形成与保持机制,并通过Matlab代码实现了完整的仿真验证,展示了算法在不同动态场景下的适应能力与性能优势; 适合人群:具备机器人学、自动控制理论、多智能体系统等相关基础知识,熟悉Matlab编程语言,从事智能系统、协同控制、路径规划与自主导航等方向的研究生、科研人员及工程技术人员; 使用场景及目标:①应用于安防监控、环境探测、灾害救援等场景中的多机器人目标围捕与跟踪任务;②为多智能体协同控制、分布式编队保持、避障与可见性维护等关键技术提供可复现的算法框架与仿真平台;③辅助高校与科研机构在相关领域的教学演示与科研创新,深化对自适应控制与分布式协同机制的理解; 阅读建议:建议读者结合提供的Matlab代码逐模块分析其实现逻辑,重点关注控制律设计、约束处理与自适应机制部分,可通过调整机器人数量、目标轨迹、传感器参数等进行扩展性实验,以深入掌握多机器人协同系统的动态行为与优化方法。

两路半桥LLC谐振变换器软开关Simulink仿真(模拟谐振参数不同、分裂电容)

内容概要:本文详细介绍了两路半桥LLC谐振变换器软开关的Simulink仿真研究,重点模拟了不同谐振参数及分裂电容对系统性能的影响。通过建立精确的电路模型,分析了软开关实现条件、谐振腔参数变化对电压电流波形、效率及功率传输能力的作用机制,探讨了分裂电容结构在改善均流特性与提升系统稳定性方面的优势。仿真结果有助于深入理解LLC变换器的工作原理与动态响应特性,为高频高效电源设计提供理论支持与优化方向。; 适合人群:电力电子、电气工程及其自动化等相关专业的科研人员、研究生及从事开关电源设计的工程师。; 使用场景及目标:①掌握LLC谐振变换器的基本建模与仿真方法;②研究谐振参数(如谐振电感、电容)对软开关过程的影响规律;③分析分裂电容结构在多路并联变换器中的均流与稳定性作用;④为高频高效DC-DC变换器的设计与优化提供仿真依据和技术参考。; 阅读建议:建议结合Simulink模型逐步操作,关注关键波形的观测点,对比不同参数下的仿真结果,深入理解软开关的实现条件与系统动态特性,同时可进一步拓展至效率分析与热管理设计。

patch_1.23.0.2584_game_No6.android.pak

patch_1.23.0.2584_game_No6.android.pak

状态估计【卡尔曼滤波kalman】UKF、EKF、粒子滤波PF学习与研究(Matlab代码实现)

内容概要:本文系统地研究了无迹卡尔曼滤波(UKF)、扩展卡尔曼滤波(EKF)和粒子滤波(PF)在非线性系统状态估计中的理论基础与实际应用,并结合Matlab代码实现进行了深入剖析。内容涵盖三种滤波算法的核心原理、数学推导及其在轨迹估计等工程问题中的具体实施方法。通过详尽的Matlab编程实例,展示了如何利用这些先进滤波技术解决如目标跟踪、传感器融合等复杂问题,并特别探讨了BP神经网络与EKF结合的优化训练策略以及粒子滤波在提高状态跟踪精度方面的潜力。该资料为希望掌握现代状态估计算法的研究人员和技术爱好者提供了一套完整的理论与实践指南; 适合人群:具备一定编程基础,尤其是熟练使用Matlab工具,且对控制理论、信号处理或相关工程技术领域有初步了解的研发人员和高校学生; 使用场景及目标:① 深入理解UKF、EKF和PF的基本概念及其在非线性动态系统中进行状态变量估计的应用;② 通过Matlab代码实践加深对各滤波器工作机制的理解,能够独立开发相应的算法以应对诸如轨迹预测、多源信息融合等实际挑战;③ 探索将BP神经网络与EKF相结合的新途径,以期提升模型的学习效率和预测准确性; 阅读建议:此资源不仅提供了坚实的理论支撑,还包括丰富的代码示例,建议读者按照文档结构循序渐进地学习,同时动手实现每一个案例,以便更深刻地把握各种滤波技术的关键细节。对于致力于深入研究状态估计领域的专业人士而言,这是一份极具价值的学习材料。

数控基础知识数控加工工序的安排原则

数控基础知识数控加工工序的安排原则

无人机多旋翼倾转动力测试系统-适用于(eVTOL开发、缩比模型测试、科研教育)

LY-QZ-F4多旋翼倾转动力测试系统是全球首款专为倾转四旋翼设计的多自由度动力测试平台,融合高精度传感、动态倾转模拟与智能工况分析,为下一代eVTOL技术提供全维度验证工具。采用航空级应变传感器(精度±0.1% FS),同步捕获推力、扭矩、俯仰/滚转力矩,动态误差<1%。同时测试电驱动系统(单轴最大150kW)与混合动力单元(增程式),支持高压(800V)平台。通过MET数据采集软件,控制采集一体化,定制化,实时观察上百个传感器数据,实时更改测试需求。可搭配六维姿态平台,温湿度舱、振动台等环境模拟设备。

weixin_49209795的博客 877
上一篇: ECE2810J — Data Structures and Algorithms
下一篇: ENG4200 Neural networks
wx____codinghelp
博客等级 码龄2年 771粉丝 115原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值