def mlp_classification_train(table, group_by=None, **params): check_required_parameters(_mlp_classification_train, params, ['table']) params = get_default_from_parameters_if_required( params, _mlp_classification_train) if (params['batch_size_auto']): param_validation_check = [ greater_than(params, 0.0, 'learning_rate_init'), greater_than(params, 0.0, 'tol') ] else: if not params['batch_size'] or not isinstance(params['batch_size'], int): param_validation_check = [require_param('batch_size')] validate(*param_validation_check) param_validation_check = [ greater_than(params, 0, 'batch_size'), greater_than(params, 0.0, 'learning_rate_init'), greater_than(params, 0.0, 'tol') ] validate(*param_validation_check) if group_by is not None: grouped_model = _function_by_group(_mlp_classification_train, table, group_by=group_by, **params) return grouped_model else: return _mlp_classification_train(table, **params)
def _search(table, user_dict=pd.DataFrame(), input_cols=[], search_words=[], synonym_dict=[], main_operator='and'): if len(search_words) == 0: raise BrighticsFunctionException('0033', 'Search Words') for search_word in search_words: if search_word is None: raise BrighticsFunctionException('0033', 'Search Words') _table = table.copy() filter_list = [] if len(input_cols) == 0: validate(require_param('input_cols')) for _list in product(input_cols, search_words): c, od = _list filter_list.append([c, od.strip('\'')]) _out_table = _table filtered_set = set(_out_table.index) cond = np.full(len(_table), True).tolist() for _filter in filter_list: cond = (cond) & (_table[_filter[0]].str.contains(_filter[1])) _out_table = _table.loc[list( filtered_set.intersection(set(_table[cond].index)))] if len(user_dict.index) != 0: filter_list = [] search_words = [ user_dict['value'][i] for i, key in enumerate(user_dict['key']) if key in search_words ] print(search_words) for _list in product(input_cols, search_words): c, od = _list filter_list.append([c, od.strip('\'')]) filtered_set = set() syno_cond = np.full(len(_table), False).tolist() for _filter in filter_list: syno_cond = (syno_cond) | (_table[_filter[0]].str.contains( _filter[1])) syno_cond = syno_cond | cond _out_table = _table.loc[list( filtered_set.union(set(_table[syno_cond].index)))] return {'out_table': _out_table}
def _sort(table, input_cols, is_asc=None): if is_asc is None or is_asc == True: is_asc = [True for _ in input_cols] elif is_asc == False: is_asc = [False for _ in input_cols] if len(input_cols) == 0: validate(require_param('input_cols')) _table = table.copy() return {'out_table': table.sort_values(by=input_cols, ascending=is_asc)}
def simple_filter(table, input_cols, operators, operands, main_operator='and'): _table = table.copy() _column = [c.strip() for c in input_cols] _operator = [o.strip() for o in operators] if len(input_cols) == 0 or not (len(input_cols) == len(operators) == len(operands)): validate(require_param('input_cols')) _main_operator = 'and' if main_operator == 'and' else 'or' _query = _main_operator.join(['''({input_cols} {operators} {operands})'''.format(input_cols=c, operators=op, operands=od) for c, op, od in zip(_column, _operator, operands)]) _out_table = _table.query(_query, engine='python') return {'out_table':_out_table}
def simple_filter(table, input_cols, operators, operands, main_operator='and'): _table = table.copy() _column = [c.strip() for c in input_cols] _operator = [o.strip() for o in operators] if len(input_cols) == 0 or not (len(input_cols) == len(operators) == len(operands)): validate(require_param('input_cols')) _query = "" first_filter_list = [] second_filter_list = [] for c, op, od in zip(_column, _operator, operands): if op in ['starts with', 'ends with', 'contain', 'not contain']: second_filter_list.append([c, op, od.strip('\'')]) else: first_filter_list.append([c, op, od]) _query = main_operator.join(['''({input_cols} {operators} {operands})'''.format(input_cols=c, operators=op, operands=od) for c, op, od in first_filter_list]) if len(_query) == 0: _out_table = _table else: _out_table = _table.query(_query, engine='python') first_filtered_set = set(_out_table.index) if len(second_filter_list) == 0: _out_table = _out_table else: if main_operator == 'and': cond = np.full(len(_table), True).tolist() for _filter in second_filter_list: if _filter[1] == 'starts with': cond = (cond) and (_table[_filter[0]].str.startswith(_filter[2])) if _filter[1] == 'ends with': cond = (cond) and (_table[_filter[0]].str.endswith(_filter[2])) if _filter[1] == 'contain': cond = (cond) and (_table[_filter[0]].str.contains(_filter[2])) if _filter[1] == 'not contain': cond = (cond) and (~(_table[_filter[0]].str.contains(_filter[2]))) _out_table = _table.loc[list(first_filtered_set.intersection(set(_table[cond].index)))] elif main_operator == 'or': cond = np.full(len(_table), False).tolist() for _filter in second_filter_list: if _filter[1] == 'starts with': cond = (cond)or(_table[_filter[0]].str.startswith(_filter[2])) if _filter[1] == 'ends with': cond = (cond)or(_table[_filter[0]].str.endswith(_filter[2])) if _filter[1] == 'contain': cond = (cond) or (_table[_filter[0]].str.contains(_filter[2])) if _filter[1] == 'not contain': cond = (cond) or (~(_table[_filter[0]].str.contains(_filter[2]))) _out_table = _table.loc[list(first_filtered_set.union(set(_table[cond].index)))] return {'out_table':_out_table}
def simple_filter(table, input_cols, operators, operands, main_operator='and'): if len(input_cols) == 0 or not (len(input_cols) == len(operators) == len(operands)): validate(require_param('input_cols')) _column = [c.strip() for c in input_cols] _operator = [o.strip() for o in operators] _query = "" first_filter_list = [] second_filter_list = [] for c, op, od in zip(_column, _operator, operands): if op in ['starts with', 'ends with', 'contain', 'not contain']: second_filter_list.append([c, op, od.strip('\'')]) else: first_filter_list.append([c, op, od]) _query = main_operator.join([ '''({input_cols} {operators} {operands})'''.format(input_cols=c, operators=op, operands=od) for c, op, od in first_filter_list ]) if len(first_filter_list) == 0: _table = table.copy() cond = np.full(len(table), False) else: _table = table.query(_query, engine='python') cond = [ True if i in _table.index else False for i in range(len(table)) ] if len(second_filter_list) == 0: out_table = _table.copy() else: if main_operator == 'and': cond = np.full(len(_table), True) for _filter in second_filter_list: if _filter[1] == 'starts with': cond = cond & _table[_filter[0]].str.startswith( _filter[2]).values if _filter[1] == 'ends with': cond = cond & _table[_filter[0]].str.endswith( _filter[2]).values if _filter[1] == 'contain': cond = cond & _table[_filter[0]].str.contains( _filter[2]).values if _filter[1] == 'not contain': cond = cond & ~(_table[_filter[0]].str.contains( _filter[2]).values) out_table = _table[cond] elif main_operator == 'or': for _filter in second_filter_list: if _filter[1] == 'starts with': cond = cond | table[_filter[0]].str.startswith( _filter[2]).values if _filter[1] == 'ends with': cond = cond | table[_filter[0]].str.endswith( _filter[2]).values if _filter[1] == 'contain': cond = cond | table[_filter[0]].str.contains( _filter[2]).values if _filter[1] == 'not contain': cond = cond | ~(table[_filter[0]].str.contains( _filter[2]).values) out_table = table[cond] return {'out_table': out_table}