예제 #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 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
예제 #3
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_)
예제 #4
0
 def __init__(self, configuration_file):
     DataLoader.__init__(self, configuration_file)
     BaseRegression.__init__(self,
                             location=os.path.dirname(configuration_file))
     self.search_strategy = 'grid'
     self.n_jobs = -1
     self.metric = mean_absolute_error
예제 #5
0
 def __init__(self, configuration_file, out_dir):
     BaseMachineLearning.__init__(self, configuration_file)
     DataLoader.__init__(self, configuration_file)
     BaseRegression.__init__(self)
     self.metric = mean_absolute_error
     self.out_dir = out_dir
예제 #6
0
 def __init__(self, configuration_file):
     DataLoader.__init__(self, configuration_file)
     BaseClassification.__init__(self, location=os.path.dirname(configuration_file))
예제 #7
0
 def __init__(self, configuration_file, out_dir):
     BaseMachineLearning.__init__(self, configuration_file)
     DataLoader.__init__(self, configuration_file)
     BaseClassification.__init__(
         self)  # StatisticalAnalysis inherit from BaseClassification
     self.out_dir = out_dir
예제 #8
0
def test_dataLoading():
    data_loader = DataLoader(configuration_file='./dataLoadingTest.json')
    data_loader.load_data()
예제 #9
0
 def __init__(self, configuration_file):
     DataLoader.__init__(self, configuration_file)
     BaseClustering.__init__(self, location=os.path.dirname(configuration_file))