Пример #1
0
def test_base():
    base = BaseMachineLearning(
        configuration_file=
        r'D:\My_Codes\virtualenv_eslearn\Lib\site-packages\eslearn\machine_learning\classification\tests/clf_configuration.json'
    )
    data_loader = DataLoader(
        configuration_file=
        r'D:\My_Codes\virtualenv_eslearn\Lib\site-packages\eslearn\machine_learning\classification\tests/clf_configuration.json'
    )
    data_loader.load_data()

    base.get_all_inputs()

    print(base.method_feature_preprocessing_)
    print(base.param_feature_preprocessing_)
    print(base.method_dim_reduction_)
    print(base.param_dim_reduction_)
    print(base.method_feature_selection_)
    print(base.param_feature_selection_)
    print(base.method_unbalance_treatment_)
    print(base.param_unbalance_treatment_)
    print(base.method_machine_learning_)
    print(base.param_machine_learning_)
    print(base.method_model_evaluation_)
    print(base.param_model_evaluation_)
    print(base.method_statistical_analysis_)
    print(base.param_statistical_analysis_)
Пример #2
0
def test_base():
    base = BaseMachineLearning(
        configuration_file=
        r'D:\work\lichao\nanjingshifandaxue\code\EEG-Classification-master\data1\eeg.json'
    )
    data_loader = DataLoader(
        configuration_file=
        r'D:\work\lichao\nanjingshifandaxue\code\EEG-Classification-master\data1\eeg.json'
    )
    data_loader.load_data()

    base.get_all_inputs()

    print(base.method_feature_preprocessing_)
    print(base.param_feature_preprocessing_)
    print(base.method_dim_reduction_)
    print(base.param_dim_reduction_)
    print(base.method_feature_selection_)
    print(base.param_feature_selection_)
    print(base.method_unbalance_treatment_)
    print(base.param_unbalance_treatment_)
    print(base.method_machine_learning_)
    print(base.param_machine_learning_)
    print(base.method_model_evaluation_)
    print(base.param_model_evaluation_)
    print(base.method_statistical_analysis_)
    print(base.param_statistical_analysis_)
Пример #3
0
    def run(self):
        """ 
        """

        # Load model
        output = pickle.load(open(self.model_file, "rb"))
        preprocessor = output["preprocessor"]
        best_model = output["model"]
        if hasattr(best_model, "best_estimator_"):
            best_model = best_model.best_estimator_

        # Get data
        data_loader = DataLoader(configuration_file=self.data_file)
        data_loader.load_data()
        feature = data_loader.features_  
        target = data_loader.targets_ 
        
        # Predict
        if not isinstance(best_model, list):  # Force the model and preprocessor is a list
            best_model = [best_model, best_model]
            
        if not isinstance(preprocessor, list):  # Force the model and preprocessor is a list
            preprocessor = [preprocessor, preprocessor]
        
        predict_label = []
        pred_prob = []
        for prep, model_ in zip(preprocessor, best_model):
            
            # Feature Preprocessing
            feature = prep.transform(feature)
            
            # Predict
            predict_label.append(model_.predict(feature))   
                                  
            if hasattr(model_, 'predict_proba'):
                pred_prob.append(model_.predict_proba(feature))
            elif hasattr(model_, 'decision_function'):
                prob_pos = model_.decision_function(feature)
                prob_pos = \
                    (prob_pos - prob_pos.min()) / (prob_pos.max() - prob_pos.min())
                    
                pred_prob.append(prob_pos)
                
                
            
            
            else:
                pred_prob = predict_label
        
        # Get voted predict label
        final_label = self.vote(predict_label)
        final_prob = np.mean(pred_prob,0)
        
        # Evaluation
        acc, sens, spec, _, _ = ModelEvaluator().binary_evaluator(
            target, final_label, final_prob,
            verbose=1, is_showfig=False, is_savefig=False
        )

        return acc, sens, spec
Пример #4
0
def test_dataLoading():
    data_loader = DataLoader(configuration_file='./dataLoadingTest.json')
    data_loader.load_data()