Skip to content
Snippets Groups Projects
Commit 94d560cf authored by Baptiste Bauvin's avatar Baptiste Bauvin
Browse files

Added model inspection for FSCMLF and tried to homogenize ouptulfile names

parent b71be23a
Branches
Tags
No related merge requests found
...@@ -125,9 +125,9 @@ def initConstants(args, X, classificationIndices, labelsNames, name, directory): ...@@ -125,9 +125,9 @@ def initConstants(args, X, classificationIndices, labelsNames, name, directory):
learningRate = float(len(classificationIndices[0])) / (len(classificationIndices[0]) + len(classificationIndices[1])) learningRate = float(len(classificationIndices[0])) / (len(classificationIndices[0]) + len(classificationIndices[1]))
labelsString = "-".join(labelsNames) labelsString = "-".join(labelsNames)
CL_type_string = CL_type CL_type_string = CL_type
timestr = time.strftime("%Y_%m_%d-%H:%M:%S")
outputFileName = directory + CL_type_string + "/" + feat + "/" + "Results-" + CL_type_string + "-" + labelsString + \ outputFileName = directory + CL_type_string + "/" + feat + "/" + timestr + "-Results-" + CL_type_string + "-" + labelsString + \
'-learnRate' + str(learningRate) + '-' + name + "-" + feat + "-" '-learnRate_{0:.2f}'.format(learningRate) + '-' + name + "-" + feat + "-"
if not os.path.exists(os.path.dirname(outputFileName)): if not os.path.exists(os.path.dirname(outputFileName)):
try: try:
os.makedirs(os.path.dirname(outputFileName)) os.makedirs(os.path.dirname(outputFileName))
......
...@@ -40,12 +40,12 @@ def initConstants(kwargs, classificationIndices, metrics, name, nbCores, KFolds, ...@@ -40,12 +40,12 @@ def initConstants(kwargs, classificationIndices, metrics, name, nbCores, KFolds,
def saveResults(LABELS_DICTIONARY, stringAnalysis, views, classifierModule, classificationKWARGS, directory, learningRate, name, imagesAnalysis): def saveResults(LABELS_DICTIONARY, stringAnalysis, views, classifierModule, classificationKWARGS, directory, learningRate, name, imagesAnalysis):
labelsSet = set(LABELS_DICTIONARY.values()) labelsSet = set(LABELS_DICTIONARY.values())
logging.info(stringAnalysis) logging.info(stringAnalysis)
featureString = "-".join(views) viewsString = "-".join(views)
labelsString = "-".join(labelsSet) labelsString = "-".join(labelsSet)
timestr = time.strftime("%Y%m%d-%H%M%S") timestr = time.strftime("%Y_%m_%d-%H:%M:%S")
CL_type_string = classifierModule.genName(classificationKWARGS) CL_type_string = classifierModule.genName(classificationKWARGS)
outputFileName = directory + "/" + CL_type_string + "/" + timestr + "Results-" + CL_type_string + "-" + featureString + '-' + labelsString + \ outputFileName = directory + "/" + CL_type_string + "/" + timestr + "-Results-" + CL_type_string + "-" + viewsString + '-' + labelsString + \
'-learnRate' + str(learningRate) + '-' + name '-learnRate_{0:.2f}'.format(learningRate) + '-' + name
if not os.path.exists(os.path.dirname(outputFileName)): if not os.path.exists(os.path.dirname(outputFileName)):
try: try:
os.makedirs(os.path.dirname(outputFileName)) os.makedirs(os.path.dirname(outputFileName))
......
...@@ -77,6 +77,6 @@ def execute(classifier, trainLabels, ...@@ -77,6 +77,6 @@ def execute(classifier, trainLabels,
metricsScores = getMetricsScores(metrics, trainLabels, testLabels, metricsScores = getMetricsScores(metrics, trainLabels, testLabels,
validationIndices, learningIndices, labels) validationIndices, learningIndices, labels)
stringAnalysis += printMetricScore(metricsScores, metrics) stringAnalysis += printMetricScore(metricsScores, metrics)
stringAnalysis += "\n\n" + classifier.getSpecificAnalysis(classificationKWARGS) stringAnalysis += "\n\n Interpretation : \n\n" + classifier.getSpecificAnalysis(classificationKWARGS)
imagesAnalysis = {} imagesAnalysis = {}
return stringAnalysis, imagesAnalysis, metricsScores return stringAnalysis, imagesAnalysis, metricsScores
\ No newline at end of file
...@@ -87,7 +87,7 @@ class FatSCMLateFusionClass: ...@@ -87,7 +87,7 @@ class FatSCMLateFusionClass:
return "p : "+str(self.p)+", max_aributes : "+str(self.max_attributes)+", model : "+self.model return "p : "+str(self.p)+", max_aributes : "+str(self.max_attributes)+", model : "+self.model
def getSpecificAnalysis(self, classificationKWARGS): def getSpecificAnalysis(self, classificationKWARGS):
stringAnalysis = '' stringAnalysis = 'Rules used : ' + str(self.SCMClassifier.clf.model_)
return stringAnalysis return stringAnalysis
......
...@@ -126,7 +126,7 @@ def publishMetricsGraphs(metricsScores, directory, databaseName, labelsNames): ...@@ -126,7 +126,7 @@ def publishMetricsGraphs(metricsScores, directory, databaseName, labelsNames):
testScores = metricScores["testScores"] testScores = metricScores["testScores"]
names = metricScores["classifiersNames"] names = metricScores["classifiersNames"]
nbResults = len(testScores) nbResults = len(testScores)
fileName = directory + databaseName +"-"+"vs".join(labelsNames)+ "-" + metricName + ".png" fileName = directory + time.strftime("%Y%m%d-%H%M%S") + databaseName +"-"+"_vs_".join(labelsNames)+ "-" + metricName + ".png"
plotMetricOneIter(trainScores, testScores, names, nbResults, metricName, fileName) plotMetricOneIter(trainScores, testScores, names, nbResults, metricName, fileName)
logging.debug("Done:\t Biclass score graph generation for " + metricName) logging.debug("Done:\t Biclass score graph generation for " + metricName)
...@@ -167,20 +167,20 @@ def publishExampleErrors(exampleErrors, directory, databaseName, labelsNames, mi ...@@ -167,20 +167,20 @@ def publishExampleErrors(exampleErrors, directory, databaseName, labelsNames, mi
borderaxespad=0, borderaxespad=0,
ncol=3) ncol=3)
fig.tight_layout() fig.tight_layout()
fig.savefig(directory + databaseName +"-"+"vs".join(labelsNames)+ "-error_analysis.png", bbox_inches="tight") fig.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + databaseName +"-"+"_vs_".join(labelsNames)+ "-error_analysis.png", bbox_inches="tight")
plt.close() plt.close()
logging.debug("Done:\t Biclass Label analysis figure generation") logging.debug("Done:\t Biclass Label analysis figure generation")
logging.debug("Start:\t Biclass Error by example figure generation") logging.debug("Start:\t Biclass Error by example figure generation")
errorOnExamples = -1*np.sum(data, axis=1)/nbIter+nbClassifiers errorOnExamples = -1*np.sum(data, axis=1)/nbIter+nbClassifiers
np.savetxt(directory + "-clf_errors_doubled.csv", data, delimiter=",") np.savetxt(directory + "clf_errors_doubled.csv", data, delimiter=",")
np.savetxt(directory + "-example_errors.csv", temp_data, delimiter=",") np.savetxt(directory + "example_errors.csv", temp_data, delimiter=",")
fig, ax = plt.subplots() fig, ax = plt.subplots()
x = np.arange(nbExamples) x = np.arange(nbExamples)
plt.bar(x, errorOnExamples) plt.bar(x, errorOnExamples)
plt.ylim([0,nbClassifiers]) plt.ylim([0,nbClassifiers])
plt.title("Number of classifiers that failed to classify each example") plt.title("Number of classifiers that failed to classify each example")
fig.savefig(directory + databaseName +"-"+"vs".join(labelsNames)+ "-example_errors.png") fig.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + databaseName +"-"+"_vs_".join(labelsNames)+ "-example_errors.png")
plt.close() plt.close()
logging.debug("Done:\t Biclass Error by example figure generation") logging.debug("Done:\t Biclass Error by example figure generation")
...@@ -326,20 +326,20 @@ def publishMulticlassExmapleErrors(multiclassResults, directories, databaseName, ...@@ -326,20 +326,20 @@ def publishMulticlassExmapleErrors(multiclassResults, directories, databaseName,
green_patch = mpatches.Patch(color='green', label='Classifier succeded') green_patch = mpatches.Patch(color='green', label='Classifier succeded')
plt.legend(handles=[red_patch, green_patch], bbox_to_anchor=(0,1.02,1,0.2), loc="lower left",mode="expand", borderaxespad=0, ncol=2) plt.legend(handles=[red_patch, green_patch], bbox_to_anchor=(0,1.02,1,0.2), loc="lower left",mode="expand", borderaxespad=0, ncol=2)
fig.tight_layout() fig.tight_layout()
fig.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + "-" + databaseName +"-error_analysis.png", bbox_inches="tight") fig.savefig(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-" + databaseName +"-error_analysis.png", bbox_inches="tight")
plt.close() plt.close()
logging.debug("Done:\t Label analysis figure generation") logging.debug("Done:\t Label analysis figure generation")
logging.debug("Start:\t Error by example figure generation") logging.debug("Start:\t Error by example figure generation")
errorOnExamples = -1*np.sum(data, axis=1)/nbIter+nbClassifiers errorOnExamples = -1*np.sum(data, axis=1)/nbIter+nbClassifiers
np.savetxt(directory + time.strftime("%Y%m%d-%H%M%S") + "-clf_errors_doubled.csv", data, delimiter=",") np.savetxt(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-clf_errors_doubled.csv", data, delimiter=",")
np.savetxt(directory + time.strftime("%Y%m%d-%H%M%S") + "-example_errors.csv", temp_data, delimiter=",") np.savetxt(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-example_errors.csv", temp_data, delimiter=",")
fig, ax = plt.subplots() fig, ax = plt.subplots()
x = np.arange(nbExamples) x = np.arange(nbExamples)
plt.bar(x, errorOnExamples) plt.bar(x, errorOnExamples)
plt.ylim([0,nbClassifiers]) plt.ylim([0,nbClassifiers])
plt.title("Number of classifiers that failed to classify each example") plt.title("Number of classifiers that failed to classify each example")
fig.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + "-" + databaseName +"-example_errors.png") fig.savefig(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-" + databaseName +"-example_errors.png")
plt.close() plt.close()
logging.debug("Done:\t Error by example figure generation") logging.debug("Done:\t Error by example figure generation")
...@@ -451,7 +451,7 @@ def publishIterBiclassMetricsScores(iterResults, directory, labelsDictionary, cl ...@@ -451,7 +451,7 @@ def publishIterBiclassMetricsScores(iterResults, directory, labelsDictionary, cl
ax.set_xticks(np.arange(nbResults) + barWidth) ax.set_xticks(np.arange(nbResults) + barWidth)
ax.set_xticklabels(names, rotation="vertical") ax.set_xticklabels(names, rotation="vertical")
f.tight_layout() f.tight_layout()
f.savefig(currentDirectory + time.strftime("%Y%m%d-%H%M%S") + "-" + dataBaseName + "-Mean_on_" f.savefig(currentDirectory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-" + dataBaseName + "-Mean_on_"
+ str(statsIter) + "_iter-" + metricName + ".png") + str(statsIter) + "_iter-" + metricName + ".png")
plt.close() plt.close()
...@@ -491,7 +491,7 @@ def publishIterBiclassExampleErrors(iterResults, directory, labelsDictionary, cl ...@@ -491,7 +491,7 @@ def publishIterBiclassExampleErrors(iterResults, directory, labelsDictionary, cl
cbar = fig.colorbar(cax, ticks=[-100*statsIter/2, 0, statsIter]) cbar = fig.colorbar(cax, ticks=[-100*statsIter/2, 0, statsIter])
cbar.ax.set_yticklabels(['Unseen', 'Always Wrong', 'Always Right']) cbar.ax.set_yticklabels(['Unseen', 'Always Wrong', 'Always Right'])
fig.tight_layout() fig.tight_layout()
fig.savefig(currentDirectory + time.strftime("%Y%m%d-%H%M%S") + "-error_analysis.png") fig.savefig(currentDirectory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-error_analysis.png")
plt.close() plt.close()
logging.debug("Done:\t Global label analysis figure generation") logging.debug("Done:\t Global label analysis figure generation")
...@@ -542,7 +542,7 @@ def publishIterMulticlassMetricsScores(iterMulticlassResults, classifiersNames, ...@@ -542,7 +542,7 @@ def publishIterMulticlassMetricsScores(iterMulticlassResults, classifiersNames,
ax.set_xticks(np.arange(nbResults) + barWidth) ax.set_xticks(np.arange(nbResults) + barWidth)
ax.set_xticklabels(names, rotation="vertical") ax.set_xticklabels(names, rotation="vertical")
f.tight_layout() f.tight_layout()
f.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + "-" + dataBaseName + "-Mean_on_" f.savefig(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-" + dataBaseName + "-Mean_on_"
+ str(statsIter) + "_iter-" + metricName + ".png") + str(statsIter) + "_iter-" + metricName + ".png")
plt.close() plt.close()
...@@ -570,14 +570,14 @@ def publishIterMulticlassExampleErrors(iterMulticlassResults, directory, classif ...@@ -570,14 +570,14 @@ def publishIterMulticlassExampleErrors(iterMulticlassResults, directory, classif
logging.debug("Start:\t Global error by example figure generation") logging.debug("Start:\t Global error by example figure generation")
errorOnExamples = -1 * np.sum(data, axis=1) + (nbClassifiers*statsIter) errorOnExamples = -1 * np.sum(data, axis=1) + (nbClassifiers*statsIter)
np.savetxt(directory + time.strftime("%Y%m%d-%H%M%S") + "-clf_errors.csv", data, delimiter=",") np.savetxt(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-clf_errors.csv", data, delimiter=",")
np.savetxt(directory + time.strftime("%Y%m%d-%H%M%S") + "-example_errors.csv", errorOnExamples, delimiter=",") np.savetxt(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-example_errors.csv", errorOnExamples, delimiter=",")
fig, ax = plt.subplots() fig, ax = plt.subplots()
x = np.arange(nbExamples) x = np.arange(nbExamples)
plt.bar(x, errorOnExamples) plt.bar(x, errorOnExamples)
plt.ylim([0,nbClassifiers*statsIter]) plt.ylim([0,nbClassifiers*statsIter])
plt.title("Number of classifiers that failed to classify each example") plt.title("Number of classifiers that failed to classify each example")
fig.savefig(directory + time.strftime("%Y%m%d-%H%M%S") + "-example_errors.png") fig.savefig(directory + time.strftime("%Y_%m_%d-%H:%M:%S") + "-example_errors.png")
plt.close() plt.close()
logging.debug("Done:\t Global error by example figure generation") logging.debug("Done:\t Global error by example figure generation")
......
...@@ -21,12 +21,12 @@ def getFeatureImportance(classifier, directory, interpretString=""): ...@@ -21,12 +21,12 @@ def getFeatureImportance(classifier, directory, interpretString=""):
ax.yaxis.set_major_formatter(formatter) ax.yaxis.set_major_formatter(formatter)
plt.bar(x, featureImportancesSorted) plt.bar(x, featureImportancesSorted)
plt.title("Importance depending on feature") plt.title("Importance depending on feature")
fig.savefig(directory + "-feature_importances.png") fig.savefig(directory + "feature_importances.png")
plt.close() plt.close()
featuresImportancesDict = dict((featureIndex, featureImportance) featuresImportancesDict = dict((featureIndex, featureImportance)
for featureIndex, featureImportance in enumerate(featureImportances) for featureIndex, featureImportance in enumerate(featureImportances)
if featureImportance != 0) if featureImportance != 0)
with open(directory+'-feature_importances.pickle', 'wb') as handle: with open(directory+'feature_importances.pickle', 'wb') as handle:
pickle.dump(featuresImportancesDict, handle) pickle.dump(featuresImportancesDict, handle)
interpretString += "Feature importances : \n" interpretString += "Feature importances : \n"
for featureIndex, featureImportance in zip(featureIndicesSorted, featureImportancesSorted): for featureIndex, featureImportance in zip(featureIndicesSorted, featureImportancesSorted):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment