Commit b983ea7e authored by Antoine PIGEAU's avatar Antoine PIGEAU
Browse files

update with standard variation

parent 49f0dd7a
......@@ -261,11 +261,11 @@ class ScriptClassifier:
if os.path.exists(fileNameSavedResult) and cache:
with open(fileNameSavedResult, "rb") as fileResult:
(accuracy, confusionMatrice, dictResultWeight, auc) = pickle.load(fileResult)
(accuracy, confusionMatrice, dictResultWeight, auc, stdAcurracy, stdAuc) = pickle.load(fileResult)
print(str(fileNameSavedResult)+" is already done")
return (accuracy, confusionMatrice, dictResultWeight, auc)
return (accuracy, confusionMatrice, dictResultWeight, auc, stdAcurracy, stdAuc)
#self.classifier.testIdCourse = testIdCourse
......@@ -291,12 +291,14 @@ class ScriptClassifier:
confusionMatrice = confusionMatrice / float(ntime)
s = np.sum(confusionMatrice, axis=0)
confusionMatrice = confusionMatrice / s
stdAccuracy = np.std(accuracys)
stdDAuc = np.std(aucScores)
if cache:
with open(fileNameSavedResult, "wb") as fileResult:
pickle.dump((np.average(accuracys), confusionMatrice, dictResultWeight, np.nanmean(aucScores)), fileResult)
pickle.dump((np.average(accuracys), confusionMatrice, dictResultWeight, np.nanmean(aucScores), stdAccuracy, stdDAuc), fileResult)
return (np.average(accuracys), confusionMatrice, dictResultWeight, np.nanmean(aucScores))
return (np.average(accuracys), confusionMatrice, dictResultWeight, np.nanmean(aucScores), stdAccuracy, stdDAuc)
def setFeatures(self, course=None, whereToCut=None):
......@@ -333,7 +335,7 @@ class ScriptClassifier:
self.setFeatures(course, whereToCut)
(accuracy, confusionMatrix, dictWeight, aucScore) = self.predictionTaskNTimes(
(accuracy, confusionMatrix, dictWeight, aucScore, _, _) = self.predictionTaskNTimes(
course,
whereToCut=whereToCut,
ntime=ntime)
......@@ -365,7 +367,9 @@ class ScriptClassifier:
scoreFinal = np.average(accuracies)
stdAccuracy = np.std(accuracies)
aucScoreFinal = np.nanmean(aucScores)
stdAuc = np.std(aucScores)
fileResult.write("\n final Accuracy("+str(scoreFinal)+")")
fileResult.write("\n final AUC ("+str(aucScoreFinal)+") \n")
......@@ -392,7 +396,7 @@ class ScriptClassifier:
fileResult.write(str(resultWeigth))
return (accuracies, accuracysPerClass, aucScores)
return (accuracies, accuracysPerClass, aucScores, stdAccuracy, stdAuc)
def predictionTaskForAllPeriods(self, ntime = 10):
......@@ -406,7 +410,7 @@ class ScriptClassifier:
for t in self.classifier.whereToCuts:
accuracies, accuracysPerClass, rocScores = self.predictionTaskForAllCourses(t, ntime)
accuracies, accuracysPerClass, aucScores, stdAccuracy, stdAuc = self.predictionTaskForAllCourses(t, ntime)
for i, idCourse in enumerate(self.classifier.getIdCourses()): #
......@@ -415,7 +419,7 @@ class ScriptClassifier:
if not scoresCourse:
dictResult[idCourse] = scoresCourse
scoresCourse.append((accuracies[i], accuracysPerClass[i], rocScores[i]))
scoresCourse.append((accuracies[i], accuracysPerClass[i], aucScores[i]))
fileNameSavedResult = os.path.join(self.directoryExperiment,
self.fileName+
......@@ -433,7 +437,7 @@ class ScriptClassifier:
self.classifier.getFeatures(),
self.classifier.getWhereToCuts,
self.classifier.getWhereToCutUnity(),
groups), fileResult)
groups, stdAccuracy, stdAuc), fileResult)
fileNameResultAccuracy = os.path.join(self.directoryExperiment,
"Latex"+
......
......@@ -42,10 +42,10 @@ if __name__ == "__main__":
classifier = Classifier(idCourses = ConstantModel.ID_COURSES,
nameGroups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS],
features = None,
features = ConstantFeature.IMPLEMENTED_FEATURES,
typeFeatureGroup = ConstantFeature.TYPE_FEATURE_GROUP,
hiddenLayers = None,
featuresByCourse = ConstantFeature.BEST_LR_FEATURE_ALL_COURSES,
featuresByCourse = None,
featuresByPeriod = None)
# classifier = Classifier(idCourses=ConstantModel.ID_COURSES,
......@@ -54,7 +54,7 @@ if __name__ == "__main__":
# typeFeatureGroup = ConstantFeature.TYPE_FEATURE_GROUP_SEQUENTIAL_N,
# hiddenLayers=[16])
classifier.setScriptClassifier(ConstantClassifier.LogisticRegression)
classifier.setScriptClassifier(ConstantClassifier.AdaBoost)
'''
......@@ -63,8 +63,8 @@ if __name__ == "__main__":
'''
# course = Course(ConstantModel.COURSE_ID_ARDUINO)
# groups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS]
course = Course(ConstantModel.COURSE_ID_ARDUINO)
groups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS]
''' classification one time '''
......@@ -73,30 +73,34 @@ if __name__ == "__main__":
# print(confusionMatrix)
# print("epochOrWeight="+str(weightOrEpoch))
# print("auc="+str(rocScore))
''' classification N times '''
# (accuracy, confusionMatrix, weightOrEpoch, rocScore) = classifier.predictionTaskNTimes(course,
# (accuracy, confusionMatrix, weightOrEpoch, rocScore, stdAccuracy, stdAuc) = classifier.predictionTaskNTimes(course,
# whereToCut=25,
# ntime=1,
# cache = False)
# ntime=10,
# cache = True)
# print("accuracy: ", accuracy)
# print("std accuracy: ", stdAccuracy)
# print("confusion Matrix:\n", confusionMatrix)
# print("Weight or Epoch: ", weightOrEpoch)
# print("AUC score: ", rocScore)
# print("std AUC:", stdAuc)
''' for all courses '''
# (accuracies, accuracysPerClass, aucScores) = classifier.predictionTaskForAllCourses(whereToCut=25, ntime=10)
# print("accuracy: ", accuracies)
# print("accuracy per class:\n", accuracysPerClass)
# print("AUC scores: ", aucScores)
(accuracies, accuracysPerClass, aucScores, stdAccuracy, stdAuc) = classifier.predictionTaskForAllCourses(whereToCut=100, ntime=10)
print("accuracy: ", accuracies)
print("std accuracy: ", stdAccuracy)
print("accuracy per class:\n", accuracysPerClass)
print("AUC scores: ", aucScores)
print("std AUC: ", stdAuc)
''' for all periods '''
classifier.predictionTaskForAllPeriods(ntime=10)
# classifier.predictionTaskForAllPeriods(ntime=10)
''' NN : all courses with hidden layers'''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment