0
ML Course (Python)
Hey there, I wanted to ask, if anyone has the same problem like me with solving the Code Projects 28 and 37 of the above mentioned course. The problem is, that merely hidden test cases don’t work fine, so I can’t tell, what could be the problem. In both projects you just have to implement formulas, which I have implemented correctly (in my opinion, especially after checking the non-hidden test cases). https://code.sololearn.com/cM3JiMxQ86Rq/?ref=app https://code.sololearn.com/cvM5dy5lyv7f/?ref=app
9 odpowiedzi
+ 1
https://code.sololearn.com/csQkqNgHsS2y/?ref=app
Sometimes, the way you put things in a code leads to slightly different results.
I think your formula is fine. So I decided to test the positioning of the code (see my attachment).
I did the rather slow (and stupid) thing of typing in random numbers and I managed to find that I received a different result in 1 case.
Perhaps it's that.
There are way smarter people here than I am. If my version doesn't help, I'll call on them for you 😄
+ 3
You could Ceil instead of round...
Without the task, it's hard to say.
+ 1
Ok, I see that round is needed.
The hidden test cases is to stop people "hard coding" an answer that they can see and instead think of a code that works for all instances of the problem.
An example (a poor one probably):
Create a program that adds 2 numbers.
Answer = 4.
The programmer should take 2 inputs: x & y and then add them and output that result.
However, if the answer is supplied as "4", a poor programmer can simply output 4 and pass.
Sorry for the rant.
I'll see if I get a chance to check your codes. 😉
+ 1
Zum Glück!
Sehr gerne.
0
28
Calculating Evaluation Metrics using the Confusion Matrix.
Task
You will be given the values of the confusion matrix (true positives, false positives, false negatives, and true negatives). Your job is to compute the accuracy, precision, recall and f1 score and print the values rounded to 4 decimal places. To round, you can use round(x, 4).
Input Format
The values of tp, fp, fn, tn, in that order separated by spaces
Output Format
Each value on its own line, rounded to 4 decimal places, in this order:
accuracy, precision, recall, f1 score
Sample Input
233 65 109 480
Sample Output
0.8038
0.7819
0.6813
0.7281
Explanation
Accuracy is (tp + tn) / total = (233+480)/(233+65+109+480)=0.8038
Precision is tp / (tp + fp) = 233/(233+65) = 0.7819
Recall is tp / (tp + fn) = 233/(233+109) = 0.6813
F1 score is 2 * precision * recall / (precision + recall) = 2*0.7819*0.6813/(0.7819+0.6813) = 0.7281
0
37
Calculate Information Gain.
Task
Given a dataset and a split of the dataset, calculate the information gain using the gini impurity.
The first line of the input is a list of the target values in the initial dataset. The second line is the target values of the left split and the third line is the target values of the right split.
Round your result to 5 decimal places. You can use round(x, 5).
Input Format
Three lines of 1's and 0's separated by spaces
Output Format
Float (rounded to 5 decimal places)
Sample Input
1 0 1 0 1 0
1 1 1
0 0 0
Sample Output
0.5
Explanation
The initial set has 3 positive cases and 3 negative cases. Thus the gini impurity is 2*0.5*0.5=0.5.
The left set has 3 positive cases and 0 negative cases. Thus the gini impurity is 2*1*0=0.
The right set has 0 positive cases and 3 negative cases. Thus the gini impurity is 2*0*1=0.
The information gain is 0.5-0-0=0.5
0
Hey, thanks for your answers so far.
Ausgrindtube as you can see in the task description posted by Yaroslav, you should use the round Method.
Does a way exist to look up the hidden test cases?
0
Hey, no problem. I‘m just grateful that you are trying to help me.
0
It worked 🙈 thank you very much :D