Advanced Lesson 1
Regular Expressions
Chapter 8: Real world applications
Challenge 1 - I love experiments
Now, let’s put everything you have learnt about regular expressions into practice.
You are given some challenging “real-world” problems with noisy texts, and your task is to use regular expressions to extract the desired information.
Some of these may end up being pretty hacky, but that is how it is with using regular expressions in practice.
Challenge 1: I love experiments
Download these two files:
These are results from scikit-learn
‘s classification_report()
for two classifiers evaluated on different datasets.
Task 1
First load the report content of the file.
Then extract the classification accuracy from the report content using regular expressions.
Test this on both classification1.txt
and classification2.txt
. The accuracy should be 0.89
and 0.85
respectively.
Task 2
Extract the f1-score per class from the same report content using regular expressions. Print out the f1-scores in the following format (example for classification2.txt
):
f1-score for class 0 = 0.88
f1-score for class 1 = 0.82
f1-score for class 2 = 0.87
f1-score for class 3 = 0.82
f1-score for class 4 = 0.83
Test this on from both classification1.txt
and classification2.txt
.
Your code should be general enough to read the results for any number of classes. So it should be able to process both files without you having to specify the number of classes in each dataset.