Skip to content
Snippets Groups Projects
Commit 480c60fa authored by VIGEOLAS-CHOURY Paul's avatar VIGEOLAS-CHOURY Paul
Browse files

Merge branch 'main' into 'gris'

# Conflicts:
#   TP.py
parents 398e7538 005a2d06
No related branches found
No related tags found
1 merge request!1Gris
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -163,21 +163,54 @@ def predictFromHisto(S, model, list_dict=True):
def computeError(S):
"""
Compute the empirical error of the model on the given sample.
:param S: the sample to test
:param S: the sample to test.
:return: the empirical error of the model on the given sample.
"""
error_count = 0
for image in S:
if image["y_true_class"] != image["y_predicted_class"]:
error_count += 1
return error_count
return round(error_count/len(S), 2)
def computeScore(S):
"""
Compute the score of the model on the given sample.
:param S: the sample to test.
:return: the score in percentages of the model on the given sample.
"""
y_true_classes = []
y_predicted_classes = []
for image in S:
y_true_classes.append(image["y_true_class"])
y_predicted_classes.append(image["y_predicted_class"])
return accuracy_score(y_true_classes,y_predicted_classes)
return round(accuracy_score(y_true_classes,y_predicted_classes),2) * 100
def computePredictionFile(classifier):
"""
Compute a file with the predictions of the model.
:param classifier: the classifier to use.
:return: A file .txt with the name of the team, the classifier used, the description methods of images,
the prediction on each image, the empirical error, the real error and the score.
"""
file = open("syntax_error.txt", "w+")
file.write("# T. Bertochio, N. Efremon, P. Vigeolas-Choury (Equipe Syntax Error) \n")
file.write("# Nom de l’algorithme d’apprentissage utilisé \n")
file.write("# Valeurs des hyper-paramètres principaux de l’algorithme \n")
file.write("# Concaténation: histogramme de couleurs, niveaux de gris \n")
S = buildSampleFromPath("./Init/Mer", "./Init/Ailleurs")
classifier, S_test, y_test, S_train, y_train = fitFromHisto(S, classifier)
predictFromHisto(S, classifier)
for image in S:
image_name = os.path.split(image["name_path"])[1]
if image["y_predicted_class"] == 1:
image_predicted_class = "+1"
else:
image_predicted_class = "-1"
file.write(image_name+" "+image_predicted_class+"\n")
file.write("# EE = "+ str(computeError(S_train))+"\n")
file.write("# ER = "+ str(computeError(S_test))+"\n")
file.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment