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

resolve nan problem in results

parent 75e3e312
......@@ -294,6 +294,11 @@ class ScriptClassifier:
result = self.predictionTask(course,
whereToCut=whereToCut)
print('*********************************')
if (self.classifier.testIdCourse == '3432066'):
print(result)
print('*********************************')
accuracies.append(result.accuracy)
aucScores.append(result.auc)
......@@ -574,7 +579,7 @@ class ScriptClassifier:
with open(fileNameResult, 'w') as fileResult:
for course in mergedCourse.getCourses(): #[Course.COURSE_ID_ARDUINO, Course.COURSE_ID_AUDACE]
for course in mergedCourse.getCourses(): #[dictCourse['26832']] : # #
self.classifier.testIdCourse = course.getCourseId()
......
......@@ -245,7 +245,7 @@ def exportTransfertLearningResult(fileName, dictResult):
for t in [25, 50, 75, 100]:
auc, accuracy, number = resultModel[t]
auc = round(auc,2)
auc = round(auc,3)
accuracy = round(accuracy, 2)
fileResult.write(str(auc)+" & "+str(accuracy)+" & "+str(number))
......
......@@ -58,17 +58,7 @@ if __name__ == "__main__":
classifier.setScriptClassifier(ConstantClassifier.LogisticRegression)
classifier = Classifier.getClassifierLR()
classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
classifier = Classifier.getClassifierAdaBoost()
classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
classifier = Classifier.getClassifierRandomForest()
classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
classifier = Classifier.getClassifierPerceptron()
classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
'''
classification task process
......@@ -90,19 +80,20 @@ if __name__ == "__main__":
''' classification N times '''
# classifier.features = ConstantFeature.BEST_LR_FEATURE_ALL_COURSES[course.getCourseId()][25]
#
# result = classifier.predictionTaskNTimes(course,
# whereToCut=25,
# ntime=10,
# cache = False)
#
# print("accuracy: ", np.nanmean(result.accuracies))
# print("std accuracy: ", np.std(result.accuracies))
# print("confusion Matrix:\n", result.avgConfusionMatrix)
# print("AUC score: ", np.nanmean(result.aucs))
# print("std AUC:", np.std(result.aucs))
# print("dictWeight:", result.dictWeight)
# course = Course(ConstantModel.COURSE_ID_RUBY)
# classifier.features = ConstantFeature.BEST_LR_FEATURE_ALL_COURSES[course.getCourseId()][50]
#
# result = classifier.predictionTaskNTimes(course,
# whereToCut=50,
# ntime=10,
# cache = False)
#
# print("accuracy: ", np.nanmean(result.accuracies))
# print("std accuracy: ", np.std(result.accuracies))
# print("confusion Matrix:\n", result.avgConfusionMatrix)
# print("AUC score: ", np.nanmean(result.aucs))
# print("std AUC:", np.std(result.aucs))
# print("dictWeight:", result.dictWeight)
......@@ -120,6 +111,18 @@ if __name__ == "__main__":
''' for all periods '''
#classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
# classifier = Classifier.getClassifierLR()
# classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
#
# classifier = Classifier.getClassifierAdaBoost()
# classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
#
# classifier = Classifier.getClassifierRandomForest()
# classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
#
# classifier = Classifier.getClassifierPerceptron()
# classifier.predictionTaskForAllPeriods(ntime=10, cache=True)
''' NN : all courses with hidden layers'''
......
......@@ -38,32 +38,32 @@ if __name__ == "__main__":
print("start of the process boosting")
startTime = datetime.now()
classifier = Classifier(idCourses = ConstantModel.ID_COURSES,
directory = Classifier.DIRECTORY_EXPERIMENT_MERGED,
nameGroups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS],
features = None,
typeFeatureGroup = ConstantFeature.TYPE_FEATURE_GROUP,
hiddenLayers = None,
featuresByPeriod = ConstantFeature.BEST_LR_FEATURE_MERGED_ALL_PERIODS,
featuresByCourse= None )#ConstantFeature.IMPLEMENTED_FEATURES_FORWARD_BEST_MERGED_LR)
classifier.setScriptClassifier(ConstantClassifier.LogisticRegression)
# classifier = Classifier(idCourses = ConstantModel.ID_COURSES,
# directory = Classifier.DIRECTORY_EXPERIMENT_MERGED,
# nameGroups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS],
# features = None,
# typeFeatureGroup = ConstantFeature.TYPE_FEATURE_GROUP,
# hiddenLayers = None,
# featuresByPeriod = ConstantFeature.BEST_LR_FEATURE_MERGED_ALL_PERIODS,
# featuresByCourse= None )#ConstantFeature.IMPLEMENTED_FEATURES_FORWARD_BEST_MERGED_LR)
#
# classifier.setScriptClassifier(ConstantClassifier.LogisticRegression)
classifier = Classifier.getClassifierLRMerge()
'''
Creation of the merged course with all the courses
'''
courses = []
# dictCourses = {}
dictCourses = {}
for idCourse in ConstantModel.ID_COURSES:
course = Course(idCourse, granularity=ConstantModel.CHAPTER)
courses.append(course)
# dictCourses[idCourse] = course
dictCourses[idCourse] = course
mergedCourse = MergedCourse(courses)
......@@ -73,19 +73,19 @@ if __name__ == "__main__":
''' classification one time '''
# groups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS]
# whereToCut=25
#
# classifier.testCourseId = ConstantModel.COURSE_ID_GESTION_PROJET
# classifier.scriptClassifier.setFeatures(dictCourses[classifier.testCourseId], whereToCut)
#
# #(accuracy, confusionMatrix, weightOrEpoch, rocScore) = classifier.predictionTaskNTimes(mergedCourse, whereToCut=25, cache = False)
# resultCourse = classifier.predictionTaskNTimes(mergedCourse, whereToCut=whereToCut, cache = False)
# #(accuracy, confusionMatrix, weightOrEpoch, rocScore) = classifier.predictionTask(mergedCourse, whereToCut=25)
# print("accuracy="+str(np.nanmean(resultCourse.accuracies)))
# #print(confusionMatrix)
# #print("weightOrEpoch="+str(weightOrEpoch))
# print("auc="+str(np.nanmean(resultCourse.aucs)))
# groups = [ConstantModel.GROUP_SUCCEED_ALL_USERS, ConstantModel.GROUP_FAILED_ALL_USERS]
# whereToCut=100
#
# classifier.testCourseId = ConstantModel.COURSE_ID_RUBY
# classifier.scriptClassifier.setFeatures(dictCourses[classifier.testCourseId], whereToCut)
#
# #(accuracy, confusionMatrix, weightOrEpoch, rocScore) = classifier.predictionTaskNTimes(mergedCourse, whereToCut=25, cache = False)
# resultCourse = classifier.predictionTaskNTimes(mergedCourse, whereToCut=whereToCut, ntime=10, cache = True)
# #(accuracy, confusionMatrix, weightOrEpoch, rocScore) = classifier.predictionTask(mergedCourse, whereToCut=25)
# print("accuracy="+str(np.nanmean(resultCourse.accuracies)))
# #print(confusionMatrix)
# #print("weightOrEpoch="+str(weightOrEpoch))
# print("auc="+str(np.nanmean(resultCourse.aucs)))
''' classification n-times for a specific period '''
......@@ -96,7 +96,7 @@ if __name__ == "__main__":
''' classification for all periods '''
classifier = Classifier.getClassifierLRMerge()
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=1, cache=True)
classifier = Classifier.getClassifierAdaBoostMerge()
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
......@@ -108,8 +108,6 @@ if __name__ == "__main__":
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
print("result=", dictResult)
'''
Best features for LR
'''
......
......@@ -140,9 +140,18 @@ if __name__ == "__main__":
howBetterAucs.append(howBetterAuc)
howBetterAccuracys.append(howBetterAccuracy)
print(key+" Course Improved with transfert learning #[", len(coursesImproved),", ", np.mean(howBetterAucs), ", ", np.mean(howBetterAccuracys) ,"] : " , coursesImproved)
howBetterAuc = np.nanmean(howBetterAucs)
dictOutput[key][t] = [np.mean(howBetterAucs), np.mean(howBetterAccuracys), len(coursesImproved)]
if np.isnan(howBetterAuc) :
howBetterAuc = 0.0
howBetterAccuracy = np.nanmean(howBetterAccuracys)
if np.isnan(howBetterAccuracy) :
howBetterAccuracy = 0.0
print(key+" Course Improved with transfert learning #[", len(coursesImproved),", ", howBetterAuc, ", ", howBetterAccuracy ,"] : " , coursesImproved)
dictOutput[key][t] = [howBetterAuc, howBetterAccuracy, len(coursesImproved)]
fileNameResult = os.path.join(ProjectParameters.DIRECTORY_EXPERIMENT,
......
......@@ -68,7 +68,7 @@ if __name__ == "__main__":
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
classifier = Classifier.getClassifierAdaBoostMerge()
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=False)
classifier = Classifier.getClassifierRandomForestMerge()
dictResult = classifier.predictionTaskForMergedForAllPeriods(mergedCourse, ntime=10, cache=True)
......
......@@ -140,10 +140,19 @@ if __name__ == "__main__":
coursesImproved.append((idCourse, howBetterAuc, howBetterAccuracy))
howBetterAucs.append(howBetterAuc)
howBetterAccuracys.append(howBetterAccuracy)
howBetterAuc = np.nanmean(howBetterAucs)
print(key+" Course Improved with transfert learning #[", len(coursesImproved),", ", np.mean(howBetterAucs), ", ", np.mean(howBetterAccuracys) ,"] : " , coursesImproved)
if np.isnan(howBetterAuc) :
howBetterAuc = 0.0
howBetterAccuracy = np.nanmean(howBetterAccuracys)
if np.isnan(howBetterAccuracy) :
howBetterAccuracy = 0.0
print(key+" Course Improved with transfert learning #[", len(coursesImproved),", ", howBetterAuc, ", ", howBetterAccuracy ,"] : " , coursesImproved)
dictOutput[key][t] = [np.mean(howBetterAucs), np.mean(howBetterAccuracys), len(coursesImproved)]
dictOutput[key][t] = [howBetterAuc, howBetterAccuracy, len(coursesImproved)]
fileNameResult = os.path.join(ProjectParameters.DIRECTORY_EXPERIMENT,
......
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