def __init__(self, association, api=None): self.resource_id = None self.complement = None self.discretization = {} self.field_discretizations = {} self.items = [] self.max_k = None self.max_lhs = None self.min_confidence = None self.min_leverage = None self.min_support = None self.min_lift = None self.search_strategy = DEFAULT_SEARCH_STRATEGY self.rules = [] self.significance_level = None self.resource_id, association = get_resource_dict( \ association, "association", api=api) if 'object' in association and isinstance(association['object'], dict): association = association['object'] if 'associations' in association and \ isinstance(association['associations'], dict): status = get_status(association) if 'code' in status and status['code'] == FINISHED: associations = association['associations'] fields = associations['fields'] ModelFields.__init__(self, fields) self.complement = associations.get('complement', False) self.discretization = associations.get('discretization', {}) self.field_discretizations = associations.get( 'field_discretizations', {}) self.items = [ Item(index, item, fields) for index, item in enumerate(associations.get('items', [])) ] self.max_k = associations.get('max_k', 100) self.max_lhs = associations.get('max_lhs', 4) self.min_confidence = associations.get('min_confidence', 0) self.min_leverage = associations.get('min_leverage', -1) self.min_support = associations.get('min_support', 0) self.min_lift = associations.get('min_lift', 0) self.search_strategy = associations.get('search_strategy', \ DEFAULT_SEARCH_STRATEGY) self.rules = [ AssociationRule(rule) for rule in associations.get('rules', []) ] self.significance_level = associations.get( 'significance_level', 0.05) else: raise Exception("The association isn't finished yet") else: raise Exception("Cannot create the Association instance. Could not" " find the 'associations' key in the " "resource:\n\n%s" % association)
def __init__(self, association, api=None): self.resource_id = None self.complement = None self.discretization = {} self.field_discretizations = {} self.items = [] self.k = None self.max_lhs = None self.min_coverage = None self.min_leverage = None self.min_strength = None self.min_support = None self.min_lift = None self.prune = None self.search_strategy = DEFAULT_SEARCH_STRATEGY self.rules = [] self.significance_level = None if not (isinstance(association, dict) and 'resource' in association and association['resource'] is not None): if api is None: api = BigML(storage=STORAGE) self.resource_id = get_association_id(association) if self.resource_id is None: raise Exception( api.error_message(association, resource_type='association', method='get')) query_string = ONLY_MODEL association = retrieve_resource(api, self.resource_id, query_string=query_string) else: self.resource_id = get_association_id(association) if 'object' in association and isinstance(association['object'], dict): association = association['object'] if 'associations' in association and \ isinstance(association['associations'], dict): status = get_status(association) if 'code' in status and status['code'] == FINISHED: associations = association['associations'] fields = associations['fields'] ModelFields.__init__(self, fields) self.complement = associations.get('complement', False) self.discretization = associations.get('discretization', {}) self.field_discretizations = associations.get( 'field_discretizations', {}) self.items = [ Item(index, item, fields) for index, item in enumerate(associations.get('items', [])) ] self.k = associations.get('k', 100) self.max_lhs = associations.get('max_lhs', 4) self.min_coverage = associations.get('min_coverage', 0) self.min_leverage = associations.get('min_leverage', -1) self.min_strength = associations.get('min_strength', 0) self.min_support = associations.get('min_support', 0) self.min_lift = associations.get('min_lift', 0) self.prune = associations.get('prune', True) self.search_strategy = associations.get('search_strategy', \ DEFAULT_SEARCH_STRATEGY) self.rules = [ AssociationRule(rule) for rule in associations.get('rules', []) ] self.significance_level = associations.get( 'significance_level', 0.05) else: raise Exception("The association isn't finished yet") else: raise Exception("Cannot create the Association instance. Could not" " find the 'associations' key in the " "resource:\n\n%s" % association)
def __init__(self, association, api=None, cache_get=None): if use_cache(cache_get): # using a cache to store the association attributes self.__dict__ = load(get_association_id(association), cache_get) for index, item in enumerate(self.items): self.items[index] = Item(item["index"], item, self.fields) for index, rule in enumerate(self.rules): self.rules[index] = AssociationRule(rule) return self.resource_id = None self.complement = None self.discretization = {} self.default_numeric_value = None self.field_discretizations = {} self.items = [] self.max_k = None self.max_lhs = None self.min_confidence = None self.min_leverage = None self.min_support = None self.min_lift = None self.search_strategy = DEFAULT_SEARCH_STRATEGY self.rules = [] self.significance_level = None api = get_api_connection(api) self.resource_id, association = get_resource_dict( \ association, "association", api=api) if 'object' in association and isinstance(association['object'], dict): association = association['object'] if 'associations' in association and \ isinstance(association['associations'], dict): status = get_status(association) if 'code' in status and status['code'] == FINISHED: self.input_fields = association['input_fields'] self.default_numeric_value = association.get( \ 'default_numeric_value') associations = association['associations'] fields = associations['fields'] ModelFields.__init__( \ self, fields, \ missing_tokens=associations.get('missing_tokens')) self.complement = associations.get('complement', False) self.discretization = associations.get('discretization', {}) self.field_discretizations = associations.get( 'field_discretizations', {}) self.items = [Item(index, item, fields) for index, item in enumerate(associations.get('items', []))] self.max_k = associations.get('max_k', 100) self.max_lhs = associations.get('max_lhs', 4) self.min_confidence = associations.get('min_confidence', 0) self.min_leverage = associations.get('min_leverage', -1) self.min_support = associations.get('min_support', 0) self.min_lift = associations.get('min_lift', 0) self.search_strategy = associations.get('search_strategy', \ DEFAULT_SEARCH_STRATEGY) self.rules = [AssociationRule(rule) for rule in associations.get('rules', [])] self.significance_level = associations.get( 'significance_level', 0.05) else: raise Exception("The association isn't finished yet") else: raise Exception("Cannot create the Association instance. Could not" " find the 'associations' key in the " "resource:\n\n%s" % association)