0
0
TensorFlowml~10 mins

Error analysis patterns in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to calculate the mean absolute error between true and predicted values.

TensorFlow
from sklearn.metrics import [1]
true = [3, -0.5, 2, 7]
pred = [2.5, 0.0, 2, 8]
error = [1](true, pred)
print(error)
Drag options to blanks, or click blank then click option'
Aaccuracy_score
Bmean_squared_error
Cr2_score
Dmean_absolute_error
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean_squared_error which squares errors instead of absolute values.
Using accuracy_score which is for classification, not regression.
2fill in blank
medium

Complete the code to identify samples where the prediction error is greater than 1.0.

TensorFlow
errors = [abs(t - p) for t, p in zip(true, pred)]
high_error_indices = [i for i, e in enumerate(errors) if e [1] 1.0]
print(high_error_indices)
Drag options to blanks, or click blank then click option'
A>
B<=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < which selects small errors instead of large ones.
Using == which only selects errors exactly equal to 1.0.
3fill in blank
hard

Fix the error in the code to compute residuals (difference between true and predicted values).

TensorFlow
residuals = [true[i] [1] pred[i] for i in range(len(true))]
print(residuals)
Drag options to blanks, or click blank then click option'
A+
B*
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding true and predicted values instead of subtracting.
Multiplying or dividing which do not represent residuals.
4fill in blank
hard

Fill both blanks to create a dictionary of samples with residuals greater than 0.5.

TensorFlow
large_residuals = {i: residuals[i] for i in range(len(residuals)) if abs(residuals[i]) [1] 0.5 and residuals[i] [2] 0}
print(large_residuals)
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using < which selects smaller residuals.
Using == which only selects exact values.
5fill in blank
hard

Fill all three blanks to create a dictionary of samples where the residual is negative and its absolute value is greater than 0.7.

TensorFlow
negative_large_residuals = {i: residuals[i] for i in range(len(residuals)) if residuals[i] [1] 0 and abs(residuals[i]) [2] 0.7 and residuals[i] [3] -1}
print(negative_large_residuals)
Drag options to blanks, or click blank then click option'
A<
B>
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < for negative check.
Using == which restricts to exact values.