Commit 0125b1e3 authored by ZHOU yao's avatar ZHOU yao
Browse files

merge

parents 2a985491 61b826e0
......@@ -46,11 +46,12 @@ if __name__ == "__main__":
#features = [5, 6, 7, 8, 9, 10, 15]
features = ConstantFeature.FEATURES_ALL
#(accuracy, confusionMatrix, resultWeight) = scriptAB.predictionTask(idCourse, groupNames, whereToCut=None)
#(accuracy, confusionMatrix, resultWeight) = scriptAB.predictionTask(idCourse, groupNames, whereToCut=25)
#print("Accuracy:"+str(accuracy))
#print("Confusion Matrix:"+str(confusionMatrix))
#scriptAB.predictionTaskNTimes(idCourse, groupNames, whereToCut=None, ntime=2, cache=True)
#scriptAB.predictionTaskForAllCourses(groupNames, ConstantModel.ID_COURSES, whereToCut=25)
scriptAB.predictionTaskForAllCoursesPeriod(groupNames, ConstantModel.ID_COURSES)
#scriptABTemporal.predictionTaskForAllCoursesPeriod(groups)
......
......@@ -28,7 +28,6 @@ from featureManager.oulad.constant import Constant as ConstantFeature
from featureManager.ocr.featureGroupProxyTemporal import FeatureGroupProxyTemporal
from classifierManager.boosting import Boosting
from classifierManager.oulad.scriptClassifier import ScriptClassifier
class ScriptAdaBoost(ScriptClassifier):
......
......@@ -91,9 +91,8 @@ class ScriptClassifier:
''' load feature '''
self.featureMultiGroup.featureGroups = []
self.featureMultiGroup.data = pd.DataFrame()
self.featureMultiGroup.addGroup(course, groupNames, self.features, whereToCut, whereToCutUnity)
self.featureMultiGroup.clear()
self.featureMultiGroup.addGroup(course, groupNames, self.features, whereToCut=whereToCut, whereToCutUnity=whereToCutUnity)
train_x, train_y, test_x, test_y = self.featureMultiGroup.getTrainTestNumpyFeatures()
test_y = np.ravel(test_y)
......@@ -145,6 +144,7 @@ class ScriptClassifier:
model = self.loadModel()
print("Model loaded:"+str(type(model)))
print("groups:"+str(groups))
model.fit(train_x, train_y)
......@@ -157,7 +157,8 @@ class ScriptClassifier:
print("--------------------------------------------------")
print("input dimension:"+str(train_x.shape))
print("train[0, 500:600]="+str(train_x[0, 10:60]))
print("input dimension:"+str(train_y.shape))
print("train[0, 10:60]="+str(train_x[0, 10:60]))
courseName = course.getName()
print(("Course "+courseName+": "+str(accuracy)))
print("Confusion Matrix:")
......@@ -179,12 +180,13 @@ class ScriptClassifier:
'''
accuracys = []
course = Course(idCourse)
size = len(groupNames)
confusionMatrice = np.zeros((size, size))
dictResultWeight = {}
nameCourse = Course.getCourseName(idCourse, summary=True)
nameCourse = course.getName()
fileNameSavedResult = os.path.join(ScriptClassifier.DIRECTORY_EXPERIMENT,
self.fileName+
str(nameCourse)+'Session'+str(whereToCut)+'.p')
......@@ -244,17 +246,25 @@ class ScriptClassifier:
with open(fileNameResult, 'w') as fileResult:
for idCourse in idCourses: #[Course.COURSE_ID_ARDUINO, Course.COURSE_ID_AUDACE]
print("idCourse: "+str(idCourse))
course = Course(idCourse)
(accuracy, confusionMatrix, dictWeight) = self.predictionTaskNTimes(
idCourse,
groupNames,
whereToCut=whereToCut,
ntime=10)
ntime=2)
scores.append(accuracy)
if dictWeight:
dictWeightAllCourses[idCourse] = dictWeight
courseName = Course.getCourseName(idCourse, summary=True)
dictWeightAllCourses[idCourse] = dictWeight
courseName = course.getName()
fileResult.write("--------------------------\n")
fileResult.write("Course "+courseName+": accuracy("+str(accuracy)+") \n")
......
......@@ -60,7 +60,7 @@ class FeatureMultiGroup:
if self.course is None:
self.course = featureGroup.getCourse()
elif self.course != featureGroup.getCourse():
elif self.course.getIdCourse() != featureGroup.getCourse().getIdCourse():
warnings.warn('featureManager.features - FeatureMultiGroup - FeatureMultiGroup are merged from different courses', Warning)
label = len(self.featureGroups)
self.featureGroups.append(featureGroup)
......@@ -154,6 +154,8 @@ class FeatureMultiGroup:
trainX, trainY, testX, testY = self.getTrainTestPandasFeatures(train, test)
return trainX.values, trainY.values, testX.values, testY.values
return trainX.values.astype(float), trainY.values.astype(int), testX.values.astype(float), testY.values.astype(int)
def clear(self):
self.__init__()
\ No newline at end of file
......@@ -257,7 +257,7 @@ class FeatureSequence:
@return: a dataframe with resources as column and one row per user with the averages
'''
return FeatureSequence.__getNumberAccessPerResource(idUser, events, course, np.mean, filterType)
return FeatureSequence.__getNumberAccessPerResource(idUser, events, course, lambda l : np.sum(l)/len(l) if len(l) else 0, filterType)
@staticmethod
def getAllMarks(idUser, events, course):
......
......@@ -43,7 +43,7 @@ class Test(unittest.TestCase):
print(nameFeature+": "+str(featureWindowDuration[nameFeature].values[0]))
self.assertTrue(featureWindowDuration[nameFeature].values[0] == -259)
self.assertTrue(featureWindowDuration[nameFeature].values[0] == 258)
dataEmpty = FeatureSequence.getWindowDuration(idUser, pd.DataFrame())
......
......@@ -78,6 +78,8 @@ class Constant:
ID_COURSES = [AAA_2013_J]
#DDD_2013_B,DDD_2013_J,DDD_2014_B,DDD_2014_J,FFF_2014_J,FFF_2013_B,FFF_2013_J,FFF_2014_B]
REGISTRATION = 'registration'
......
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