-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data Evaluation #3
Comments
# using inside and outside to calculate the accuracy by Mean Square Error, (inside - outside)^2 is the MSE
# inside: the list of the inside data
# outside: the list of the outside data
# return: the accuracy of the model
def evaluation(inside, outside,data_name,model_name):
# iterate the inside and outside data
print(len(inside),len(outside))
for i in range(len(inside)):
# reshape the inside and outside data to 1D array
inside_single = inside[i].reshape(1, -1)[0]
outside_single = outside[i].reshape(1, -1)[0]
# calculate the MSE, MAE, corelation
# print(MSE(inside_single, outside_single), MAE(inside_single, outside_single), corelation(inside_single, outside_single))
# save to .csv file
# MSE, MAE, corelation should be in the same table
# the first column is the data_name, the second column is the MSE, the third column is the MAE, the fourth column is the corelation
# if the file is not exist, create the file and write the first line
if not os.path.exists('evaluation.csv'):
with open('evaluation.csv', 'w') as f:
f.write('data_name,MSE,MAE,corelation\n')
# write the data to the file
with open('evaluation.csv', 'a') as f:
f.write(data_name[i] + ',' + str(MSE(inside_single, outside_single)) + ',' + str(MAE(inside_single, outside_single)) + ',' + str(corelation(inside_single, outside_single)) + '\n')
with open('evaluation.csv', 'a') as f:
inside_mean = np.mean(inside, axis=0).reshape(1, -1)[0]
outside_mean = np.mean(outside, axis=0).reshape(1, -1)[0]
print(inside_mean)
f.write(model_name+'average' + ',' + str(MSE(inside_mean, outside_mean)) + ',' + str(MAE(inside_mean, outside_mean)) + ',' + str(corelation(inside_mean, outside_mean)) + '\n')
return 0
def MSE(inside, outside):
# L2 norm
return np.square(np.subtract(inside, outside)).mean()
def MAE(inside, outside):
# L1 norm
return np.abs(np.subtract(inside, outside)).mean()
def corelation(inside, outside):
return np.corrcoef(inside, outside)[0, 1] |
Result: Compare with U-Net and OBS
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using MSE, MAE and correlation to compare with U-Net and OBS.
The Evaluation Function is attached below.
The text was updated successfully, but these errors were encountered: