コード例 #1
0
    def __init__(
        self,
        change_params,
        lab_panel,
        num_episodes,
        use_cache=None,
        random_state=None,
        build_raw_only=False,
    ):
        SupervisedLearningPipeline.__init__(self, lab_panel, num_episodes,
                                            use_cache, random_state)
        self._change_params = change_params
        self._change_params[
            'feature_old'] = self._lookup_previous_measurement_feature(
                self._var)
        log.debug('change_params: %s' % self._change_params)

        if build_raw_only:
            self._build_raw_feature_matrix()
            return

        else:
            self._build_raw_feature_matrix()
            self._build_processed_feature_matrix()
            self._train_and_analyze_predictors()
コード例 #2
0
    def __init__(self, lab_panel, microcultures,  num_episodes, use_cache=None, random_state=None):
        SupervisedLearningPipeline.__init__(self, lab_panel, num_episodes, use_cache, random_state)

        self.panel = microcultures
        self._build_raw_feature_matrix()
        self._build_processed_feature_matrix()
        self._train_and_analyze_predictors()
コード例 #3
0
 def __init__(self, lab_panel, num_episodes, use_cache=None, random_state=None, isLabPanel=True,
              notUsePatIds=[], pat_batch_ind=None):
     self.notUsePatIds = notUsePatIds
     self.pat_batch_ind = pat_batch_ind
     self.usedPatIds = []
     SupervisedLearningPipeline.__init__(self, lab_panel, num_episodes, use_cache, random_state, isLabPanel)
     self._factory = FeatureMatrixFactory()
     self._build_raw_feature_matrix()
コード例 #4
0
    def __init__(self,
                 lab_panel,
                 num_episodes,
                 use_cache=None,
                 random_state=None,
                 isLabPanel=True,
                 timeLimit=None,
                 notUsePatIds=None,
                 holdOut=False,
                 pat_batch_ind=None):
        self.notUsePatIds = notUsePatIds
        self.pat_batch_ind = pat_batch_ind
        self.usedPatIds = []
        SupervisedLearningPipeline.__init__(
            self,
            lab_panel,
            num_episodes,
            use_cache,
            random_state,
            isLabPanel,
            timeLimit,
            holdOut,
            isLabNormalityPredictionPipeline=True)
        # TODO: naming of lab_panel
        self._factory = FeatureMatrixFactory()
        self._build_raw_feature_matrix()

        data_lab_folder = self._fetch_data_dir_path(
            inspect.getfile(inspect.currentframe()))
        feat2imputed_dict_path = data_lab_folder + '/feat2imputed_dict.pkl'

        if holdOut:
            '''
            For holdOut evaluation data, produce the raw matrix, pick 
            features according to the saved feat2imputed_dict. 
            '''
            self.feat2imputed_dict = pickle.load(
                open(feat2imputed_dict_path, 'r'))
            self._build_processed_feature_matrix_holdout()
            self._analyze_predictors_on_holdout()
        else:
            '''
            For training/validation data, record the pat_ids, 
            selected features and their imputed value correspondingly. 
            '''
            pickle.dump(self.usedPatIds,
                        open('data/used_patient_set_%s.pkl' % self._var, 'w'),
                        pickle.HIGHEST_PROTOCOL)
            self._build_processed_feature_matrix()
            self._build_baseline_results()  # TODO: prototype in SLPP
            return

            # TODO: find better place to put the dict.pkl
            pickle.dump(self.feat2imputed_dict,
                        open(feat2imputed_dict_path, 'w'),
                        pickle.HIGHEST_PROTOCOL)
            self._train_and_analyze_predictors()
コード例 #5
0
    def __init__(self, lab_panel, num_episodes, use_cache=None, random_state=None,
                 timeLimit=None, notUsePatIds=None, holdOut=False, pat_batch_ind=None, includeLastNormality=True):
        # self.notUsePatIds = notUsePatIds
        self.pat_batch_ind = pat_batch_ind
        self._holdOut = holdOut
        self.usedPatIds = []
        SupervisedLearningPipeline.__init__(self, lab_panel, num_episodes, use_cache, random_state,
                                            timeLimit, notUsePatIds)
        # TODO: naming of lab_panel
        self._factory = FeatureMatrixFactory()
        self._build_raw_feature_matrix()

        if LAB_TYPE == 'panel':
            self.ylabel = 'all_components_normal'
        else:
            self.ylabel = 'component_normal'

        self.includeLastNormality = includeLastNormality

        if self.includeLastNormality:
            fm_io = FeatureMatrixIO()
            df = fm_io.read_file_to_data_frame('data/'+lab_panel+'/%s-normality-matrix-raw.tab'%lab_panel)
            df = df.sort_values(['pat_id', 'order_time']).reset_index(drop=True)
            df['last_normality'] = df['order_proc_id'].apply(lambda x:float('nan'))
            for i in range(1,df.shape[0]):
                if df.ix[i, 'pat_id'] == df.ix[i-1, 'pat_id']:
                    df.ix[i, 'last_normality'] = df.ix[i-1, self.ylabel]
            df.to_csv('data/'+lab_panel+'/%s-normality-matrix-raw.tab'%lab_panel, index=False, sep='\t')

        data_lab_folder = self._fetch_data_dir_path(inspect.getfile(inspect.currentframe()))
        feat2imputed_dict_path = data_lab_folder + '/feat2imputed_dict.pkl'

        if holdOut:
            '''
            For holdOut evaluation data, produce the raw matrix, pick 
            features according to the saved feat2imputed_dict. 
            '''
            self.feat2imputed_dict = pickle.load(open(feat2imputed_dict_path, 'r'))
            self._build_processed_feature_matrix_holdout()
            self._analyze_predictors_on_holdout()
        else:
            '''
            For training/validation data, record the pat_ids, 
            selected features and their imputed value correspondingly. 
            '''
            pickle.dump(self.usedPatIds, open('data/used_patient_set_%s.pkl'%self._var, 'w'), pickle.HIGHEST_PROTOCOL)
            self._build_processed_feature_matrix()
            self._build_baseline_results()  # TODO: prototype in SLPP
            # return

            # TODO: find better place to put the dict.pkl
            pickle.dump(self.feat2imputed_dict, open(feat2imputed_dict_path, 'w'), pickle.HIGHEST_PROTOCOL)
            self._train_and_analyze_predictors()