r/learnpython • u/Chemical_Holiday_503 • 8d ago
Can anyone help me with my homework
I’m taking into to programming right now and I’m very confused on what to do and my professor is no help can anyone help explain to me what to do for these questions. The question are
- Write a script that determines on its own whether each text is spam or ham WITHOUT using the first column at all. You should only be reading from the second column of the file as you make this decision. The decision will be a sequence of if statements that you write. Try to determine what generic qualities of a text message determine if it is spam or not. One possible rule would be "contains two or more fully capitalized words." Read through the file and see if you can come up with the best rules.
- Once you've come up with your rules, determine how good they are! Compare whether your script got the decision right. Add up the number of correct classifications and divide that by the total lines in the file. This will give you the accuracy of your script. Output this value. If you are not happy with it, edit your rules. When you submit, ensure your accuracy is at least 90%
link to data set
Any help would be really appreciated.
0
Upvotes
9
u/aqua_regis 8d ago
Start by telling and showing us what you have tried and where exactly you are stuck.
Can you read a line in a file? Can you test for two or more fully capitalized words?
2
u/Cold_Arachnid_2617 8d ago
You lazy student, do your own homework!
1
u/Sure-Passion2224 8d ago
Looks like you need to read a text file line by line, and each line represents 2 or more columns of data, possibly comma or tab delimited text. You are to parse each line and apply some sort of logic to a specific column, then document the results. Be aware of a possible need to either account for or ignore UPPER/lower case.
You should work with the language(s) discussed in class but this is relatively easy as either a bash shell script, or using Perl.
Once you can define the process this is a quickie in ChatGPT but you damned well better be able to describe what each line of generated code is doing. When you eventually (hopefully) land a coding job you will have to be able to discuss your code in peer review.
1
u/MarsupialLeast145 8d ago
You need to parse a CSV and read just the data in the second column.
For every row it reads, you need to validate it against a set of rules (probably each in their own function to be manageable and follow SOLID principles)
These rules allow you to classify the text, so each function might return true or false, e.g. true for SPAM, and if you get a single false, you need to return to the main loop, and identify the text as SPAM.
You have over 200 rows, so you should probably have an additional check against column one to see if the guess was correct at the end and output a percentage. Don't fail anything if you get this wrong, just always output a percentage at the end so you can see it go up.
Start by getting this working with just a dummy check. It will output 0% correct.
As you progress, add a new check, make sure the percentage goes up.
1
u/mjmvideos 8d ago
This seems relatively straightforward.
1
u/patryk_builds 8d ago
The task sounds bigger than it is. break it into three small steps and do them in order.
Then improve the rules by looking at what you got wrong. print the spam messages your function missed and read twenty of them. you'll see patterns fast: words like free, win, call now, long numbers, links, currency signs. each pattern is one more if. One tip before you start: check what accuracy you get by answering ham for everything. in most of these datasets spam is a small share, so that baseline is already high, and it tells you how far your rules really have to carry you to reach 90