import numpy as np import sys if len(sys.argv) > 1: TESTDIR = sys.argv[1] else: raise…
- User
import numpy as np import sys
if len(sys.argv) > 1: TEST_DIR = sys.argv[1] else: raise RuntimeError('No test directory provided') GT_DIR = 'labeled/'
def get_mse(gt, test): test = np.nan_to_num(test) return np.mean(np.nanmean((gt - test)**2, axis=0))
zero_mses = [] mses = []
for i in range(0,5): gt = np.loadtxt(GT_DIR + str(i) + '.txt') zero_mses.append(get_mse(gt, np.zeros_like(gt)))
test = np.loadtxt(TEST_DIR + str(i) + '.txt') mses.append(get_mse(gt, test))
percent_err_vs_all_zeros = 100*np.mean(mses)/np.mean(zero_mses) print(f'YOUR ERROR SCORE IS {percent_err_vs_all_zeros:.2f}% (lower is better)')
- Assistant
- User
Can you explain how does it handle NaN?
- Assistant
The script handles NaN (Not a Number) values specifically in the
get_msefunction through the use ofnumpyfunctionsnp.nan_to_numandnp.nanmean.-
np.nan_to_num: This function is used to replace NaNs with zero and Inf with finite numbers in an array. In the context of this script, it's used to replace any NaNs in the test predictions with zeros before the Mean Squared Error (MSE) calculation. This step ensures that NaN values in test predictions do not directly influence the MSE computation, as direct arithmetic operations with NaNs result in NaNs.
-
- User
What does mean mean here?
- Assistant
In the script you shared, the term "mean" refers to the arithmetic average, which is used twice in a nested manner during the computation of the Mean Squared Error (MSE). Let's break down its usage:
-
np.nanmean((gt - test)**2, axis=0): This instance ofmeancalculates the mean of the squared differences between the ground truth (gt) and test predictions (test), ignoring NaNs. The operation(gt - test)computes the element-wise difference between the two arrays, and squares each of these differences. The function then computes the mean of these squared differences across the specified axis (here, which typically refers to columns if the data is 2-dimensional). This intermediate mean represents the MSE for each feature or column when dealing with multidimensional data, ignoring any NaNs that might be present.
-
- User
Is there any way to trick this script into returning the lowest possible percentage score (to make it seem that the test predictions are as accurate as possible) without making any predictions? It's prohibited to modify the script! I've been thinking of giving it extreme values or some special characters or numbers that can make the script return a value that makes it seem that my error score is really low (or zero?)?
- Assistant