experiments/runners.py
def _single_run(self, kernels, **kwargs):
        """Generate a dataset an train/test all the kernels on it."""
        if self.verbose:
            print("#{} {}".format(self.state, time.asctime()))
        # Generate the appropiate dataset:
        dataset = self._generate_dataset(**kwargs)
        # Split the data in train and test:
        X_train, X_test, y_train, y_test = dataset.train_test_split(
            train_size=kwargs['train_size'],
            test_size=kwargs['test_size'],
            random_state=self.state,
            )
        # Cross validation folds:
        cvf = cv.StratifiedKFold(y_train, kwargs['folds'])
        # Test preformance with every kernel:
        evaluation = {}
        for model_name in kernels.split(','):
            # Instantiate the model:
            model = getattr(kh, model_name)()
            # Train the model:
            if self.verbose:
                print('Training {}...'.format(model.name))
            best_fit = model.train(cv=cvf, X=X_train, y=y_train)
            # Test the model:
            if self.verbose:
                print('Testing {}...'.format(model.name))
            results = model.test(best_fit, X=X_test, y=y_test)
            evaluation[model.name] = results
        # Update results:
        self.results.append({
            'timestamp': time.asctime(),
            'arguments': kwargs,
            'evaluation': evaluation,
            })
        # Save partial results:
        if self.verbose:
            self.save("{}.json~".format(kwargs['dataset']))
        # Change state for next run:
        self.state += 1
Generate a dataset an train/test all the kernels on it.
Generate a dataset an train/test all the kernels on it.
Generate a dataset an train / test all the kernels on it .
def _single_run(self, kernels, **kwargs):
        if self.verbose:
            print("#{} {}".format(self.state, time.asctime()))
        dataset = self._generate_dataset(**kwargs)
        X_train, X_test, y_train, y_test = dataset.train_test_split(
            train_size=kwargs['train_size'],
            test_size=kwargs['test_size'],
            random_state=self.state,
            )
        cvf = cv.StratifiedKFold(y_train, kwargs['folds'])
        evaluation = {}
        for model_name in kernels.split(','):
            model = getattr(kh, model_name)()
            if self.verbose:
                print('Training {}...'.format(model.name))
            best_fit = model.train(cv=cvf, X=X_train, y=y_train)
            if self.verbose:
                print('Testing {}...'.format(model.name))
            results = model.test(best_fit, X=X_test, y=y_test)
            evaluation[model.name] = results
        self.results.append({
            'timestamp': time.asctime(),
            'arguments': kwargs,
            'evaluation': evaluation,
            })
        if self.verbose:
            self.save("{}.json~".format(kwargs['dataset']))
        self.state += 1
def _single_run ( self , kernels , ** kwargs ) : if self . verbose : print ( "#{} {}" . format ( self . state , time . asctime ( ) ) ) dataset = self . _generate_dataset ( ** kwargs ) X_train , X_test , y_train , y_test = dataset . train_test_split ( train_size = kwargs [ 'train_size' ] , test_size = kwargs [ 'test_size' ] , random_state = self . state , ) cvf = cv . StratifiedKFold ( y_train , kwargs [ 'folds' ] ) evaluation = { } for model_name in kernels . split ( ',' ) : model = getattr ( kh , model_name ) ( ) if self . verbose : print ( 'Training {}...' . format ( model . name ) ) best_fit = model . train ( cv = cvf , X = X_train , y = y_train ) if self . verbose : print ( 'Testing {}...' . format ( model . name ) ) results = model . test ( best_fit , X = X_test , y = y_test ) evaluation [ model . name ] = results self . results . append ( { 'timestamp' : time . asctime ( ) , 'arguments' : kwargs , 'evaluation' : evaluation , } ) if self . verbose : self . save ( "{}.json~" . format ( kwargs [ 'dataset' ] ) ) self . state += 1
Generate a dataset an train/test all the kernels on it.
Generate a dataset an train / test all the kernels on it .
"""Generate a dataset an train/test all the kernels on it.""" # Generate the appropiate dataset: # Split the data in train and test: # Cross validation folds: # Test preformance with every kernel: # Instantiate the model: # Train the model: # Test the model: # Update results: # Save partial results: # Change state for next run:
self
kernels