id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
21,500
apache/incubator-superset
superset/utils/core.py
datetime_f
def datetime_f(dttm): """Formats datetime to take less room when it is recent""" if dttm: dttm = dttm.isoformat() now_iso = datetime.now().isoformat() if now_iso[:10] == dttm[:10]: dttm = dttm[11:] elif now_iso[:4] == dttm[:4]: dttm = dttm[5:] return '...
python
def datetime_f(dttm): """Formats datetime to take less room when it is recent""" if dttm: dttm = dttm.isoformat() now_iso = datetime.now().isoformat() if now_iso[:10] == dttm[:10]: dttm = dttm[11:] elif now_iso[:4] == dttm[:4]: dttm = dttm[5:] return '...
[ "def", "datetime_f", "(", "dttm", ")", ":", "if", "dttm", ":", "dttm", "=", "dttm", ".", "isoformat", "(", ")", "now_iso", "=", "datetime", ".", "now", "(", ")", ".", "isoformat", "(", ")", "if", "now_iso", "[", ":", "10", "]", "==", "dttm", "[",...
Formats datetime to take less room when it is recent
[ "Formats", "datetime", "to", "take", "less", "room", "when", "it", "is", "recent" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L321-L330
21,501
apache/incubator-superset
superset/utils/core.py
error_msg_from_exception
def error_msg_from_exception(e): """Translate exception into error message Database have different ways to handle exception. This function attempts to make sense of the exception object and construct a human readable sentence. TODO(bkyryliuk): parse the Presto error message from the connection ...
python
def error_msg_from_exception(e): """Translate exception into error message Database have different ways to handle exception. This function attempts to make sense of the exception object and construct a human readable sentence. TODO(bkyryliuk): parse the Presto error message from the connection ...
[ "def", "error_msg_from_exception", "(", "e", ")", ":", "msg", "=", "''", "if", "hasattr", "(", "e", ",", "'message'", ")", ":", "if", "isinstance", "(", "e", ".", "message", ",", "dict", ")", ":", "msg", "=", "e", ".", "message", ".", "get", "(", ...
Translate exception into error message Database have different ways to handle exception. This function attempts to make sense of the exception object and construct a human readable sentence. TODO(bkyryliuk): parse the Presto error message from the connection created via create_eng...
[ "Translate", "exception", "into", "error", "message" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L403-L423
21,502
apache/incubator-superset
superset/utils/core.py
generic_find_fk_constraint_name
def generic_find_fk_constraint_name(table, columns, referenced, insp): """Utility to find a foreign-key constraint name in alembic migrations""" for fk in insp.get_foreign_keys(table): if fk['referred_table'] == referenced and set(fk['referred_columns']) == columns: return fk['name']
python
def generic_find_fk_constraint_name(table, columns, referenced, insp): """Utility to find a foreign-key constraint name in alembic migrations""" for fk in insp.get_foreign_keys(table): if fk['referred_table'] == referenced and set(fk['referred_columns']) == columns: return fk['name']
[ "def", "generic_find_fk_constraint_name", "(", "table", ",", "columns", ",", "referenced", ",", "insp", ")", ":", "for", "fk", "in", "insp", ".", "get_foreign_keys", "(", "table", ")", ":", "if", "fk", "[", "'referred_table'", "]", "==", "referenced", "and",...
Utility to find a foreign-key constraint name in alembic migrations
[ "Utility", "to", "find", "a", "foreign", "-", "key", "constraint", "name", "in", "alembic", "migrations" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L459-L463
21,503
apache/incubator-superset
superset/utils/core.py
generic_find_fk_constraint_names
def generic_find_fk_constraint_names(table, columns, referenced, insp): """Utility to find foreign-key constraint names in alembic migrations""" names = set() for fk in insp.get_foreign_keys(table): if fk['referred_table'] == referenced and set(fk['referred_columns']) == columns: names....
python
def generic_find_fk_constraint_names(table, columns, referenced, insp): """Utility to find foreign-key constraint names in alembic migrations""" names = set() for fk in insp.get_foreign_keys(table): if fk['referred_table'] == referenced and set(fk['referred_columns']) == columns: names....
[ "def", "generic_find_fk_constraint_names", "(", "table", ",", "columns", ",", "referenced", ",", "insp", ")", ":", "names", "=", "set", "(", ")", "for", "fk", "in", "insp", ".", "get_foreign_keys", "(", "table", ")", ":", "if", "fk", "[", "'referred_table'...
Utility to find foreign-key constraint names in alembic migrations
[ "Utility", "to", "find", "foreign", "-", "key", "constraint", "names", "in", "alembic", "migrations" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L466-L474
21,504
apache/incubator-superset
superset/utils/core.py
generic_find_uq_constraint_name
def generic_find_uq_constraint_name(table, columns, insp): """Utility to find a unique constraint name in alembic migrations""" for uq in insp.get_unique_constraints(table): if columns == set(uq['column_names']): return uq['name']
python
def generic_find_uq_constraint_name(table, columns, insp): """Utility to find a unique constraint name in alembic migrations""" for uq in insp.get_unique_constraints(table): if columns == set(uq['column_names']): return uq['name']
[ "def", "generic_find_uq_constraint_name", "(", "table", ",", "columns", ",", "insp", ")", ":", "for", "uq", "in", "insp", ".", "get_unique_constraints", "(", "table", ")", ":", "if", "columns", "==", "set", "(", "uq", "[", "'column_names'", "]", ")", ":", ...
Utility to find a unique constraint name in alembic migrations
[ "Utility", "to", "find", "a", "unique", "constraint", "name", "in", "alembic", "migrations" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L477-L482
21,505
apache/incubator-superset
superset/utils/core.py
setup_cache
def setup_cache(app: Flask, cache_config) -> Optional[Cache]: """Setup the flask-cache on a flask app""" if cache_config and cache_config.get('CACHE_TYPE') != 'null': return Cache(app, config=cache_config) return None
python
def setup_cache(app: Flask, cache_config) -> Optional[Cache]: """Setup the flask-cache on a flask app""" if cache_config and cache_config.get('CACHE_TYPE') != 'null': return Cache(app, config=cache_config) return None
[ "def", "setup_cache", "(", "app", ":", "Flask", ",", "cache_config", ")", "->", "Optional", "[", "Cache", "]", ":", "if", "cache_config", "and", "cache_config", ".", "get", "(", "'CACHE_TYPE'", ")", "!=", "'null'", ":", "return", "Cache", "(", "app", ","...
Setup the flask-cache on a flask app
[ "Setup", "the", "flask", "-", "cache", "on", "a", "flask", "app" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L702-L707
21,506
apache/incubator-superset
superset/utils/core.py
user_label
def user_label(user: User) -> Optional[str]: """Given a user ORM FAB object, returns a label""" if user: if user.first_name and user.last_name: return user.first_name + ' ' + user.last_name else: return user.username return None
python
def user_label(user: User) -> Optional[str]: """Given a user ORM FAB object, returns a label""" if user: if user.first_name and user.last_name: return user.first_name + ' ' + user.last_name else: return user.username return None
[ "def", "user_label", "(", "user", ":", "User", ")", "->", "Optional", "[", "str", "]", ":", "if", "user", ":", "if", "user", ".", "first_name", "and", "user", ".", "last_name", ":", "return", "user", ".", "first_name", "+", "' '", "+", "user", ".", ...
Given a user ORM FAB object, returns a label
[ "Given", "a", "user", "ORM", "FAB", "object", "returns", "a", "label" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L860-L868
21,507
apache/incubator-superset
superset/utils/core.py
get_since_until
def get_since_until(time_range: Optional[str] = None, since: Optional[str] = None, until: Optional[str] = None, time_shift: Optional[str] = None, relative_end: Optional[str] = None) -> Tuple[datetime, datetime]: """Return `since` and `u...
python
def get_since_until(time_range: Optional[str] = None, since: Optional[str] = None, until: Optional[str] = None, time_shift: Optional[str] = None, relative_end: Optional[str] = None) -> Tuple[datetime, datetime]: """Return `since` and `u...
[ "def", "get_since_until", "(", "time_range", ":", "Optional", "[", "str", "]", "=", "None", ",", "since", ":", "Optional", "[", "str", "]", "=", "None", ",", "until", ":", "Optional", "[", "str", "]", "=", "None", ",", "time_shift", ":", "Optional", ...
Return `since` and `until` date time tuple from string representations of time_range, since, until and time_shift. This functiom supports both reading the keys separately (from `since` and `until`), as well as the new `time_range` key. Valid formats are: - ISO 8601 - X days/years/hours/day...
[ "Return", "since", "and", "until", "date", "time", "tuple", "from", "string", "representations", "of", "time_range", "since", "until", "and", "time_shift", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L932-L1005
21,508
apache/incubator-superset
superset/utils/core.py
split_adhoc_filters_into_base_filters
def split_adhoc_filters_into_base_filters(fd): """ Mutates form data to restructure the adhoc filters in the form of the four base filters, `where`, `having`, `filters`, and `having_filters` which represent free form where sql, free form having sql, structured where clauses and structured having cla...
python
def split_adhoc_filters_into_base_filters(fd): """ Mutates form data to restructure the adhoc filters in the form of the four base filters, `where`, `having`, `filters`, and `having_filters` which represent free form where sql, free form having sql, structured where clauses and structured having cla...
[ "def", "split_adhoc_filters_into_base_filters", "(", "fd", ")", ":", "adhoc_filters", "=", "fd", ".", "get", "(", "'adhoc_filters'", ")", "if", "isinstance", "(", "adhoc_filters", ",", "list", ")", ":", "simple_where_filters", "=", "[", "]", "simple_having_filters...
Mutates form data to restructure the adhoc filters in the form of the four base filters, `where`, `having`, `filters`, and `having_filters` which represent free form where sql, free form having sql, structured where clauses and structured having clauses.
[ "Mutates", "form", "data", "to", "restructure", "the", "adhoc", "filters", "in", "the", "form", "of", "the", "four", "base", "filters", "where", "having", "filters", "and", "having_filters", "which", "represent", "free", "form", "where", "sql", "free", "form",...
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/utils/core.py#L1043-L1080
21,509
apache/incubator-superset
superset/data/energy.py
load_energy
def load_energy(): """Loads an energy related dataset to use with sankey and graphs""" tbl_name = 'energy_usage' data = get_example_data('energy.json.gz') pdf = pd.read_json(data) pdf.to_sql( tbl_name, db.engine, if_exists='replace', chunksize=500, dtype={ ...
python
def load_energy(): """Loads an energy related dataset to use with sankey and graphs""" tbl_name = 'energy_usage' data = get_example_data('energy.json.gz') pdf = pd.read_json(data) pdf.to_sql( tbl_name, db.engine, if_exists='replace', chunksize=500, dtype={ ...
[ "def", "load_energy", "(", ")", ":", "tbl_name", "=", "'energy_usage'", "data", "=", "get_example_data", "(", "'energy.json.gz'", ")", "pdf", "=", "pd", ".", "read_json", "(", "data", ")", "pdf", ".", "to_sql", "(", "tbl_name", ",", "db", ".", "engine", ...
Loads an energy related dataset to use with sankey and graphs
[ "Loads", "an", "energy", "related", "dataset", "to", "use", "with", "sankey", "and", "graphs" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/data/energy.py#L32-L140
21,510
apache/incubator-superset
superset/cli.py
runserver
def runserver(debug, console_log, use_reloader, address, port, timeout, workers, socket): """Starts a Superset web server.""" debug = debug or config.get('DEBUG') or console_log if debug: print(Fore.BLUE + '-=' * 20) print( Fore.YELLOW + 'Starting Superset server in ' + ...
python
def runserver(debug, console_log, use_reloader, address, port, timeout, workers, socket): """Starts a Superset web server.""" debug = debug or config.get('DEBUG') or console_log if debug: print(Fore.BLUE + '-=' * 20) print( Fore.YELLOW + 'Starting Superset server in ' + ...
[ "def", "runserver", "(", "debug", ",", "console_log", ",", "use_reloader", ",", "address", ",", "port", ",", "timeout", ",", "workers", ",", "socket", ")", ":", "debug", "=", "debug", "or", "config", ".", "get", "(", "'DEBUG'", ")", "or", "console_log", ...
Starts a Superset web server.
[ "Starts", "a", "Superset", "web", "server", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L112-L144
21,511
apache/incubator-superset
superset/cli.py
version
def version(verbose): """Prints the current version number""" print(Fore.BLUE + '-=' * 15) print(Fore.YELLOW + 'Superset ' + Fore.CYAN + '{version}'.format( version=config.get('VERSION_STRING'))) print(Fore.BLUE + '-=' * 15) if verbose: print('[DB] : ' + '{}'.format(db.engine)) p...
python
def version(verbose): """Prints the current version number""" print(Fore.BLUE + '-=' * 15) print(Fore.YELLOW + 'Superset ' + Fore.CYAN + '{version}'.format( version=config.get('VERSION_STRING'))) print(Fore.BLUE + '-=' * 15) if verbose: print('[DB] : ' + '{}'.format(db.engine)) p...
[ "def", "version", "(", "verbose", ")", ":", "print", "(", "Fore", ".", "BLUE", "+", "'-='", "*", "15", ")", "print", "(", "Fore", ".", "YELLOW", "+", "'Superset '", "+", "Fore", ".", "CYAN", "+", "'{version}'", ".", "format", "(", "version", "=", "...
Prints the current version number
[ "Prints", "the", "current", "version", "number" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L149-L157
21,512
apache/incubator-superset
superset/cli.py
refresh_druid
def refresh_druid(datasource, merge): """Refresh druid datasources""" session = db.session() from superset.connectors.druid.models import DruidCluster for cluster in session.query(DruidCluster).all(): try: cluster.refresh_datasources(datasource_name=datasource, ...
python
def refresh_druid(datasource, merge): """Refresh druid datasources""" session = db.session() from superset.connectors.druid.models import DruidCluster for cluster in session.query(DruidCluster).all(): try: cluster.refresh_datasources(datasource_name=datasource, ...
[ "def", "refresh_druid", "(", "datasource", ",", "merge", ")", ":", "session", "=", "db", ".", "session", "(", ")", "from", "superset", ".", "connectors", ".", "druid", ".", "models", "import", "DruidCluster", "for", "cluster", "in", "session", ".", "query"...
Refresh druid datasources
[ "Refresh", "druid", "datasources" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L225-L242
21,513
apache/incubator-superset
superset/cli.py
import_dashboards
def import_dashboards(path, recursive): """Import dashboards from JSON""" p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.json')) elif p.exists() and recursive: files.extend(p.rglob('*.json')) for f i...
python
def import_dashboards(path, recursive): """Import dashboards from JSON""" p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.json')) elif p.exists() and recursive: files.extend(p.rglob('*.json')) for f i...
[ "def", "import_dashboards", "(", "path", ",", "recursive", ")", ":", "p", "=", "Path", "(", "path", ")", "files", "=", "[", "]", "if", "p", ".", "is_file", "(", ")", ":", "files", ".", "append", "(", "p", ")", "elif", "p", ".", "exists", "(", "...
Import dashboards from JSON
[ "Import", "dashboards", "from", "JSON" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L253-L271
21,514
apache/incubator-superset
superset/cli.py
export_dashboards
def export_dashboards(print_stdout, dashboard_file): """Export dashboards to JSON""" data = dashboard_import_export.export_dashboards(db.session) if print_stdout or not dashboard_file: print(data) if dashboard_file: logging.info('Exporting dashboards to %s', dashboard_file) with ...
python
def export_dashboards(print_stdout, dashboard_file): """Export dashboards to JSON""" data = dashboard_import_export.export_dashboards(db.session) if print_stdout or not dashboard_file: print(data) if dashboard_file: logging.info('Exporting dashboards to %s', dashboard_file) with ...
[ "def", "export_dashboards", "(", "print_stdout", ",", "dashboard_file", ")", ":", "data", "=", "dashboard_import_export", ".", "export_dashboards", "(", "db", ".", "session", ")", "if", "print_stdout", "or", "not", "dashboard_file", ":", "print", "(", "data", ")...
Export dashboards to JSON
[ "Export", "dashboards", "to", "JSON" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L281-L289
21,515
apache/incubator-superset
superset/cli.py
import_datasources
def import_datasources(path, sync, recursive): """Import datasources from YAML""" sync_array = sync.split(',') p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.yaml')) files.extend(p.glob('*.yml')) eli...
python
def import_datasources(path, sync, recursive): """Import datasources from YAML""" sync_array = sync.split(',') p = Path(path) files = [] if p.is_file(): files.append(p) elif p.exists() and not recursive: files.extend(p.glob('*.yaml')) files.extend(p.glob('*.yml')) eli...
[ "def", "import_datasources", "(", "path", ",", "sync", ",", "recursive", ")", ":", "sync_array", "=", "sync", ".", "split", "(", "','", ")", "p", "=", "Path", "(", "path", ")", "files", "=", "[", "]", "if", "p", ".", "is_file", "(", ")", ":", "fi...
Import datasources from YAML
[ "Import", "datasources", "from", "YAML" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L305-L328
21,516
apache/incubator-superset
superset/cli.py
export_datasources
def export_datasources(print_stdout, datasource_file, back_references, include_defaults): """Export datasources to YAML""" data = dict_import_export.export_to_dict( session=db.session, recursive=True, back_references=back_references, include_defaults=includ...
python
def export_datasources(print_stdout, datasource_file, back_references, include_defaults): """Export datasources to YAML""" data = dict_import_export.export_to_dict( session=db.session, recursive=True, back_references=back_references, include_defaults=includ...
[ "def", "export_datasources", "(", "print_stdout", ",", "datasource_file", ",", "back_references", ",", "include_defaults", ")", ":", "data", "=", "dict_import_export", ".", "export_to_dict", "(", "session", "=", "db", ".", "session", ",", "recursive", "=", "True",...
Export datasources to YAML
[ "Export", "datasources", "to", "YAML" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L344-L357
21,517
apache/incubator-superset
superset/cli.py
export_datasource_schema
def export_datasource_schema(back_references): """Export datasource YAML schema to stdout""" data = dict_import_export.export_schema_to_dict( back_references=back_references) yaml.safe_dump(data, stdout, default_flow_style=False)
python
def export_datasource_schema(back_references): """Export datasource YAML schema to stdout""" data = dict_import_export.export_schema_to_dict( back_references=back_references) yaml.safe_dump(data, stdout, default_flow_style=False)
[ "def", "export_datasource_schema", "(", "back_references", ")", ":", "data", "=", "dict_import_export", ".", "export_schema_to_dict", "(", "back_references", "=", "back_references", ")", "yaml", ".", "safe_dump", "(", "data", ",", "stdout", ",", "default_flow_style", ...
Export datasource YAML schema to stdout
[ "Export", "datasource", "YAML", "schema", "to", "stdout" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L364-L368
21,518
apache/incubator-superset
superset/cli.py
update_datasources_cache
def update_datasources_cache(): """Refresh sqllab datasources cache""" from superset.models.core import Database for database in db.session.query(Database).all(): if database.allow_multi_schema_metadata_fetch: print('Fetching {} datasources ...'.format(database.name)) try: ...
python
def update_datasources_cache(): """Refresh sqllab datasources cache""" from superset.models.core import Database for database in db.session.query(Database).all(): if database.allow_multi_schema_metadata_fetch: print('Fetching {} datasources ...'.format(database.name)) try: ...
[ "def", "update_datasources_cache", "(", ")", ":", "from", "superset", ".", "models", ".", "core", "import", "Database", "for", "database", "in", "db", ".", "session", ".", "query", "(", "Database", ")", ".", "all", "(", ")", ":", "if", "database", ".", ...
Refresh sqllab datasources cache
[ "Refresh", "sqllab", "datasources", "cache" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L372-L384
21,519
apache/incubator-superset
superset/cli.py
worker
def worker(workers): """Starts a Superset worker for async SQL query execution.""" logging.info( "The 'superset worker' command is deprecated. Please use the 'celery " "worker' command instead.") if workers: celery_app.conf.update(CELERYD_CONCURRENCY=workers) elif config.get('SUP...
python
def worker(workers): """Starts a Superset worker for async SQL query execution.""" logging.info( "The 'superset worker' command is deprecated. Please use the 'celery " "worker' command instead.") if workers: celery_app.conf.update(CELERYD_CONCURRENCY=workers) elif config.get('SUP...
[ "def", "worker", "(", "workers", ")", ":", "logging", ".", "info", "(", "\"The 'superset worker' command is deprecated. Please use the 'celery \"", "\"worker' command instead.\"", ")", "if", "workers", ":", "celery_app", ".", "conf", ".", "update", "(", "CELERYD_CONCURREN...
Starts a Superset worker for async SQL query execution.
[ "Starts", "a", "Superset", "worker", "for", "async", "SQL", "query", "execution", "." ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L392-L404
21,520
apache/incubator-superset
superset/cli.py
flower
def flower(port, address): """Runs a Celery Flower web server Celery Flower is a UI to monitor the Celery operation on a given broker""" BROKER_URL = celery_app.conf.BROKER_URL cmd = ( 'celery flower ' f'--broker={BROKER_URL} ' f'--port={port} ' f'--address={address}...
python
def flower(port, address): """Runs a Celery Flower web server Celery Flower is a UI to monitor the Celery operation on a given broker""" BROKER_URL = celery_app.conf.BROKER_URL cmd = ( 'celery flower ' f'--broker={BROKER_URL} ' f'--port={port} ' f'--address={address}...
[ "def", "flower", "(", "port", ",", "address", ")", ":", "BROKER_URL", "=", "celery_app", ".", "conf", ".", "BROKER_URL", "cmd", "=", "(", "'celery flower '", "f'--broker={BROKER_URL} '", "f'--port={port} '", "f'--address={address} '", ")", "logging", ".", "info", ...
Runs a Celery Flower web server Celery Flower is a UI to monitor the Celery operation on a given broker
[ "Runs", "a", "Celery", "Flower", "web", "server" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/cli.py#L416-L435
21,521
apache/incubator-superset
superset/connectors/druid/views.py
Druid.refresh_datasources
def refresh_datasources(self, refreshAll=True): """endpoint that refreshes druid datasources metadata""" session = db.session() DruidCluster = ConnectorRegistry.sources['druid'].cluster_class for cluster in session.query(DruidCluster).all(): cluster_name = cluster.cluster_nam...
python
def refresh_datasources(self, refreshAll=True): """endpoint that refreshes druid datasources metadata""" session = db.session() DruidCluster = ConnectorRegistry.sources['druid'].cluster_class for cluster in session.query(DruidCluster).all(): cluster_name = cluster.cluster_nam...
[ "def", "refresh_datasources", "(", "self", ",", "refreshAll", "=", "True", ")", ":", "session", "=", "db", ".", "session", "(", ")", "DruidCluster", "=", "ConnectorRegistry", ".", "sources", "[", "'druid'", "]", ".", "cluster_class", "for", "cluster", "in", ...
endpoint that refreshes druid datasources metadata
[ "endpoint", "that", "refreshes", "druid", "datasources", "metadata" ]
ca2996c78f679260eb79c6008e276733df5fb653
https://github.com/apache/incubator-superset/blob/ca2996c78f679260eb79c6008e276733df5fb653/superset/connectors/druid/views.py#L339-L363
21,522
keon/algorithms
algorithms/linkedlist/add_two_numbers.py
convert_to_str
def convert_to_str(l: Node) -> str: """ converts the non-negative number list into a string. """ result = "" while l: result += str(l.val) l = l.next return result
python
def convert_to_str(l: Node) -> str: """ converts the non-negative number list into a string. """ result = "" while l: result += str(l.val) l = l.next return result
[ "def", "convert_to_str", "(", "l", ":", "Node", ")", "->", "str", ":", "result", "=", "\"\"", "while", "l", ":", "result", "+=", "str", "(", "l", ".", "val", ")", "l", "=", "l", ".", "next", "return", "result" ]
converts the non-negative number list into a string.
[ "converts", "the", "non", "-", "negative", "number", "list", "into", "a", "string", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/add_two_numbers.py#L66-L74
21,523
keon/algorithms
algorithms/sort/cocktail_shaker_sort.py
cocktail_shaker_sort
def cocktail_shaker_sort(arr): """ Cocktail_shaker_sort Sorting a given array mutation of bubble sort reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort Worst-case performance: O(N^2) """ def swap(i, j): arr[i], arr[j] = arr[j], arr[i] n = len(arr) swap...
python
def cocktail_shaker_sort(arr): """ Cocktail_shaker_sort Sorting a given array mutation of bubble sort reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort Worst-case performance: O(N^2) """ def swap(i, j): arr[i], arr[j] = arr[j], arr[i] n = len(arr) swap...
[ "def", "cocktail_shaker_sort", "(", "arr", ")", ":", "def", "swap", "(", "i", ",", "j", ")", ":", "arr", "[", "i", "]", ",", "arr", "[", "j", "]", "=", "arr", "[", "j", "]", ",", "arr", "[", "i", "]", "n", "=", "len", "(", "arr", ")", "sw...
Cocktail_shaker_sort Sorting a given array mutation of bubble sort reference: https://en.wikipedia.org/wiki/Cocktail_shaker_sort Worst-case performance: O(N^2)
[ "Cocktail_shaker_sort", "Sorting", "a", "given", "array", "mutation", "of", "bubble", "sort" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/cocktail_shaker_sort.py#L1-L30
21,524
keon/algorithms
algorithms/strings/longest_common_prefix.py
common_prefix
def common_prefix(s1, s2): "Return prefix common of 2 strings" if not s1 or not s2: return "" k = 0 while s1[k] == s2[k]: k = k + 1 if k >= len(s1) or k >= len(s2): return s1[0:k] return s1[0:k]
python
def common_prefix(s1, s2): "Return prefix common of 2 strings" if not s1 or not s2: return "" k = 0 while s1[k] == s2[k]: k = k + 1 if k >= len(s1) or k >= len(s2): return s1[0:k] return s1[0:k]
[ "def", "common_prefix", "(", "s1", ",", "s2", ")", ":", "if", "not", "s1", "or", "not", "s2", ":", "return", "\"\"", "k", "=", "0", "while", "s1", "[", "k", "]", "==", "s2", "[", "k", "]", ":", "k", "=", "k", "+", "1", "if", "k", ">=", "l...
Return prefix common of 2 strings
[ "Return", "prefix", "common", "of", "2", "strings" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/strings/longest_common_prefix.py#L21-L30
21,525
keon/algorithms
algorithms/strings/min_distance.py
lcs
def lcs(s1, s2, i, j): """ The length of longest common subsequence among the two given strings s1 and s2 """ if i == 0 or j == 0: return 0 elif s1[i - 1] == s2[j - 1]: return 1 + lcs(s1, s2, i - 1, j - 1) else: return max(lcs(s1, s2, i - 1, j), lcs(s1, s2, i, j - 1))
python
def lcs(s1, s2, i, j): """ The length of longest common subsequence among the two given strings s1 and s2 """ if i == 0 or j == 0: return 0 elif s1[i - 1] == s2[j - 1]: return 1 + lcs(s1, s2, i - 1, j - 1) else: return max(lcs(s1, s2, i - 1, j), lcs(s1, s2, i, j - 1))
[ "def", "lcs", "(", "s1", ",", "s2", ",", "i", ",", "j", ")", ":", "if", "i", "==", "0", "or", "j", "==", "0", ":", "return", "0", "elif", "s1", "[", "i", "-", "1", "]", "==", "s2", "[", "j", "-", "1", "]", ":", "return", "1", "+", "lc...
The length of longest common subsequence among the two given strings s1 and s2
[ "The", "length", "of", "longest", "common", "subsequence", "among", "the", "two", "given", "strings", "s1", "and", "s2" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/strings/min_distance.py#L17-L26
21,526
keon/algorithms
algorithms/maths/nth_digit.py
find_nth_digit
def find_nth_digit(n): """find the nth digit of given number. 1. find the length of the number where the nth digit is from. 2. find the actual number where the nth digit is from 3. find the nth digit and return """ length = 1 count = 9 start = 1 while n > length * count: n -=...
python
def find_nth_digit(n): """find the nth digit of given number. 1. find the length of the number where the nth digit is from. 2. find the actual number where the nth digit is from 3. find the nth digit and return """ length = 1 count = 9 start = 1 while n > length * count: n -=...
[ "def", "find_nth_digit", "(", "n", ")", ":", "length", "=", "1", "count", "=", "9", "start", "=", "1", "while", "n", ">", "length", "*", "count", ":", "n", "-=", "length", "*", "count", "length", "+=", "1", "count", "*=", "10", "start", "*=", "10...
find the nth digit of given number. 1. find the length of the number where the nth digit is from. 2. find the actual number where the nth digit is from 3. find the nth digit and return
[ "find", "the", "nth", "digit", "of", "given", "number", ".", "1", ".", "find", "the", "length", "of", "the", "number", "where", "the", "nth", "digit", "is", "from", ".", "2", ".", "find", "the", "actual", "number", "where", "the", "nth", "digit", "is...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/nth_digit.py#L1-L17
21,527
keon/algorithms
algorithms/maths/prime_check.py
prime_check
def prime_check(n): """Return True if n is a prime number Else return False. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: retu...
python
def prime_check(n): """Return True if n is a prime number Else return False. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: retu...
[ "def", "prime_check", "(", "n", ")", ":", "if", "n", "<=", "1", ":", "return", "False", "if", "n", "==", "2", "or", "n", "==", "3", ":", "return", "True", "if", "n", "%", "2", "==", "0", "or", "n", "%", "3", "==", "0", ":", "return", "False...
Return True if n is a prime number Else return False.
[ "Return", "True", "if", "n", "is", "a", "prime", "number", "Else", "return", "False", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/prime_check.py#L1-L17
21,528
keon/algorithms
algorithms/arrays/longest_non_repeat.py
longest_non_repeat_v1
def longest_non_repeat_v1(string): """ Find the length of the longest substring without repeating characters. """ if string is None: return 0 dict = {} max_length = 0 j = 0 for i in range(len(string)): if string[i] in dict: j = max(dict[string[i]], j) ...
python
def longest_non_repeat_v1(string): """ Find the length of the longest substring without repeating characters. """ if string is None: return 0 dict = {} max_length = 0 j = 0 for i in range(len(string)): if string[i] in dict: j = max(dict[string[i]], j) ...
[ "def", "longest_non_repeat_v1", "(", "string", ")", ":", "if", "string", "is", "None", ":", "return", "0", "dict", "=", "{", "}", "max_length", "=", "0", "j", "=", "0", "for", "i", "in", "range", "(", "len", "(", "string", ")", ")", ":", "if", "s...
Find the length of the longest substring without repeating characters.
[ "Find", "the", "length", "of", "the", "longest", "substring", "without", "repeating", "characters", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/longest_non_repeat.py#L14-L29
21,529
keon/algorithms
algorithms/arrays/longest_non_repeat.py
longest_non_repeat_v2
def longest_non_repeat_v2(string): """ Find the length of the longest substring without repeating characters. Uses alternative algorithm. """ if string is None: return 0 start, max_len = 0, 0 used_char = {} for index, char in enumerate(string): if char in used_char an...
python
def longest_non_repeat_v2(string): """ Find the length of the longest substring without repeating characters. Uses alternative algorithm. """ if string is None: return 0 start, max_len = 0, 0 used_char = {} for index, char in enumerate(string): if char in used_char an...
[ "def", "longest_non_repeat_v2", "(", "string", ")", ":", "if", "string", "is", "None", ":", "return", "0", "start", ",", "max_len", "=", "0", ",", "0", "used_char", "=", "{", "}", "for", "index", ",", "char", "in", "enumerate", "(", "string", ")", ":...
Find the length of the longest substring without repeating characters. Uses alternative algorithm.
[ "Find", "the", "length", "of", "the", "longest", "substring", "without", "repeating", "characters", ".", "Uses", "alternative", "algorithm", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/longest_non_repeat.py#L31-L47
21,530
keon/algorithms
algorithms/arrays/longest_non_repeat.py
get_longest_non_repeat_v1
def get_longest_non_repeat_v1(string): """ Find the length of the longest substring without repeating characters. Return max_len and the substring as a tuple """ if string is None: return 0, '' sub_string = '' dict = {} max_length = 0 j = 0 for i in range(len(string))...
python
def get_longest_non_repeat_v1(string): """ Find the length of the longest substring without repeating characters. Return max_len and the substring as a tuple """ if string is None: return 0, '' sub_string = '' dict = {} max_length = 0 j = 0 for i in range(len(string))...
[ "def", "get_longest_non_repeat_v1", "(", "string", ")", ":", "if", "string", "is", "None", ":", "return", "0", ",", "''", "sub_string", "=", "''", "dict", "=", "{", "}", "max_length", "=", "0", "j", "=", "0", "for", "i", "in", "range", "(", "len", ...
Find the length of the longest substring without repeating characters. Return max_len and the substring as a tuple
[ "Find", "the", "length", "of", "the", "longest", "substring", "without", "repeating", "characters", ".", "Return", "max_len", "and", "the", "substring", "as", "a", "tuple" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/longest_non_repeat.py#L50-L69
21,531
keon/algorithms
algorithms/arrays/longest_non_repeat.py
get_longest_non_repeat_v2
def get_longest_non_repeat_v2(string): """ Find the length of the longest substring without repeating characters. Uses alternative algorithm. Return max_len and the substring as a tuple """ if string is None: return 0, '' sub_string = '' start, max_len = 0, 0 used_char = ...
python
def get_longest_non_repeat_v2(string): """ Find the length of the longest substring without repeating characters. Uses alternative algorithm. Return max_len and the substring as a tuple """ if string is None: return 0, '' sub_string = '' start, max_len = 0, 0 used_char = ...
[ "def", "get_longest_non_repeat_v2", "(", "string", ")", ":", "if", "string", "is", "None", ":", "return", "0", ",", "''", "sub_string", "=", "''", "start", ",", "max_len", "=", "0", ",", "0", "used_char", "=", "{", "}", "for", "index", ",", "char", "...
Find the length of the longest substring without repeating characters. Uses alternative algorithm. Return max_len and the substring as a tuple
[ "Find", "the", "length", "of", "the", "longest", "substring", "without", "repeating", "characters", ".", "Uses", "alternative", "algorithm", ".", "Return", "max_len", "and", "the", "substring", "as", "a", "tuple" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/longest_non_repeat.py#L71-L91
21,532
keon/algorithms
algorithms/queues/priority_queue.py
PriorityQueue.push
def push(self, item, priority=None): """Push the item in the priority queue. if priority is not given, priority is set to the value of item. """ priority = item if priority is None else priority node = PriorityQueueNode(item, priority) for index, current in enumerate(self...
python
def push(self, item, priority=None): """Push the item in the priority queue. if priority is not given, priority is set to the value of item. """ priority = item if priority is None else priority node = PriorityQueueNode(item, priority) for index, current in enumerate(self...
[ "def", "push", "(", "self", ",", "item", ",", "priority", "=", "None", ")", ":", "priority", "=", "item", "if", "priority", "is", "None", "else", "priority", "node", "=", "PriorityQueueNode", "(", "item", ",", "priority", ")", "for", "index", ",", "cur...
Push the item in the priority queue. if priority is not given, priority is set to the value of item.
[ "Push", "the", "item", "in", "the", "priority", "queue", ".", "if", "priority", "is", "not", "given", "priority", "is", "set", "to", "the", "value", "of", "item", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/queues/priority_queue.py#L38-L49
21,533
keon/algorithms
algorithms/arrays/flatten.py
flatten_iter
def flatten_iter(iterable): """ Takes as input multi dimensional iterable and returns generator which produces one dimensional output. """ for element in iterable: if isinstance(element, Iterable): yield from flatten_iter(element) else: yield element
python
def flatten_iter(iterable): """ Takes as input multi dimensional iterable and returns generator which produces one dimensional output. """ for element in iterable: if isinstance(element, Iterable): yield from flatten_iter(element) else: yield element
[ "def", "flatten_iter", "(", "iterable", ")", ":", "for", "element", "in", "iterable", ":", "if", "isinstance", "(", "element", ",", "Iterable", ")", ":", "yield", "from", "flatten_iter", "(", "element", ")", "else", ":", "yield", "element" ]
Takes as input multi dimensional iterable and returns generator which produces one dimensional output.
[ "Takes", "as", "input", "multi", "dimensional", "iterable", "and", "returns", "generator", "which", "produces", "one", "dimensional", "output", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/flatten.py#L22-L31
21,534
keon/algorithms
algorithms/iterables/convolved.py
convolved
def convolved(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """Iterable to get every convolution window per loop iteration. For example: `convolved([1, 2, 3, 4], kernel_size=2)` will produce the following result: `[[1, 2], [2, 3], [3, 4]]`. `convolve...
python
def convolved(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """Iterable to get every convolution window per loop iteration. For example: `convolved([1, 2, 3, 4], kernel_size=2)` will produce the following result: `[[1, 2], [2, 3], [3, 4]]`. `convolve...
[ "def", "convolved", "(", "iterable", ",", "kernel_size", "=", "1", ",", "stride", "=", "1", ",", "padding", "=", "0", ",", "default_value", "=", "None", ")", ":", "# Input validation and error messages", "if", "not", "hasattr", "(", "iterable", ",", "'__iter...
Iterable to get every convolution window per loop iteration. For example: `convolved([1, 2, 3, 4], kernel_size=2)` will produce the following result: `[[1, 2], [2, 3], [3, 4]]`. `convolved([1, 2, 3], kernel_size=2, stride=1, padding=2, default_value=42)` will pro...
[ "Iterable", "to", "get", "every", "convolution", "window", "per", "loop", "iteration", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/iterables/convolved.py#L28-L94
21,535
keon/algorithms
algorithms/iterables/convolved.py
convolved_1d
def convolved_1d(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """1D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevali...
python
def convolved_1d(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """1D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevali...
[ "def", "convolved_1d", "(", "iterable", ",", "kernel_size", "=", "1", ",", "stride", "=", "1", ",", "padding", "=", "0", ",", "default_value", "=", "None", ")", ":", "return", "convolved", "(", "iterable", ",", "kernel_size", ",", "stride", ",", "padding...
1D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevalier/python-conv-lib - MIT License, Copyright (c) 2018 Guillaume Chevalier
[ "1D", "Iterable", "to", "get", "every", "convolution", "window", "per", "loop", "iteration", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/iterables/convolved.py#L96-L104
21,536
keon/algorithms
algorithms/iterables/convolved.py
convolved_2d
def convolved_2d(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """2D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevali...
python
def convolved_2d(iterable, kernel_size=1, stride=1, padding=0, default_value=None): """2D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevali...
[ "def", "convolved_2d", "(", "iterable", ",", "kernel_size", "=", "1", ",", "stride", "=", "1", ",", "padding", "=", "0", ",", "default_value", "=", "None", ")", ":", "kernel_size", "=", "dimensionize", "(", "kernel_size", ",", "nd", "=", "2", ")", "str...
2D Iterable to get every convolution window per loop iteration. For more information, refer to: - https://github.com/guillaume-chevalier/python-conv-lib/blob/master/conv/conv.py - https://github.com/guillaume-chevalier/python-conv-lib - MIT License, Copyright (c) 2018 Guillaume Chevalier
[ "2D", "Iterable", "to", "get", "every", "convolution", "window", "per", "loop", "iteration", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/iterables/convolved.py#L107-L128
21,537
keon/algorithms
algorithms/iterables/convolved.py
dimensionize
def dimensionize(maybe_a_list, nd=2): """Convert integers to a list of integers to fit the number of dimensions if the argument is not already a list. For example: `dimensionize(3, nd=2)` will produce the following result: `(3, 3)`. `dimensionize([3, 1], nd=2)` will produce ...
python
def dimensionize(maybe_a_list, nd=2): """Convert integers to a list of integers to fit the number of dimensions if the argument is not already a list. For example: `dimensionize(3, nd=2)` will produce the following result: `(3, 3)`. `dimensionize([3, 1], nd=2)` will produce ...
[ "def", "dimensionize", "(", "maybe_a_list", ",", "nd", "=", "2", ")", ":", "if", "not", "hasattr", "(", "maybe_a_list", ",", "'__iter__'", ")", ":", "# Argument is probably an integer so we map it to a list of size `nd`.", "now_a_list", "=", "[", "maybe_a_list", "]", ...
Convert integers to a list of integers to fit the number of dimensions if the argument is not already a list. For example: `dimensionize(3, nd=2)` will produce the following result: `(3, 3)`. `dimensionize([3, 1], nd=2)` will produce the following result: `[3, 1]`. ...
[ "Convert", "integers", "to", "a", "list", "of", "integers", "to", "fit", "the", "number", "of", "dimensions", "if", "the", "argument", "is", "not", "already", "a", "list", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/iterables/convolved.py#L131-L154
21,538
keon/algorithms
algorithms/arrays/merge_intervals.py
merge_intervals
def merge_intervals(intervals): """ Merge intervals in the form of a list. """ if intervals is None: return None intervals.sort(key=lambda i: i[0]) out = [intervals.pop(0)] for i in intervals: if out[-1][-1] >= i[0]: out[-1][-1] = max(out[-1][-1], i[-1]) else: ...
python
def merge_intervals(intervals): """ Merge intervals in the form of a list. """ if intervals is None: return None intervals.sort(key=lambda i: i[0]) out = [intervals.pop(0)] for i in intervals: if out[-1][-1] >= i[0]: out[-1][-1] = max(out[-1][-1], i[-1]) else: ...
[ "def", "merge_intervals", "(", "intervals", ")", ":", "if", "intervals", "is", "None", ":", "return", "None", "intervals", ".", "sort", "(", "key", "=", "lambda", "i", ":", "i", "[", "0", "]", ")", "out", "=", "[", "intervals", ".", "pop", "(", "0"...
Merge intervals in the form of a list.
[ "Merge", "intervals", "in", "the", "form", "of", "a", "list", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/merge_intervals.py#L66-L77
21,539
keon/algorithms
algorithms/arrays/merge_intervals.py
Interval.merge
def merge(intervals): """ Merge two intervals into one. """ out = [] for i in sorted(intervals, key=lambda i: i.start): if out and i.start <= out[-1].end: out[-1].end = max(out[-1].end, i.end) else: out += i, return out
python
def merge(intervals): """ Merge two intervals into one. """ out = [] for i in sorted(intervals, key=lambda i: i.start): if out and i.start <= out[-1].end: out[-1].end = max(out[-1].end, i.end) else: out += i, return out
[ "def", "merge", "(", "intervals", ")", ":", "out", "=", "[", "]", "for", "i", "in", "sorted", "(", "intervals", ",", "key", "=", "lambda", "i", ":", "i", ".", "start", ")", ":", "if", "out", "and", "i", ".", "start", "<=", "out", "[", "-", "1...
Merge two intervals into one.
[ "Merge", "two", "intervals", "into", "one", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/merge_intervals.py#L47-L55
21,540
keon/algorithms
algorithms/arrays/merge_intervals.py
Interval.print_intervals
def print_intervals(intervals): """ Print out the intervals. """ res = [] for i in intervals: res.append(repr(i)) print("".join(res))
python
def print_intervals(intervals): """ Print out the intervals. """ res = [] for i in intervals: res.append(repr(i)) print("".join(res))
[ "def", "print_intervals", "(", "intervals", ")", ":", "res", "=", "[", "]", "for", "i", "in", "intervals", ":", "res", ".", "append", "(", "repr", "(", "i", ")", ")", "print", "(", "\"\"", ".", "join", "(", "res", ")", ")" ]
Print out the intervals.
[ "Print", "out", "the", "intervals", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/arrays/merge_intervals.py#L58-L63
21,541
keon/algorithms
algorithms/sort/heap_sort.py
max_heapify
def max_heapify(arr, end, simulation, iteration): """ Max heapify helper for max_heap_sort """ last_parent = (end - 1) // 2 # Iterate from last parent to first for parent in range(last_parent, -1, -1): current_parent = parent # Iterate from current_parent to last_parent whi...
python
def max_heapify(arr, end, simulation, iteration): """ Max heapify helper for max_heap_sort """ last_parent = (end - 1) // 2 # Iterate from last parent to first for parent in range(last_parent, -1, -1): current_parent = parent # Iterate from current_parent to last_parent whi...
[ "def", "max_heapify", "(", "arr", ",", "end", ",", "simulation", ",", "iteration", ")", ":", "last_parent", "=", "(", "end", "-", "1", ")", "//", "2", "# Iterate from last parent to first", "for", "parent", "in", "range", "(", "last_parent", ",", "-", "1",...
Max heapify helper for max_heap_sort
[ "Max", "heapify", "helper", "for", "max_heap_sort" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/heap_sort.py#L18-L45
21,542
keon/algorithms
algorithms/sort/heap_sort.py
min_heapify
def min_heapify(arr, start, simulation, iteration): """ Min heapify helper for min_heap_sort """ # Offset last_parent by the start (last_parent calculated as if start index was 0) # All array accesses need to be offset by start end = len(arr) - 1 last_parent = (end - start - 1) // 2 # Itera...
python
def min_heapify(arr, start, simulation, iteration): """ Min heapify helper for min_heap_sort """ # Offset last_parent by the start (last_parent calculated as if start index was 0) # All array accesses need to be offset by start end = len(arr) - 1 last_parent = (end - start - 1) // 2 # Itera...
[ "def", "min_heapify", "(", "arr", ",", "start", ",", "simulation", ",", "iteration", ")", ":", "# Offset last_parent by the start (last_parent calculated as if start index was 0)", "# All array accesses need to be offset by start", "end", "=", "len", "(", "arr", ")", "-", "...
Min heapify helper for min_heap_sort
[ "Min", "heapify", "helper", "for", "min_heap_sort" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/heap_sort.py#L61-L92
21,543
keon/algorithms
algorithms/maths/rsa.py
generate_key
def generate_key(k, seed=None): """ the RSA key generating algorithm k is the number of bits in n """ def modinv(a, m): """calculate the inverse of a mod m that is, find b such that (a * b) % m == 1""" b = 1 while not (a * b) % m == 1: b += 1 retu...
python
def generate_key(k, seed=None): """ the RSA key generating algorithm k is the number of bits in n """ def modinv(a, m): """calculate the inverse of a mod m that is, find b such that (a * b) % m == 1""" b = 1 while not (a * b) % m == 1: b += 1 retu...
[ "def", "generate_key", "(", "k", ",", "seed", "=", "None", ")", ":", "def", "modinv", "(", "a", ",", "m", ")", ":", "\"\"\"calculate the inverse of a mod m\n that is, find b such that (a * b) % m == 1\"\"\"", "b", "=", "1", "while", "not", "(", "a", "*", ...
the RSA key generating algorithm k is the number of bits in n
[ "the", "RSA", "key", "generating", "algorithm", "k", "is", "the", "number", "of", "bits", "in", "n" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/rsa.py#L27-L78
21,544
keon/algorithms
algorithms/maths/sqrt_precision_factor.py
square_root
def square_root(n, epsilon=0.001): """Return square root of n, with maximum absolute error epsilon""" guess = n / 2 while abs(guess * guess - n) > epsilon: guess = (guess + (n / guess)) / 2 return guess
python
def square_root(n, epsilon=0.001): """Return square root of n, with maximum absolute error epsilon""" guess = n / 2 while abs(guess * guess - n) > epsilon: guess = (guess + (n / guess)) / 2 return guess
[ "def", "square_root", "(", "n", ",", "epsilon", "=", "0.001", ")", ":", "guess", "=", "n", "/", "2", "while", "abs", "(", "guess", "*", "guess", "-", "n", ")", ">", "epsilon", ":", "guess", "=", "(", "guess", "+", "(", "n", "/", "guess", ")", ...
Return square root of n, with maximum absolute error epsilon
[ "Return", "square", "root", "of", "n", "with", "maximum", "absolute", "error", "epsilon" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/sqrt_precision_factor.py#L12-L19
21,545
keon/algorithms
algorithms/set/set_covering.py
powerset
def powerset(iterable): """Calculate the powerset of any iterable. For a range of integers up to the length of the given list, make all possible combinations and chain them together as one object. From https://docs.python.org/3/library/itertools.html#itertools-recipes """ "list(powerset([1,2,3]...
python
def powerset(iterable): """Calculate the powerset of any iterable. For a range of integers up to the length of the given list, make all possible combinations and chain them together as one object. From https://docs.python.org/3/library/itertools.html#itertools-recipes """ "list(powerset([1,2,3]...
[ "def", "powerset", "(", "iterable", ")", ":", "\"list(powerset([1,2,3])) --> [(), (1,), (2,), (3,), (1,2), (1,3), (2,3), (1,2,3)]\"", "s", "=", "list", "(", "iterable", ")", "return", "chain", ".", "from_iterable", "(", "combinations", "(", "s", ",", "r", ")", "for", ...
Calculate the powerset of any iterable. For a range of integers up to the length of the given list, make all possible combinations and chain them together as one object. From https://docs.python.org/3/library/itertools.html#itertools-recipes
[ "Calculate", "the", "powerset", "of", "any", "iterable", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/set/set_covering.py#L25-L34
21,546
keon/algorithms
algorithms/set/set_covering.py
greedy_set_cover
def greedy_set_cover(universe, subsets, costs): """Approximate greedy algorithm for set-covering. Can be used on large inputs - though not an optimal solution. Args: universe (list): Universe of elements subsets (dict): Subsets of U {S1:elements,S2:elements} costs (dict): Costs of e...
python
def greedy_set_cover(universe, subsets, costs): """Approximate greedy algorithm for set-covering. Can be used on large inputs - though not an optimal solution. Args: universe (list): Universe of elements subsets (dict): Subsets of U {S1:elements,S2:elements} costs (dict): Costs of e...
[ "def", "greedy_set_cover", "(", "universe", ",", "subsets", ",", "costs", ")", ":", "elements", "=", "set", "(", "e", "for", "s", "in", "subsets", ".", "keys", "(", ")", "for", "e", "in", "subsets", "[", "s", "]", ")", "# elements don't cover universe ->...
Approximate greedy algorithm for set-covering. Can be used on large inputs - though not an optimal solution. Args: universe (list): Universe of elements subsets (dict): Subsets of U {S1:elements,S2:elements} costs (dict): Costs of each subset in S - {S1:cost, S2:cost...}
[ "Approximate", "greedy", "algorithm", "for", "set", "-", "covering", ".", "Can", "be", "used", "on", "large", "inputs", "-", "though", "not", "an", "optimal", "solution", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/set/set_covering.py#L61-L95
21,547
keon/algorithms
algorithms/tree/avl/avl.py
AvlTree.insert
def insert(self, key): """ Insert new key into node """ # Create new node n = TreeNode(key) if not self.node: self.node = n self.node.left = AvlTree() self.node.right = AvlTree() elif key < self.node.val: self.node.l...
python
def insert(self, key): """ Insert new key into node """ # Create new node n = TreeNode(key) if not self.node: self.node = n self.node.left = AvlTree() self.node.right = AvlTree() elif key < self.node.val: self.node.l...
[ "def", "insert", "(", "self", ",", "key", ")", ":", "# Create new node", "n", "=", "TreeNode", "(", "key", ")", "if", "not", "self", ".", "node", ":", "self", ".", "node", "=", "n", "self", ".", "node", ".", "left", "=", "AvlTree", "(", ")", "sel...
Insert new key into node
[ "Insert", "new", "key", "into", "node" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/avl/avl.py#L15-L29
21,548
keon/algorithms
algorithms/tree/avl/avl.py
AvlTree.re_balance
def re_balance(self): """ Re balance tree. After inserting or deleting a node, """ self.update_heights(recursive=False) self.update_balances(False) while self.balance < -1 or self.balance > 1: if self.balance > 1: if self.node.left.balance < 0...
python
def re_balance(self): """ Re balance tree. After inserting or deleting a node, """ self.update_heights(recursive=False) self.update_balances(False) while self.balance < -1 or self.balance > 1: if self.balance > 1: if self.node.left.balance < 0...
[ "def", "re_balance", "(", "self", ")", ":", "self", ".", "update_heights", "(", "recursive", "=", "False", ")", "self", ".", "update_balances", "(", "False", ")", "while", "self", ".", "balance", "<", "-", "1", "or", "self", ".", "balance", ">", "1", ...
Re balance tree. After inserting or deleting a node,
[ "Re", "balance", "tree", ".", "After", "inserting", "or", "deleting", "a", "node" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/avl/avl.py#L31-L55
21,549
keon/algorithms
algorithms/tree/avl/avl.py
AvlTree.update_heights
def update_heights(self, recursive=True): """ Update tree height """ if self.node: if recursive: if self.node.left: self.node.left.update_heights() if self.node.right: self.node.right.update_heights() ...
python
def update_heights(self, recursive=True): """ Update tree height """ if self.node: if recursive: if self.node.left: self.node.left.update_heights() if self.node.right: self.node.right.update_heights() ...
[ "def", "update_heights", "(", "self", ",", "recursive", "=", "True", ")", ":", "if", "self", ".", "node", ":", "if", "recursive", ":", "if", "self", ".", "node", ".", "left", ":", "self", ".", "node", ".", "left", ".", "update_heights", "(", ")", "...
Update tree height
[ "Update", "tree", "height" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/avl/avl.py#L57-L70
21,550
keon/algorithms
algorithms/tree/avl/avl.py
AvlTree.update_balances
def update_balances(self, recursive=True): """ Calculate tree balance factor """ if self.node: if recursive: if self.node.left: self.node.left.update_balances() if self.node.right: self.node.right.update...
python
def update_balances(self, recursive=True): """ Calculate tree balance factor """ if self.node: if recursive: if self.node.left: self.node.left.update_balances() if self.node.right: self.node.right.update...
[ "def", "update_balances", "(", "self", ",", "recursive", "=", "True", ")", ":", "if", "self", ".", "node", ":", "if", "recursive", ":", "if", "self", ".", "node", ".", "left", ":", "self", ".", "node", ".", "left", ".", "update_balances", "(", ")", ...
Calculate tree balance factor
[ "Calculate", "tree", "balance", "factor" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/avl/avl.py#L72-L86
21,551
keon/algorithms
algorithms/tree/avl/avl.py
AvlTree.in_order_traverse
def in_order_traverse(self): """ In-order traversal of the tree """ result = [] if not self.node: return result result.extend(self.node.left.in_order_traverse()) result.append(self.node.key) result.extend(self.node.right.in_order_traverse()) ...
python
def in_order_traverse(self): """ In-order traversal of the tree """ result = [] if not self.node: return result result.extend(self.node.left.in_order_traverse()) result.append(self.node.key) result.extend(self.node.right.in_order_traverse()) ...
[ "def", "in_order_traverse", "(", "self", ")", ":", "result", "=", "[", "]", "if", "not", "self", ".", "node", ":", "return", "result", "result", ".", "extend", "(", "self", ".", "node", ".", "left", ".", "in_order_traverse", "(", ")", ")", "result", ...
In-order traversal of the tree
[ "In", "-", "order", "traversal", "of", "the", "tree" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/avl/avl.py#L112-L124
21,552
keon/algorithms
algorithms/linkedlist/kth_to_last.py
kth_to_last_dict
def kth_to_last_dict(head, k): """ This is a brute force method where we keep a dict the size of the list Then we check it for the value we need. If the key is not in the dict, our and statement will short circuit and return False """ if not (head and k > -1): return False d = dict()...
python
def kth_to_last_dict(head, k): """ This is a brute force method where we keep a dict the size of the list Then we check it for the value we need. If the key is not in the dict, our and statement will short circuit and return False """ if not (head and k > -1): return False d = dict()...
[ "def", "kth_to_last_dict", "(", "head", ",", "k", ")", ":", "if", "not", "(", "head", "and", "k", ">", "-", "1", ")", ":", "return", "False", "d", "=", "dict", "(", ")", "count", "=", "0", "while", "head", ":", "d", "[", "count", "]", "=", "h...
This is a brute force method where we keep a dict the size of the list Then we check it for the value we need. If the key is not in the dict, our and statement will short circuit and return False
[ "This", "is", "a", "brute", "force", "method", "where", "we", "keep", "a", "dict", "the", "size", "of", "the", "list", "Then", "we", "check", "it", "for", "the", "value", "we", "need", ".", "If", "the", "key", "is", "not", "in", "the", "dict", "our...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/kth_to_last.py#L27-L41
21,553
keon/algorithms
algorithms/linkedlist/kth_to_last.py
kth_to_last
def kth_to_last(head, k): """ This is an optimal method using iteration. We move p1 k steps ahead into the list. Then we move p1 and p2 together until p1 hits the end. """ if not (head or k > -1): return False p1 = head p2 = head for i in range(1, k+1): if p1 is None:...
python
def kth_to_last(head, k): """ This is an optimal method using iteration. We move p1 k steps ahead into the list. Then we move p1 and p2 together until p1 hits the end. """ if not (head or k > -1): return False p1 = head p2 = head for i in range(1, k+1): if p1 is None:...
[ "def", "kth_to_last", "(", "head", ",", "k", ")", ":", "if", "not", "(", "head", "or", "k", ">", "-", "1", ")", ":", "return", "False", "p1", "=", "head", "p2", "=", "head", "for", "i", "in", "range", "(", "1", ",", "k", "+", "1", ")", ":",...
This is an optimal method using iteration. We move p1 k steps ahead into the list. Then we move p1 and p2 together until p1 hits the end.
[ "This", "is", "an", "optimal", "method", "using", "iteration", ".", "We", "move", "p1", "k", "steps", "ahead", "into", "the", "list", ".", "Then", "we", "move", "p1", "and", "p2", "together", "until", "p1", "hits", "the", "end", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/kth_to_last.py#L44-L62
21,554
keon/algorithms
algorithms/maths/combination.py
combination
def combination(n, r): """This function calculates nCr.""" if n == r or r == 0: return 1 else: return combination(n-1, r-1) + combination(n-1, r)
python
def combination(n, r): """This function calculates nCr.""" if n == r or r == 0: return 1 else: return combination(n-1, r-1) + combination(n-1, r)
[ "def", "combination", "(", "n", ",", "r", ")", ":", "if", "n", "==", "r", "or", "r", "==", "0", ":", "return", "1", "else", ":", "return", "combination", "(", "n", "-", "1", ",", "r", "-", "1", ")", "+", "combination", "(", "n", "-", "1", "...
This function calculates nCr.
[ "This", "function", "calculates", "nCr", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/combination.py#L1-L6
21,555
keon/algorithms
algorithms/maths/combination.py
combination_memo
def combination_memo(n, r): """This function calculates nCr using memoization method.""" memo = {} def recur(n, r): if n == r or r == 0: return 1 if (n, r) not in memo: memo[(n, r)] = recur(n - 1, r - 1) + recur(n - 1, r) return memo[(n, r)] return recur(n...
python
def combination_memo(n, r): """This function calculates nCr using memoization method.""" memo = {} def recur(n, r): if n == r or r == 0: return 1 if (n, r) not in memo: memo[(n, r)] = recur(n - 1, r - 1) + recur(n - 1, r) return memo[(n, r)] return recur(n...
[ "def", "combination_memo", "(", "n", ",", "r", ")", ":", "memo", "=", "{", "}", "def", "recur", "(", "n", ",", "r", ")", ":", "if", "n", "==", "r", "or", "r", "==", "0", ":", "return", "1", "if", "(", "n", ",", "r", ")", "not", "in", "mem...
This function calculates nCr using memoization method.
[ "This", "function", "calculates", "nCr", "using", "memoization", "method", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/combination.py#L8-L17
21,556
keon/algorithms
algorithms/sort/pancake_sort.py
pancake_sort
def pancake_sort(arr): """ Pancake_sort Sorting a given array mutation of selection sort reference: https://www.geeksforgeeks.org/pancake-sorting/ Overall time complexity : O(N^2) """ len_arr = len(arr) if len_arr <= 1: return arr for cur in range(len(arr), 1, -1):...
python
def pancake_sort(arr): """ Pancake_sort Sorting a given array mutation of selection sort reference: https://www.geeksforgeeks.org/pancake-sorting/ Overall time complexity : O(N^2) """ len_arr = len(arr) if len_arr <= 1: return arr for cur in range(len(arr), 1, -1):...
[ "def", "pancake_sort", "(", "arr", ")", ":", "len_arr", "=", "len", "(", "arr", ")", "if", "len_arr", "<=", "1", ":", "return", "arr", "for", "cur", "in", "range", "(", "len", "(", "arr", ")", ",", "1", ",", "-", "1", ")", ":", "#Finding index of...
Pancake_sort Sorting a given array mutation of selection sort reference: https://www.geeksforgeeks.org/pancake-sorting/ Overall time complexity : O(N^2)
[ "Pancake_sort", "Sorting", "a", "given", "array", "mutation", "of", "selection", "sort" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/pancake_sort.py#L1-L25
21,557
keon/algorithms
algorithms/graph/satisfiability.py
scc
def scc(graph): ''' Computes the strongly connected components of a graph ''' order = [] vis = {vertex: False for vertex in graph} graph_transposed = {vertex: [] for vertex in graph} for (v, neighbours) in graph.iteritems(): for u in neighbours: add_edge(graph_transposed, u, v)...
python
def scc(graph): ''' Computes the strongly connected components of a graph ''' order = [] vis = {vertex: False for vertex in graph} graph_transposed = {vertex: [] for vertex in graph} for (v, neighbours) in graph.iteritems(): for u in neighbours: add_edge(graph_transposed, u, v)...
[ "def", "scc", "(", "graph", ")", ":", "order", "=", "[", "]", "vis", "=", "{", "vertex", ":", "False", "for", "vertex", "in", "graph", "}", "graph_transposed", "=", "{", "vertex", ":", "[", "]", "for", "vertex", "in", "graph", "}", "for", "(", "v...
Computes the strongly connected components of a graph
[ "Computes", "the", "strongly", "connected", "components", "of", "a", "graph" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/graph/satisfiability.py#L49-L74
21,558
keon/algorithms
algorithms/graph/satisfiability.py
build_graph
def build_graph(formula): ''' Builds the implication graph from the formula ''' graph = {} for clause in formula: for (lit, _) in clause: for neg in [False, True]: graph[(lit, neg)] = [] for ((a_lit, a_neg), (b_lit, b_neg)) in formula: add_edge(graph, (a_lit...
python
def build_graph(formula): ''' Builds the implication graph from the formula ''' graph = {} for clause in formula: for (lit, _) in clause: for neg in [False, True]: graph[(lit, neg)] = [] for ((a_lit, a_neg), (b_lit, b_neg)) in formula: add_edge(graph, (a_lit...
[ "def", "build_graph", "(", "formula", ")", ":", "graph", "=", "{", "}", "for", "clause", "in", "formula", ":", "for", "(", "lit", ",", "_", ")", "in", "clause", ":", "for", "neg", "in", "[", "False", ",", "True", "]", ":", "graph", "[", "(", "l...
Builds the implication graph from the formula
[ "Builds", "the", "implication", "graph", "from", "the", "formula" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/graph/satisfiability.py#L77-L90
21,559
keon/algorithms
algorithms/tree/is_balanced.py
__get_depth
def __get_depth(root): """ return 0 if unbalanced else depth + 1 """ if root is None: return 0 left = __get_depth(root.left) right = __get_depth(root.right) if abs(left-right) > 1 or -1 in [left, right]: return -1 return 1 + max(left, right)
python
def __get_depth(root): """ return 0 if unbalanced else depth + 1 """ if root is None: return 0 left = __get_depth(root.left) right = __get_depth(root.right) if abs(left-right) > 1 or -1 in [left, right]: return -1 return 1 + max(left, right)
[ "def", "__get_depth", "(", "root", ")", ":", "if", "root", "is", "None", ":", "return", "0", "left", "=", "__get_depth", "(", "root", ".", "left", ")", "right", "=", "__get_depth", "(", "root", ".", "right", ")", "if", "abs", "(", "left", "-", "rig...
return 0 if unbalanced else depth + 1
[ "return", "0", "if", "unbalanced", "else", "depth", "+", "1" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/is_balanced.py#L12-L22
21,560
keon/algorithms
algorithms/backtrack/palindrome_partitioning.py
palindromic_substrings_iter
def palindromic_substrings_iter(s): """ A slightly more Pythonic approach with a recursive generator """ if not s: yield [] return for i in range(len(s), 0, -1): sub = s[:i] if sub == sub[::-1]: for rest in palindromic_substrings_iter(s[i:]): ...
python
def palindromic_substrings_iter(s): """ A slightly more Pythonic approach with a recursive generator """ if not s: yield [] return for i in range(len(s), 0, -1): sub = s[:i] if sub == sub[::-1]: for rest in palindromic_substrings_iter(s[i:]): ...
[ "def", "palindromic_substrings_iter", "(", "s", ")", ":", "if", "not", "s", ":", "yield", "[", "]", "return", "for", "i", "in", "range", "(", "len", "(", "s", ")", ",", "0", ",", "-", "1", ")", ":", "sub", "=", "s", "[", ":", "i", "]", "if", ...
A slightly more Pythonic approach with a recursive generator
[ "A", "slightly", "more", "Pythonic", "approach", "with", "a", "recursive", "generator" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/palindrome_partitioning.py#L34-L45
21,561
keon/algorithms
algorithms/calculator/math_parser.py
main
def main(): """ simple user-interface """ print("\t\tCalculator\n\n") while True: user_input = input("expression or exit: ") if user_input == "exit": break try: print("The result is {0}".format(evaluate(user_input))) except Excep...
python
def main(): """ simple user-interface """ print("\t\tCalculator\n\n") while True: user_input = input("expression or exit: ") if user_input == "exit": break try: print("The result is {0}".format(evaluate(user_input))) except Excep...
[ "def", "main", "(", ")", ":", "print", "(", "\"\\t\\tCalculator\\n\\n\"", ")", "while", "True", ":", "user_input", "=", "input", "(", "\"expression or exit: \"", ")", "if", "user_input", "==", "\"exit\"", ":", "break", "try", ":", "print", "(", "\"The result i...
simple user-interface
[ "simple", "user", "-", "interface" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L131-L145
21,562
keon/algorithms
algorithms/maths/primes_sieve_of_eratosthenes.py
get_primes
def get_primes(n): """Return list of all primes less than n, Using sieve of Eratosthenes. """ if n <= 0: raise ValueError("'n' must be a positive integer.") # If x is even, exclude x from list (-1): sieve_size = (n // 2 - 1) if n % 2 == 0 else (n // 2) sieve = [True for _ in range(si...
python
def get_primes(n): """Return list of all primes less than n, Using sieve of Eratosthenes. """ if n <= 0: raise ValueError("'n' must be a positive integer.") # If x is even, exclude x from list (-1): sieve_size = (n // 2 - 1) if n % 2 == 0 else (n // 2) sieve = [True for _ in range(si...
[ "def", "get_primes", "(", "n", ")", ":", "if", "n", "<=", "0", ":", "raise", "ValueError", "(", "\"'n' must be a positive integer.\"", ")", "# If x is even, exclude x from list (-1):", "sieve_size", "=", "(", "n", "//", "2", "-", "1", ")", "if", "n", "%", "2...
Return list of all primes less than n, Using sieve of Eratosthenes.
[ "Return", "list", "of", "all", "primes", "less", "than", "n", "Using", "sieve", "of", "Eratosthenes", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/primes_sieve_of_eratosthenes.py#L28-L46
21,563
keon/algorithms
algorithms/backtrack/permute.py
permute
def permute(elements): """ returns a list with the permuations. """ if len(elements) <= 1: return [elements] else: tmp = [] for perm in permute(elements[1:]): for i in range(len(elements)): tmp.append(perm[:i] + elements[0:1] + perm[i:]) ...
python
def permute(elements): """ returns a list with the permuations. """ if len(elements) <= 1: return [elements] else: tmp = [] for perm in permute(elements[1:]): for i in range(len(elements)): tmp.append(perm[:i] + elements[0:1] + perm[i:]) ...
[ "def", "permute", "(", "elements", ")", ":", "if", "len", "(", "elements", ")", "<=", "1", ":", "return", "[", "elements", "]", "else", ":", "tmp", "=", "[", "]", "for", "perm", "in", "permute", "(", "elements", "[", "1", ":", "]", ")", ":", "f...
returns a list with the permuations.
[ "returns", "a", "list", "with", "the", "permuations", "." ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/permute.py#L17-L28
21,564
dmlc/xgboost
python-package/xgboost/rabit.py
_init_rabit
def _init_rabit(): """internal library initializer.""" if _LIB is not None: _LIB.RabitGetRank.restype = ctypes.c_int _LIB.RabitGetWorldSize.restype = ctypes.c_int _LIB.RabitIsDistributed.restype = ctypes.c_int _LIB.RabitVersionNumber.restype = ctypes.c_int
python
def _init_rabit(): """internal library initializer.""" if _LIB is not None: _LIB.RabitGetRank.restype = ctypes.c_int _LIB.RabitGetWorldSize.restype = ctypes.c_int _LIB.RabitIsDistributed.restype = ctypes.c_int _LIB.RabitVersionNumber.restype = ctypes.c_int
[ "def", "_init_rabit", "(", ")", ":", "if", "_LIB", "is", "not", "None", ":", "_LIB", ".", "RabitGetRank", ".", "restype", "=", "ctypes", ".", "c_int", "_LIB", ".", "RabitGetWorldSize", ".", "restype", "=", "ctypes", ".", "c_int", "_LIB", ".", "RabitIsDis...
internal library initializer.
[ "internal", "library", "initializer", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L14-L20
21,565
dmlc/xgboost
python-package/xgboost/rabit.py
init
def init(args=None): """Initialize the rabit library with arguments""" if args is None: args = [] arr = (ctypes.c_char_p * len(args))() arr[:] = args _LIB.RabitInit(len(arr), arr)
python
def init(args=None): """Initialize the rabit library with arguments""" if args is None: args = [] arr = (ctypes.c_char_p * len(args))() arr[:] = args _LIB.RabitInit(len(arr), arr)
[ "def", "init", "(", "args", "=", "None", ")", ":", "if", "args", "is", "None", ":", "args", "=", "[", "]", "arr", "=", "(", "ctypes", ".", "c_char_p", "*", "len", "(", "args", ")", ")", "(", ")", "arr", "[", ":", "]", "=", "args", "_LIB", "...
Initialize the rabit library with arguments
[ "Initialize", "the", "rabit", "library", "with", "arguments" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L23-L29
21,566
dmlc/xgboost
python-package/xgboost/rabit.py
get_processor_name
def get_processor_name(): """Get the processor name. Returns ------- name : str the name of processor(host) """ mxlen = 256 length = ctypes.c_ulong() buf = ctypes.create_string_buffer(mxlen) _LIB.RabitGetProcessorName(buf, ctypes.byref(length), mxlen) return buf.value
python
def get_processor_name(): """Get the processor name. Returns ------- name : str the name of processor(host) """ mxlen = 256 length = ctypes.c_ulong() buf = ctypes.create_string_buffer(mxlen) _LIB.RabitGetProcessorName(buf, ctypes.byref(length), mxlen) return buf.value
[ "def", "get_processor_name", "(", ")", ":", "mxlen", "=", "256", "length", "=", "ctypes", ".", "c_ulong", "(", ")", "buf", "=", "ctypes", ".", "create_string_buffer", "(", "mxlen", ")", "_LIB", ".", "RabitGetProcessorName", "(", "buf", ",", "ctypes", ".", ...
Get the processor name. Returns ------- name : str the name of processor(host)
[ "Get", "the", "processor", "name", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L82-L94
21,567
dmlc/xgboost
python-package/xgboost/rabit.py
broadcast
def broadcast(data, root): """Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- ...
python
def broadcast(data, root): """Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- ...
[ "def", "broadcast", "(", "data", ",", "root", ")", ":", "rank", "=", "get_rank", "(", ")", "length", "=", "ctypes", ".", "c_ulong", "(", ")", "if", "root", "==", "rank", ":", "assert", "data", "is", "not", "None", ",", "'need to pass in data when broadca...
Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- object : int the result...
[ "Broadcast", "object", "from", "one", "node", "to", "all", "other", "nodes", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L97-L132
21,568
dmlc/xgboost
jvm-packages/create_jni.py
normpath
def normpath(path): """Normalize UNIX path to a native path.""" normalized = os.path.join(*path.split("/")) if os.path.isabs(path): return os.path.abspath("/") + normalized else: return normalized
python
def normpath(path): """Normalize UNIX path to a native path.""" normalized = os.path.join(*path.split("/")) if os.path.isabs(path): return os.path.abspath("/") + normalized else: return normalized
[ "def", "normpath", "(", "path", ")", ":", "normalized", "=", "os", ".", "path", ".", "join", "(", "*", "path", ".", "split", "(", "\"/\"", ")", ")", "if", "os", ".", "path", ".", "isabs", "(", "path", ")", ":", "return", "os", ".", "path", ".",...
Normalize UNIX path to a native path.
[ "Normalize", "UNIX", "path", "to", "a", "native", "path", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/jvm-packages/create_jni.py#L61-L67
21,569
dmlc/xgboost
python-package/xgboost/training.py
CVPack.update
def update(self, iteration, fobj): """"Update the boosters for one iteration""" self.bst.update(self.dtrain, iteration, fobj)
python
def update(self, iteration, fobj): """"Update the boosters for one iteration""" self.bst.update(self.dtrain, iteration, fobj)
[ "def", "update", "(", "self", ",", "iteration", ",", "fobj", ")", ":", "self", ".", "bst", ".", "update", "(", "self", ".", "dtrain", ",", "iteration", ",", "fobj", ")" ]
Update the boosters for one iteration
[ "Update", "the", "boosters", "for", "one", "iteration" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L228-L230
21,570
dmlc/xgboost
python-package/xgboost/training.py
CVPack.eval
def eval(self, iteration, feval): """"Evaluate the CVPack for one iteration.""" return self.bst.eval_set(self.watchlist, iteration, feval)
python
def eval(self, iteration, feval): """"Evaluate the CVPack for one iteration.""" return self.bst.eval_set(self.watchlist, iteration, feval)
[ "def", "eval", "(", "self", ",", "iteration", ",", "feval", ")", ":", "return", "self", ".", "bst", ".", "eval_set", "(", "self", ".", "watchlist", ",", "iteration", ",", "feval", ")" ]
Evaluate the CVPack for one iteration.
[ "Evaluate", "the", "CVPack", "for", "one", "iteration", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L232-L234
21,571
dmlc/xgboost
python-package/xgboost/callback.py
_get_callback_context
def _get_callback_context(env): """return whether the current callback context is cv or train""" if env.model is not None and env.cvfolds is None: context = 'train' elif env.model is None and env.cvfolds is not None: context = 'cv' return context
python
def _get_callback_context(env): """return whether the current callback context is cv or train""" if env.model is not None and env.cvfolds is None: context = 'train' elif env.model is None and env.cvfolds is not None: context = 'cv' return context
[ "def", "_get_callback_context", "(", "env", ")", ":", "if", "env", ".", "model", "is", "not", "None", "and", "env", ".", "cvfolds", "is", "None", ":", "context", "=", "'train'", "elif", "env", ".", "model", "is", "None", "and", "env", ".", "cvfolds", ...
return whether the current callback context is cv or train
[ "return", "whether", "the", "current", "callback", "context", "is", "cv", "or", "train" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L10-L16
21,572
dmlc/xgboost
python-package/xgboost/callback.py
_fmt_metric
def _fmt_metric(value, show_stdv=True): """format metric string""" if len(value) == 2: return '%s:%g' % (value[0], value[1]) if len(value) == 3: if show_stdv: return '%s:%g+%g' % (value[0], value[1], value[2]) return '%s:%g' % (value[0], value[1]) raise ValueError("wr...
python
def _fmt_metric(value, show_stdv=True): """format metric string""" if len(value) == 2: return '%s:%g' % (value[0], value[1]) if len(value) == 3: if show_stdv: return '%s:%g+%g' % (value[0], value[1], value[2]) return '%s:%g' % (value[0], value[1]) raise ValueError("wr...
[ "def", "_fmt_metric", "(", "value", ",", "show_stdv", "=", "True", ")", ":", "if", "len", "(", "value", ")", "==", "2", ":", "return", "'%s:%g'", "%", "(", "value", "[", "0", "]", ",", "value", "[", "1", "]", ")", "if", "len", "(", "value", ")"...
format metric string
[ "format", "metric", "string" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L19-L27
21,573
dmlc/xgboost
python-package/xgboost/callback.py
print_evaluation
def print_evaluation(period=1, show_stdv=True): """Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show...
python
def print_evaluation(period=1, show_stdv=True): """Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show...
[ "def", "print_evaluation", "(", "period", "=", "1", ",", "show_stdv", "=", "True", ")", ":", "def", "callback", "(", "env", ")", ":", "\"\"\"internal function\"\"\"", "if", "env", ".", "rank", "!=", "0", "or", "(", "not", "env", ".", "evaluation_result_lis...
Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show_stdv : bool, optional Whether show stdv if pr...
[ "Create", "a", "callback", "that", "print", "evaluation", "result", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L30-L57
21,574
dmlc/xgboost
python-package/xgboost/callback.py
reset_learning_rate
def reset_learning_rate(learning_rates): """Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized funct...
python
def reset_learning_rate(learning_rates): """Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized funct...
[ "def", "reset_learning_rate", "(", "learning_rates", ")", ":", "def", "get_learning_rate", "(", "i", ",", "n", ",", "learning_rates", ")", ":", "\"\"\"helper providing the learning rate\"\"\"", "if", "isinstance", "(", "learning_rates", ",", "list", ")", ":", "if", ...
Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized function that calculates eta in terms of curr...
[ "Reset", "learning", "rate", "after", "iteration", "1" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L100-L145
21,575
dmlc/xgboost
python-package/xgboost/sklearn.py
_objective_decorator
def _objective_decorator(func): """Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred...
python
def _objective_decorator(func): """Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred...
[ "def", "_objective_decorator", "(", "func", ")", ":", "def", "inner", "(", "preds", ",", "dmatrix", ")", ":", "\"\"\"internal function\"\"\"", "labels", "=", "dmatrix", ".", "get_label", "(", ")", "return", "func", "(", "labels", ",", "preds", ")", "return",...
Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred)``: y_true: array_like of sha...
[ "Decorate", "an", "objective", "function" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L18-L50
21,576
dmlc/xgboost
python-package/xgboost/sklearn.py
XGBModel.apply
def apply(self, X, ntree_limit=0): """Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to ...
python
def apply(self, X, ntree_limit=0): """Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to ...
[ "def", "apply", "(", "self", ",", "X", ",", "ntree_limit", "=", "0", ")", ":", "test_dmatrix", "=", "DMatrix", "(", "X", ",", "missing", "=", "self", ".", "missing", ",", "nthread", "=", "self", ".", "n_jobs", ")", "return", "self", ".", "get_booster...
Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to 0 (use all trees). Returns --...
[ "Return", "the", "predicted", "leaf", "every", "tree", "for", "each", "sample", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L458-L479
21,577
dmlc/xgboost
python-package/xgboost/sklearn.py
XGBModel.feature_importances_
def feature_importances_(self): """ Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base...
python
def feature_importances_(self): """ Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base...
[ "def", "feature_importances_", "(", "self", ")", ":", "if", "getattr", "(", "self", ",", "'booster'", ",", "None", ")", "is", "not", "None", "and", "self", ".", "booster", "!=", "'gbtree'", ":", "raise", "AttributeError", "(", "'Feature importance is not defin...
Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base learner types, such as linear learners ...
[ "Feature", "importances", "property" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L524-L546
21,578
dmlc/xgboost
python-package/xgboost/sklearn.py
XGBClassifier.predict_proba
def predict_proba(self, data, ntree_limit=None, validate_features=True): """ Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you wan...
python
def predict_proba(self, data, ntree_limit=None, validate_features=True): """ Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you wan...
[ "def", "predict_proba", "(", "self", ",", "data", ",", "ntree_limit", "=", "None", ",", "validate_features", "=", "True", ")", ":", "test_dmatrix", "=", "DMatrix", "(", "data", ",", "missing", "=", "self", ".", "missing", ",", "nthread", "=", "self", "."...
Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thread, call ``xgb.copy()`` to make copies of ...
[ "Predict", "the", "probability", "of", "each", "data", "example", "being", "of", "a", "given", "class", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L803-L839
21,579
dmlc/xgboost
python-package/xgboost/core.py
from_pystr_to_cstr
def from_pystr_to_cstr(data): """Convert a list of Python str to C pointer Parameters ---------- data : list list of str """ if not isinstance(data, list): raise NotImplementedError pointers = (ctypes.c_char_p * len(data))() if PY3: data = [bytes(d, 'utf-8') for...
python
def from_pystr_to_cstr(data): """Convert a list of Python str to C pointer Parameters ---------- data : list list of str """ if not isinstance(data, list): raise NotImplementedError pointers = (ctypes.c_char_p * len(data))() if PY3: data = [bytes(d, 'utf-8') for...
[ "def", "from_pystr_to_cstr", "(", "data", ")", ":", "if", "not", "isinstance", "(", "data", ",", "list", ")", ":", "raise", "NotImplementedError", "pointers", "=", "(", "ctypes", ".", "c_char_p", "*", "len", "(", "data", ")", ")", "(", ")", "if", "PY3"...
Convert a list of Python str to C pointer Parameters ---------- data : list list of str
[ "Convert", "a", "list", "of", "Python", "str", "to", "C", "pointer" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L60-L78
21,580
dmlc/xgboost
python-package/xgboost/core.py
from_cstr_to_pystr
def from_cstr_to_pystr(data, length): """Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data """ if PY3: res = [] for i in range(length.value): try: ...
python
def from_cstr_to_pystr(data, length): """Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data """ if PY3: res = [] for i in range(length.value): try: ...
[ "def", "from_cstr_to_pystr", "(", "data", ",", "length", ")", ":", "if", "PY3", ":", "res", "=", "[", "]", "for", "i", "in", "range", "(", "length", ".", "value", ")", ":", "try", ":", "res", ".", "append", "(", "str", "(", "data", "[", "i", "]...
Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data
[ "Revert", "C", "pointer", "to", "Python", "str" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L81-L106
21,581
dmlc/xgboost
python-package/xgboost/core.py
_load_lib
def _load_lib(): """Load xgboost Library.""" lib_paths = find_lib_path() if not lib_paths: return None try: pathBackup = os.environ['PATH'].split(os.pathsep) except KeyError: pathBackup = [] lib_success = False os_error_list = [] for lib_path in lib_paths: ...
python
def _load_lib(): """Load xgboost Library.""" lib_paths = find_lib_path() if not lib_paths: return None try: pathBackup = os.environ['PATH'].split(os.pathsep) except KeyError: pathBackup = [] lib_success = False os_error_list = [] for lib_path in lib_paths: ...
[ "def", "_load_lib", "(", ")", ":", "lib_paths", "=", "find_lib_path", "(", ")", "if", "not", "lib_paths", ":", "return", "None", "try", ":", "pathBackup", "=", "os", ".", "environ", "[", "'PATH'", "]", ".", "split", "(", "os", ".", "pathsep", ")", "e...
Load xgboost Library.
[ "Load", "xgboost", "Library", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L121-L157
21,582
dmlc/xgboost
python-package/xgboost/core.py
ctypes2buffer
def ctypes2buffer(cptr, length): """Convert ctypes pointer to buffer type.""" if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)): raise RuntimeError('expected char pointer') res = bytearray(length) rptr = (ctypes.c_char * length).from_buffer(res) if not ctypes.memmove(rptr, cptr, length)...
python
def ctypes2buffer(cptr, length): """Convert ctypes pointer to buffer type.""" if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)): raise RuntimeError('expected char pointer') res = bytearray(length) rptr = (ctypes.c_char * length).from_buffer(res) if not ctypes.memmove(rptr, cptr, length)...
[ "def", "ctypes2buffer", "(", "cptr", ",", "length", ")", ":", "if", "not", "isinstance", "(", "cptr", ",", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char", ")", ")", ":", "raise", "RuntimeError", "(", "'expected char pointer'", ")", "res", "=", "b...
Convert ctypes pointer to buffer type.
[ "Convert", "ctypes", "pointer", "to", "buffer", "type", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L197-L205
21,583
dmlc/xgboost
python-package/xgboost/core.py
c_array
def c_array(ctype, values): """Convert a python string to c array.""" if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype): return (ctype * len(values)).from_buffer_copy(values) return (ctype * len(values))(*values)
python
def c_array(ctype, values): """Convert a python string to c array.""" if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype): return (ctype * len(values)).from_buffer_copy(values) return (ctype * len(values))(*values)
[ "def", "c_array", "(", "ctype", ",", "values", ")", ":", "if", "isinstance", "(", "values", ",", "np", ".", "ndarray", ")", "and", "values", ".", "dtype", ".", "itemsize", "==", "ctypes", ".", "sizeof", "(", "ctype", ")", ":", "return", "(", "ctype",...
Convert a python string to c array.
[ "Convert", "a", "python", "string", "to", "c", "array", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L213-L217
21,584
dmlc/xgboost
python-package/xgboost/core.py
_maybe_dt_array
def _maybe_dt_array(array): """ Extract numpy array from single column data table """ if not isinstance(array, DataTable) or array is None: return array if array.shape[1] > 1: raise ValueError('DataTable for label or weight cannot have multiple columns') # below requires new dt version...
python
def _maybe_dt_array(array): """ Extract numpy array from single column data table """ if not isinstance(array, DataTable) or array is None: return array if array.shape[1] > 1: raise ValueError('DataTable for label or weight cannot have multiple columns') # below requires new dt version...
[ "def", "_maybe_dt_array", "(", "array", ")", ":", "if", "not", "isinstance", "(", "array", ",", "DataTable", ")", "or", "array", "is", "None", ":", "return", "array", "if", "array", ".", "shape", "[", "1", "]", ">", "1", ":", "raise", "ValueError", "...
Extract numpy array from single column data table
[ "Extract", "numpy", "array", "from", "single", "column", "data", "table" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L306-L318
21,585
dmlc/xgboost
python-package/xgboost/core.py
DMatrix._init_from_dt
def _init_from_dt(self, data, nthread): """ Initialize data from a datatable Frame. """ ptrs = (ctypes.c_void_p * data.ncols)() if hasattr(data, "internal") and hasattr(data.internal, "column"): # datatable>0.8.0 for icol in range(data.ncols): ...
python
def _init_from_dt(self, data, nthread): """ Initialize data from a datatable Frame. """ ptrs = (ctypes.c_void_p * data.ncols)() if hasattr(data, "internal") and hasattr(data.internal, "column"): # datatable>0.8.0 for icol in range(data.ncols): ...
[ "def", "_init_from_dt", "(", "self", ",", "data", ",", "nthread", ")", ":", "ptrs", "=", "(", "ctypes", ".", "c_void_p", "*", "data", ".", "ncols", ")", "(", ")", "if", "hasattr", "(", "data", ",", "\"internal\"", ")", "and", "hasattr", "(", "data", ...
Initialize data from a datatable Frame.
[ "Initialize", "data", "from", "a", "datatable", "Frame", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L498-L527
21,586
dmlc/xgboost
python-package/xgboost/core.py
DMatrix.set_float_info_npy2d
def set_float_info_npy2d(self, field, data): """Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ ...
python
def set_float_info_npy2d(self, field, data): """Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ ...
[ "def", "set_float_info_npy2d", "(", "self", ",", "field", ",", "data", ")", ":", "if", "getattr", "(", "data", ",", "'base'", ",", "None", ")", "is", "not", "None", "and", "data", ".", "base", "is", "not", "None", "and", "isinstance", "(", "data", ",...
Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set
[ "Set", "float", "type", "property", "into", "the", "DMatrix", "for", "numpy", "2d", "array", "input" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L598-L622
21,587
dmlc/xgboost
python-package/xgboost/core.py
Booster.load_rabit_checkpoint
def load_rabit_checkpoint(self): """Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model. """ version = ctypes.c_int() _check_call(_LIB.XGBoosterLoadRabitCheckpoint( self.hand...
python
def load_rabit_checkpoint(self): """Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model. """ version = ctypes.c_int() _check_call(_LIB.XGBoosterLoadRabitCheckpoint( self.hand...
[ "def", "load_rabit_checkpoint", "(", "self", ")", ":", "version", "=", "ctypes", ".", "c_int", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterLoadRabitCheckpoint", "(", "self", ".", "handle", ",", "ctypes", ".", "byref", "(", "version", ")", ")", ")"...
Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model.
[ "Initialize", "the", "model", "by", "load", "from", "rabit", "checkpoint", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1002-L1013
21,588
dmlc/xgboost
python-package/xgboost/core.py
Booster.attr
def attr(self, key): """Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist. """ ...
python
def attr(self, key): """Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist. """ ...
[ "def", "attr", "(", "self", ",", "key", ")", ":", "ret", "=", "ctypes", ".", "c_char_p", "(", ")", "success", "=", "ctypes", ".", "c_int", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterGetAttr", "(", "self", ".", "handle", ",", "c_str", "(", ...
Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist.
[ "Get", "attribute", "string", "from", "the", "Booster", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1019-L1038
21,589
dmlc/xgboost
python-package/xgboost/core.py
Booster.attributes
def attributes(self): """Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes. """ length = c_bst_ulong() sarr = ...
python
def attributes(self): """Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes. """ length = c_bst_ulong() sarr = ...
[ "def", "attributes", "(", "self", ")", ":", "length", "=", "c_bst_ulong", "(", ")", "sarr", "=", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char_p", ")", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterGetAttrNames", "(", "self", ".", "handle"...
Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes.
[ "Get", "attributes", "stored", "in", "the", "Booster", "as", "a", "dictionary", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1040-L1054
21,590
dmlc/xgboost
python-package/xgboost/core.py
Booster.set_attr
def set_attr(self, **kwargs): """Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute. """ for key, value in kwargs.items(): if value is not None: if n...
python
def set_attr(self, **kwargs): """Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute. """ for key, value in kwargs.items(): if value is not None: if n...
[ "def", "set_attr", "(", "self", ",", "*", "*", "kwargs", ")", ":", "for", "key", ",", "value", "in", "kwargs", ".", "items", "(", ")", ":", "if", "value", "is", "not", "None", ":", "if", "not", "isinstance", "(", "value", ",", "STRING_TYPES", ")", ...
Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute.
[ "Set", "the", "attribute", "of", "the", "Booster", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1056-L1070
21,591
dmlc/xgboost
python-package/xgboost/core.py
Booster.set_param
def set_param(self, params, value=None): """Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key...
python
def set_param(self, params, value=None): """Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key...
[ "def", "set_param", "(", "self", ",", "params", ",", "value", "=", "None", ")", ":", "if", "isinstance", "(", "params", ",", "Mapping", ")", ":", "params", "=", "params", ".", "items", "(", ")", "elif", "isinstance", "(", "params", ",", "STRING_TYPES",...
Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key
[ "Set", "parameters", "into", "the", "Booster", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1072-L1087
21,592
dmlc/xgboost
python-package/xgboost/core.py
Booster.eval
def eval(self, data, name='eval', iteration=0): """Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current ite...
python
def eval(self, data, name='eval', iteration=0): """Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current ite...
[ "def", "eval", "(", "self", ",", "data", ",", "name", "=", "'eval'", ",", "iteration", "=", "0", ")", ":", "self", ".", "_validate_features", "(", "data", ")", "return", "self", ".", "eval_set", "(", "[", "(", "data", ",", "name", ")", "]", ",", ...
Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current iteration number. Returns ------- res...
[ "Evaluate", "the", "model", "on", "mat", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1185-L1205
21,593
dmlc/xgboost
python-package/xgboost/core.py
Booster.save_model
def save_model(self, fname): """ Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To pre...
python
def save_model(self, fname): """ Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To pre...
[ "def", "save_model", "(", "self", ",", "fname", ")", ":", "if", "isinstance", "(", "fname", ",", "STRING_TYPES", ")", ":", "# assume file name", "_check_call", "(", "_LIB", ".", "XGBoosterSaveModel", "(", "self", ".", "handle", ",", "c_str", "(", "fname", ...
Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To preserve all attributes, pickle the Booster object. ...
[ "Save", "the", "model", "to", "a", "file", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1316-L1333
21,594
dmlc/xgboost
python-package/xgboost/core.py
Booster.dump_model
def dump_model(self, fout, fmap='', with_stats=False, dump_format="text"): """ Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. ...
python
def dump_model(self, fout, fmap='', with_stats=False, dump_format="text"): """ Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. ...
[ "def", "dump_model", "(", "self", ",", "fout", ",", "fmap", "=", "''", ",", "with_stats", "=", "False", ",", "dump_format", "=", "\"text\"", ")", ":", "if", "isinstance", "(", "fout", ",", "STRING_TYPES", ")", ":", "fout", "=", "open", "(", "fout", "...
Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls whether the split statistics are output. ...
[ "Dump", "model", "into", "a", "text", "or", "JSON", "file", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1373-L1406
21,595
dmlc/xgboost
python-package/xgboost/core.py
Booster.get_dump
def get_dump(self, fmap='', with_stats=False, dump_format="text"): """ Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls w...
python
def get_dump(self, fmap='', with_stats=False, dump_format="text"): """ Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls w...
[ "def", "get_dump", "(", "self", ",", "fmap", "=", "''", ",", "with_stats", "=", "False", ",", "dump_format", "=", "\"text\"", ")", ":", "length", "=", "c_bst_ulong", "(", ")", "sarr", "=", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char_p", ")", ...
Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls whether the split statistics are output. dump_format : string, optional ...
[ "Returns", "the", "model", "dump", "as", "a", "list", "of", "strings", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1408-L1453
21,596
dmlc/xgboost
python-package/xgboost/core.py
Booster.get_split_value_histogram
def get_split_value_histogram(self, feature, fmap='', bins=None, as_pandas=True): """Get split value histogram of a feature Parameters ---------- feature: str The name of the feature. fmap: str (optional) The name of feature map file. bin: int, de...
python
def get_split_value_histogram(self, feature, fmap='', bins=None, as_pandas=True): """Get split value histogram of a feature Parameters ---------- feature: str The name of the feature. fmap: str (optional) The name of feature map file. bin: int, de...
[ "def", "get_split_value_histogram", "(", "self", ",", "feature", ",", "fmap", "=", "''", ",", "bins", "=", "None", ",", "as_pandas", "=", "True", ")", ":", "xgdump", "=", "self", ".", "get_dump", "(", "fmap", "=", "fmap", ")", "values", "=", "[", "]"...
Get split value histogram of a feature Parameters ---------- feature: str The name of the feature. fmap: str (optional) The name of feature map file. bin: int, default None The maximum number of bins. Number of bins equals number o...
[ "Get", "split", "value", "histogram", "of", "a", "feature" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1692-L1733
21,597
dmlc/xgboost
python-package/xgboost/plotting.py
plot_importance
def plot_importance(booster, ax=None, height=0.2, xlim=None, ylim=None, title='Feature importance', xlabel='F score', ylabel='Features', importance_type='weight', max_num_features=None, grid=True, show_values=True, **kwargs): """Plot im...
python
def plot_importance(booster, ax=None, height=0.2, xlim=None, ylim=None, title='Feature importance', xlabel='F score', ylabel='Features', importance_type='weight', max_num_features=None, grid=True, show_values=True, **kwargs): """Plot im...
[ "def", "plot_importance", "(", "booster", ",", "ax", "=", "None", ",", "height", "=", "0.2", ",", "xlim", "=", "None", ",", "ylim", "=", "None", ",", "title", "=", "'Feature importance'", ",", "xlabel", "=", "'F score'", ",", "ylabel", "=", "'Features'",...
Plot importance based on fitted trees. Parameters ---------- booster : Booster, XGBModel or dict Booster or XGBModel instance, or dict taken by Booster.get_fscore() ax : matplotlib Axes, default None Target axes instance. If None, new figure and axes will be created. grid : bool, Tu...
[ "Plot", "importance", "based", "on", "fitted", "trees", "." ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/plotting.py#L14-L117
21,598
dmlc/xgboost
python-package/xgboost/plotting.py
_parse_edge
def _parse_edge(graph, node, text, yes_color='#0000FF', no_color='#FF0000'): """parse dumped edge""" try: match = _EDGEPAT.match(text) if match is not None: yes, no, missing = match.groups() if yes == missing: graph.edge(node, yes, label='yes, missing', co...
python
def _parse_edge(graph, node, text, yes_color='#0000FF', no_color='#FF0000'): """parse dumped edge""" try: match = _EDGEPAT.match(text) if match is not None: yes, no, missing = match.groups() if yes == missing: graph.edge(node, yes, label='yes, missing', co...
[ "def", "_parse_edge", "(", "graph", ",", "node", ",", "text", ",", "yes_color", "=", "'#0000FF'", ",", "no_color", "=", "'#FF0000'", ")", ":", "try", ":", "match", "=", "_EDGEPAT", ".", "match", "(", "text", ")", "if", "match", "is", "not", "None", "...
parse dumped edge
[ "parse", "dumped", "edge" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/plotting.py#L141-L162
21,599
tzutalin/labelImg
libs/utils.py
newAction
def newAction(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, enabled=True): """Create a new action and assign callbacks, shortcuts, etc.""" a = QAction(text, parent) if icon is not None: a.setIcon(newIcon(icon)) if shortcut is not None: if isi...
python
def newAction(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, enabled=True): """Create a new action and assign callbacks, shortcuts, etc.""" a = QAction(text, parent) if icon is not None: a.setIcon(newIcon(icon)) if shortcut is not None: if isi...
[ "def", "newAction", "(", "parent", ",", "text", ",", "slot", "=", "None", ",", "shortcut", "=", "None", ",", "icon", "=", "None", ",", "tip", "=", "None", ",", "checkable", "=", "False", ",", "enabled", "=", "True", ")", ":", "a", "=", "QAction", ...
Create a new action and assign callbacks, shortcuts, etc.
[ "Create", "a", "new", "action", "and", "assign", "callbacks", "shortcuts", "etc", "." ]
6afd15aa88f89f41254e0004ed219b3965eb2c0d
https://github.com/tzutalin/labelImg/blob/6afd15aa88f89f41254e0004ed219b3965eb2c0d/libs/utils.py#L29-L48