Exemplo n.º 1
0
 def setExperimentFromArgs(self, args):
     factory = DimensionReductionConfFactory.getFactory()
     conf = factory.fromArgs(args.algo, args, logger=self.logger)
     self.setConf(conf,
                  args.features_file,
                  annotations_filename=args.annotations_file)
     self.export()
Exemplo n.º 2
0
 def fromJson(obj):
     conf = KmeansConfiguration(obj['num_clusters'])
     if obj['projection_conf'] is not None:
         projection_conf = DimensionReductionConfFactory.getFactory(
         ).fromJson(obj['projection_conf'])
         conf.setDimensionReductionConf(projection_conf)
     return conf
Exemplo n.º 3
0
 def fromJson(obj, logger=None):
     conf = KmeansConfiguration(obj['num_clusters'], logger=logger)
     if obj['projection_conf'] is not None:
         proj_factory = DimensionReductionConfFactory.getFactory()
         projection_conf = proj_factory.fromJson(obj['projection_conf'],
                                                 logger=logger)
         conf.setDimensionReductionConf(projection_conf)
     return conf
Exemplo n.º 4
0
 def fromJson(obj, session):
     conf = DimensionReductionConfFactory.getFactory().fromJson(obj['conf'])
     experiment = ProjectionExperiment(obj['project'],
                                       obj['dataset'],
                                       session,
                                       create=False)
     DimensionReductionExperiment.expParamFromJson(experiment, obj, conf)
     return experiment
 def fromJson(obj):
     conf = ClusteringConfiguration(obj['num_clusters'],
                                    num_results=obj['num_results'],
                                    label=obj['label'])
     if obj['projection_conf'] is not None:
         projection_conf = DimensionReductionConfFactory.getFactory(
         ).fromJson(obj['projection_conf'])
         conf.setDimensionReductionConf(projection_conf)
     return conf
Exemplo n.º 6
0
 def fromJson(obj):
     conf = GaussianMixtureConfiguration(obj['num_clusters'])
     conf.covariance_type = obj['covariance_type']
     conf.init_params = obj['init_params']
     conf.max_iter = obj['max_iter']
     if obj['projection_conf'] is not None:
         projection_conf = DimensionReductionConfFactory.getFactory(
         ).fromJson(obj['projection_conf'])
         conf.setDimensionReductionConf(projection_conf)
     return conf
Exemplo n.º 7
0
 def generateParser():
     parser = argparse.ArgumentParser(
         description='Projection of the data for data visualization.')
     DimensionReductionExperiment.projectDatasetFeturesParser(parser)
     DimensionReductionExperiment.generateDimensionReductionParser(parser)
     algos = ['Pca', 'Rca', 'Lda', 'Lmnn', 'Nca', 'Itml']
     subparsers = parser.add_subparsers(dest='algo')
     factory = DimensionReductionConfFactory.getFactory()
     for algo in algos:
         algo_parser = subparsers.add_parser(algo)
         factory.generateParser(algo, algo_parser)
     return parser
 def generateParser():
     parser = argparse.ArgumentParser(description='Feature Selection.')
     algos = [
         'ChiSquare', 'Fclassif', 'MutualInfoClassif', 'VarianceFilter',
         'RecursiveFeatureElimination', 'NoneFilter'
     ]
     DimensionReductionExperiment.projectDatasetFeturesParser(parser)
     DimensionReductionExperiment.generateDimensionReductionParser(parser)
     subparsers = parser.add_subparsers(dest='algo')
     factory = DimensionReductionConfFactory.getFactory()
     for algo in algos:
         algo_parser = subparsers.add_parser(algo)
         factory.generateParser(algo, algo_parser)
     return parser
    def generateParamsFromArgs(args):

        # DimensionReduction parameters
        projection_conf = None
        if args.projection_algo is not None:
            projection_args = {}
            projection_args['families_supervision'] = args.families_supervision
            projection_args['num_components'] = None
            projection_conf = DimensionReductionConfFactory.getFactory(
            ).fromParam(args.projection_algo, projection_args)

        # Clustering parameters
        params = {}
        params['num_clusters'] = args.num_clusters
        params['num_results'] = 5
        params['projection_conf'] = projection_conf
        params['label'] = args.label

        return params
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with SecuML. If not, see <http://www.gnu.org/licenses/>.

from SecuML.core.DimensionReduction.Algorithms.FeatureSelection.VarianceFilter import VarianceFilter
from SecuML.core.DimensionReduction.Configuration import DimensionReductionConfFactory

from .UnsupervisedFeatureSelectionConfiguration import UnsupervisedFeatureSelectionConfiguration


class VarianceFilterConfiguration(UnsupervisedFeatureSelectionConfiguration):

    def __init__(self, logger=None):
        UnsupervisedFeatureSelectionConfiguration.__init__(self, VarianceFilter,
                                                           logger=logger)

    @staticmethod
    def fromJson(obj):
        conf = VarianceFilterConfiguration()
        return conf

    def toJson(self):
        conf = UnsupervisedFeatureSelectionConfiguration.toJson(self)
        conf['__type__'] = 'VarianceFilterConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass('VarianceFilterConfiguration',
                                                         VarianceFilterConfiguration)
Exemplo n.º 11
0
 def fromJson(obj, secuml_conf):
     conf = DimensionReductionConfFactory.getFactory().fromJson(obj['conf'])
     experiment = FeatureSelectionExperiment(secuml_conf)
     experiment.initExperiment(obj['project'], obj['dataset'], create=False)
     DimensionReductionExperiment.expParamFromJson(experiment, obj, conf)
     return experiment
