def run(self):
        folds_test = mask.compute_folds(self.I,self.J,self.K,self.M)
        folds_training = mask.compute_Ms(folds_test)       

        for i,(train,test) in enumerate(zip(folds_training,folds_test)):
            print "Fold %s of nested cross-validation." % (i+1)            
            
            # Run the cross-validation
            crossval = ParallelMatrixCrossValidation(
            #crossval = MatrixCrossValidation(
                method=self.method,
                X=self.X,
                M=train,
                K=self.K,
                parameter_search=self.parameter_search,
                train_config=self.train_config,
                file_performance=self.files_nested_performances[i],
                P=self.P
            )
            crossval.run()
            (best_parameters,_) = crossval.find_best_parameters(evaluation_criterion='MSE',low_better=True)
            
            print "Best parameters for fold %s were %s." % (i+1,best_parameters)
            
            # Train the model and test the performance on the test set
            performance_dict = self.run_model(train,test,best_parameters)
            self.store_performances(performance_dict)
            print "Finished fold %s, with performances %s." % (i+1,performance_dict)            
            
        self.log()
示例#2
0
    def run(self):
        folds_test = mask.compute_folds(self.I, self.J, self.K, self.M)
        folds_training = mask.compute_Ms(folds_test)

        for i, (train, test) in enumerate(zip(folds_training, folds_test)):
            print "Fold %s of nested cross-validation." % (i + 1)

            # Run the cross-validation
            crossval = ParallelMatrixCrossValidation(
                #crossval = MatrixCrossValidation(
                method=self.method,
                X=self.X,
                M=train,
                K=self.K,
                parameter_search=self.parameter_search,
                train_config=self.train_config,
                file_performance=self.files_nested_performances[i],
                P=self.P)
            crossval.run()
            (best_parameters,
             _) = crossval.find_best_parameters(evaluation_criterion='MSE',
                                                low_better=True)

            print "Best parameters for fold %s were %s." % (i + 1,
                                                            best_parameters)

            # Train the model and test the performance on the test set
            performance_dict = self.run_model(train, test, best_parameters)
            self.store_performances(performance_dict)
            print "Finished fold %s, with performances %s." % (
                i + 1, performance_dict)

        self.log()
    def run(self):
        folds_test = mask.compute_folds_attempts(I=self.I,J=self.J,no_folds=self.K,attempts=attempts_generate_M,M=self.M)
        folds_training = mask.compute_Ms(folds_test)       

        for i,(train,test) in enumerate(zip(folds_training,folds_test)):
            print "Fold %s of nested cross-validation." % (i+1)            
            
            # Run the cross-validation
            crossval = ParallelMatrixCrossValidation(
            #crossval = MatrixCrossValidation(
                method=self.method,
                X=self.X,
                M=train,
                K=self.K,
                parameter_search=self.parameter_search,
                train_config=self.train_config,
                file_performance=self.files_nested_performances[i],
                P=self.P
            )
            crossval.run()
            
            try:
                (best_parameters,_) = crossval.find_best_parameters(evaluation_criterion='MSE',low_better=True)
                print "Best parameters for fold %s were %s." % (i+1,best_parameters)
            except KeyError:
                best_parameters = self.parameter_search[0]
                print "Found no performances, dataset too sparse? Use first values instead for fold %s, %s." % (i+1,best_parameters)
            
            # Train the model and test the performance on the test set
            performance_dict = self.run_model(train,test,best_parameters)
            self.store_performances(performance_dict)
            print "Finished fold %s, with performances %s." % (i+1,performance_dict)            
            
        self.log()
示例#4
0
    def run(self):
        folds_test = mask.compute_folds_attempts(I=self.I,J=self.J,no_folds=self.K,attempts=attempts_generate_M,M=self.M)
        folds_training = mask.compute_Ms(folds_test)       

        for i,(train,test) in enumerate(zip(folds_training,folds_test)):
            print "Fold %s of nested cross-validation." % (i+1)            
            
            # Run the cross-validation
            crossval = ParallelMatrixCrossValidation(
            #crossval = MatrixCrossValidation(
                method=self.method,
                X=self.X,
                M=train,
                K=self.K,
                parameter_search=self.parameter_search,
                train_config=self.train_config,
                predict_config=self.predict_config,
                file_performance=self.files_nested_performances[i],
                P=self.P
            )
            crossval.run()
            
            try:
                (best_parameters,_) = crossval.find_best_parameters(evaluation_criterion='MSE',low_better=True)
                print "Best parameters for fold %s were %s." % (i+1,best_parameters)
            except KeyError:
                best_parameters = self.parameter_search[0]
                print "Found no performances, dataset too sparse? Use first values instead for fold %s, %s." % (i+1,best_parameters)
            
            # Train the model and test the performance on the test set
            performance_dict = self.run_model(train,test,best_parameters)
            self.store_performances(performance_dict)
            print "Finished fold %s, with performances %s." % (i+1,performance_dict)            
            
        self.log()