Exemplo n.º 12
0
from .SemiSupervisedFeatureSelectionConfiguration import SemiSupervisedFeatureSelectionConfiguration


class ChiSquareConfiguration(SemiSupervisedFeatureSelectionConfiguration):
    def __init__(self,
                 num_components=None,
                 families_supervision=None,
                 logger=None):
        SemiSupervisedFeatureSelectionConfiguration.__init__(
            self,
            ChiSquare,
            num_components=num_components,
            families_supervision=families_supervision,
            logger=logger)

    @staticmethod
    def fromJson(obj):
        conf = ChiSquareConfiguration(
            num_components=obj['num_components'],
            families_supervision=obj['families_supervision'])
        return conf

    def toJson(self):
        conf = SemiSupervisedFeatureSelectionConfiguration.toJson(self)
        conf['__type__'] = 'ChiSquareConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass(
    'ChiSquareConfiguration', ChiSquareConfiguration)
        params = SemiSupervisedFeatureSelectionConfiguration.generateParamsFromArgs(
            args)
        params['step'] = args.step
        if args.model == 'LogisticRegression':
            model = LogisticRegression()
        elif args.model == 'Svc':
            model = SVC(kernel='linear')
        elif args.model == 'DecisionTree':
            model = DecisionTreeClassifier()
        elif args.model == 'RandomForest':
            model = RandomForestClassifier()
        params['model'] = model
        return params

    @staticmethod
    def generateParser(parser):
        SemiSupervisedFeatureSelectionConfiguration.generateParser(parser)
        parser.add_argument('--step', type=int, default=1)
        parser.add_argument('--model',
                            type=str,
                            choices=[
                                'LogisticRegression', 'Svc', 'DecisionTree',
                                'RandomForest'
                            ],
                            default='LogisticRegression')


DimensionReductionConfFactory.getFactory().registerClass(
    'RecursiveFeatureEliminationConfiguration',
    RecursiveFeatureEliminationConfiguration)
Exemplo n.º 14
0

class FclassifConfiguration(SemiSupervisedFeatureSelectionConfiguration):
    def __init__(self,
                 num_components=None,
                 families_supervision=None,
                 logger=None):
        SemiSupervisedFeatureSelectionConfiguration.__init__(
            self,
            Fclassif,
            num_components=num_components,
            families_supervision=families_supervision,
            logger=logger)

    @staticmethod
    def fromJson(obj, logger=None):
        conf = FclassifConfiguration(
            num_components=obj['num_components'],
            families_supervision=obj['families_supervision'],
            logger=logger)
        return conf

    def toJson(self):
        conf = SemiSupervisedFeatureSelectionConfiguration.toJson(self)
        conf['__type__'] = 'FclassifConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass(
    'FclassifConfiguration', FclassifConfiguration)
Exemplo n.º 15
0
# with SecuML. If not, see <http://www.gnu.org/licenses/>.

from SecuML.core.DimensionReduction.Algorithms.FeatureSelection.NoneFilter \
        import NoneFilter
from SecuML.core.DimensionReduction.Configuration \
        import DimensionReductionConfFactory

from .UnsupervisedFeatureSelectionConfiguration \
        import UnsupervisedFeatureSelectionConfiguration


class NoneFilterConfiguration(UnsupervisedFeatureSelectionConfiguration):
    def __init__(self, logger=None):
        UnsupervisedFeatureSelectionConfiguration.__init__(self,
                                                           NoneFilter,
                                                           logger=logger)

    @staticmethod
    def fromJson(obj, logger=None):
        conf = NoneFilterConfiguration(logger=logger)
        return conf

    def toJson(self):
        conf = UnsupervisedFeatureSelectionConfiguration.toJson(self)
        conf['__type__'] = 'NoneFilterConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass(
    'NoneFilterConfiguration', NoneFilterConfiguration)
Exemplo n.º 16
0
from SecuML.core.DimensionReduction.Configuration \
        import DimensionReductionConfFactory

from .SemiSupervisedProjectionConfiguration \
        import SemiSupervisedProjectionConfiguration


class SdmlConfiguration(SemiSupervisedProjectionConfiguration):
    def __init__(self, families_supervision=None, logger=None):
        SemiSupervisedProjectionConfiguration.__init__(
            self,
            Sdml,
            families_supervision=families_supervision,
            logger=logger)

    @staticmethod
    def fromJson(obj, logger=None):
        conf = SdmlConfiguration(
            families_supervision=obj['families_supervision'], logger=logger)
        conf.num_components = obj['num_components']
        return conf

    def toJson(self):
        conf = SemiSupervisedProjectionConfiguration.toJson(self)
        conf['__type__'] = 'SdmlConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass(
    'SdmlConfiguration', SdmlConfiguration)
Exemplo n.º 17
0

class MutualInfoClassifConfiguration(SemiSupervisedFeatureSelectionConfiguration):

    def __init__(self, num_components=None, families_supervision=None,
                 logger=None):
        SemiSupervisedFeatureSelectionConfiguration.__init__(
                                self,
                                MutualInfoClassif,
                                num_components=num_components,
                                families_supervision=families_supervision,
                                logger=logger)

    @staticmethod
    def fromJson(obj, logger=None):
        conf = MutualInfoClassifConfiguration(
                            num_components=obj['num_components'],
                            families_supervision=obj['families_supervision'],
                            logger=logger)
        return conf

    def toJson(self):
        conf = SemiSupervisedFeatureSelectionConfiguration.toJson(self)
        conf['__type__'] = 'MutualInfoClassifConfiguration'
        return conf


DimensionReductionConfFactory.getFactory().registerClass(
                                    'MutualInfoClassifConfiguration',
                                    MutualInfoClassifConfiguration)