partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | _ArbitraryItemFormatter.get_value | Override to substitute {ATTRIBUTE} by attributes of our _item. | instaloader/instaloader.py | def get_value(self, key, args, kwargs):
"""Override to substitute {ATTRIBUTE} by attributes of our _item."""
if hasattr(self._item, key):
return getattr(self._item, key)
return super().get_value(key, args, kwargs) | def get_value(self, key, args, kwargs):
"""Override to substitute {ATTRIBUTE} by attributes of our _item."""
if hasattr(self._item, key):
return getattr(self._item, key)
return super().get_value(key, args, kwargs) | [
"Override",
"to",
"substitute",
"{",
"ATTRIBUTE",
"}",
"by",
"attributes",
"of",
"our",
"_item",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L88-L92 | [
"def",
"get_value",
"(",
"self",
",",
"key",
",",
"args",
",",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"_item",
",",
"key",
")",
":",
"return",
"getattr",
"(",
"self",
".",
"_item",
",",
"key",
")",
"return",
"super",
"(",
")",
"."... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | _ArbitraryItemFormatter.format_field | Override :meth:`string.Formatter.format_field` to have our
default format_spec for :class:`datetime.Datetime` objects, and to
let None yield an empty string rather than ``None``. | instaloader/instaloader.py | def format_field(self, value, format_spec):
"""Override :meth:`string.Formatter.format_field` to have our
default format_spec for :class:`datetime.Datetime` objects, and to
let None yield an empty string rather than ``None``."""
if isinstance(value, datetime) and not format_spec:
... | def format_field(self, value, format_spec):
"""Override :meth:`string.Formatter.format_field` to have our
default format_spec for :class:`datetime.Datetime` objects, and to
let None yield an empty string rather than ``None``."""
if isinstance(value, datetime) and not format_spec:
... | [
"Override",
":",
"meth",
":",
"string",
".",
"Formatter",
".",
"format_field",
"to",
"have",
"our",
"default",
"format_spec",
"for",
":",
"class",
":",
"datetime",
".",
"Datetime",
"objects",
"and",
"to",
"let",
"None",
"yield",
"an",
"empty",
"string",
"r... | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L94-L102 | [
"def",
"format_field",
"(",
"self",
",",
"value",
",",
"format_spec",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"datetime",
")",
"and",
"not",
"format_spec",
":",
"return",
"super",
"(",
")",
".",
"format_field",
"(",
"value",
",",
"'%Y-%m-%d_%H-%M-... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | _PostPathFormatter.vformat | Override :meth:`string.Formatter.vformat` for character substitution in paths for Windows, see issue #84. | instaloader/instaloader.py | def vformat(self, format_string, args, kwargs):
"""Override :meth:`string.Formatter.vformat` for character substitution in paths for Windows, see issue #84."""
ret = super().vformat(format_string, args, kwargs)
if platform.system() == 'Windows':
ret = ret.replace(':', '\ua789').repla... | def vformat(self, format_string, args, kwargs):
"""Override :meth:`string.Formatter.vformat` for character substitution in paths for Windows, see issue #84."""
ret = super().vformat(format_string, args, kwargs)
if platform.system() == 'Windows':
ret = ret.replace(':', '\ua789').repla... | [
"Override",
":",
"meth",
":",
"string",
".",
"Formatter",
".",
"vformat",
"for",
"character",
"substitution",
"in",
"paths",
"for",
"Windows",
"see",
"issue",
"#84",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L106-L112 | [
"def",
"vformat",
"(",
"self",
",",
"format_string",
",",
"args",
",",
"kwargs",
")",
":",
"ret",
"=",
"super",
"(",
")",
".",
"vformat",
"(",
"format_string",
",",
"args",
",",
"kwargs",
")",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"'Window... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.anonymous_copy | Yield an anonymous, otherwise equally-configured copy of an Instaloader instance; Then copy its error log. | instaloader/instaloader.py | def anonymous_copy(self):
"""Yield an anonymous, otherwise equally-configured copy of an Instaloader instance; Then copy its error log."""
new_loader = Instaloader(self.context.sleep, self.context.quiet, self.context.user_agent, self.dirname_pattern,
self.filename_patter... | def anonymous_copy(self):
"""Yield an anonymous, otherwise equally-configured copy of an Instaloader instance; Then copy its error log."""
new_loader = Instaloader(self.context.sleep, self.context.quiet, self.context.user_agent, self.dirname_pattern,
self.filename_patter... | [
"Yield",
"an",
"anonymous",
"otherwise",
"equally",
"-",
"configured",
"copy",
"of",
"an",
"Instaloader",
"instance",
";",
"Then",
"copy",
"its",
"error",
"log",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L182-L196 | [
"def",
"anonymous_copy",
"(",
"self",
")",
":",
"new_loader",
"=",
"Instaloader",
"(",
"self",
".",
"context",
".",
"sleep",
",",
"self",
".",
"context",
".",
"quiet",
",",
"self",
".",
"context",
".",
"user_agent",
",",
"self",
".",
"dirname_pattern",
"... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_pic | Downloads and saves picture with given url under given directory with given timestamp.
Returns true, if file was actually downloaded, i.e. updated. | instaloader/instaloader.py | def download_pic(self, filename: str, url: str, mtime: datetime,
filename_suffix: Optional[str] = None, _attempt: int = 1) -> bool:
"""Downloads and saves picture with given url under given directory with given timestamp.
Returns true, if file was actually downloaded, i.e. updated."... | def download_pic(self, filename: str, url: str, mtime: datetime,
filename_suffix: Optional[str] = None, _attempt: int = 1) -> bool:
"""Downloads and saves picture with given url under given directory with given timestamp.
Returns true, if file was actually downloaded, i.e. updated."... | [
"Downloads",
"and",
"saves",
"picture",
"with",
"given",
"url",
"under",
"given",
"directory",
"with",
"given",
"timestamp",
".",
"Returns",
"true",
"if",
"file",
"was",
"actually",
"downloaded",
"i",
".",
"e",
".",
"updated",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L209-L229 | [
"def",
"download_pic",
"(",
"self",
",",
"filename",
":",
"str",
",",
"url",
":",
"str",
",",
"mtime",
":",
"datetime",
",",
"filename_suffix",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"_attempt",
":",
"int",
"=",
"1",
")",
"->",
"bool",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.save_metadata_json | Saves metadata JSON file of a structure. | instaloader/instaloader.py | def save_metadata_json(self, filename: str, structure: JsonExportable) -> None:
"""Saves metadata JSON file of a structure."""
if self.compress_json:
filename += '.json.xz'
else:
filename += '.json'
save_structure_to_file(structure, filename)
if isinstance... | def save_metadata_json(self, filename: str, structure: JsonExportable) -> None:
"""Saves metadata JSON file of a structure."""
if self.compress_json:
filename += '.json.xz'
else:
filename += '.json'
save_structure_to_file(structure, filename)
if isinstance... | [
"Saves",
"metadata",
"JSON",
"file",
"of",
"a",
"structure",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L231-L240 | [
"def",
"save_metadata_json",
"(",
"self",
",",
"filename",
":",
"str",
",",
"structure",
":",
"JsonExportable",
")",
"->",
"None",
":",
"if",
"self",
".",
"compress_json",
":",
"filename",
"+=",
"'.json.xz'",
"else",
":",
"filename",
"+=",
"'.json'",
"save_s... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.save_caption | Updates picture caption / Post metadata info | instaloader/instaloader.py | def save_caption(self, filename: str, mtime: datetime, caption: str) -> None:
"""Updates picture caption / Post metadata info"""
def _elliptify(caption):
pcaption = caption.replace('\n', ' ').strip()
return '[' + ((pcaption[:29] + u"\u2026") if len(pcaption) > 31 else pcaption) +... | def save_caption(self, filename: str, mtime: datetime, caption: str) -> None:
"""Updates picture caption / Post metadata info"""
def _elliptify(caption):
pcaption = caption.replace('\n', ' ').strip()
return '[' + ((pcaption[:29] + u"\u2026") if len(pcaption) > 31 else pcaption) +... | [
"Updates",
"picture",
"caption",
"/",
"Post",
"metadata",
"info"
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L284-L321 | [
"def",
"save_caption",
"(",
"self",
",",
"filename",
":",
"str",
",",
"mtime",
":",
"datetime",
",",
"caption",
":",
"str",
")",
"->",
"None",
":",
"def",
"_elliptify",
"(",
"caption",
")",
":",
"pcaption",
"=",
"caption",
".",
"replace",
"(",
"'\\n'",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.save_location | Save post location name and Google Maps link. | instaloader/instaloader.py | def save_location(self, filename: str, location: PostLocation, mtime: datetime) -> None:
"""Save post location name and Google Maps link."""
filename += '_location.txt'
location_string = (location.name + "\n" +
"https://maps.google.com/maps?q={0},{1}&ll={0},{1}\n".form... | def save_location(self, filename: str, location: PostLocation, mtime: datetime) -> None:
"""Save post location name and Google Maps link."""
filename += '_location.txt'
location_string = (location.name + "\n" +
"https://maps.google.com/maps?q={0},{1}&ll={0},{1}\n".form... | [
"Save",
"post",
"location",
"name",
"and",
"Google",
"Maps",
"link",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L323-L332 | [
"def",
"save_location",
"(",
"self",
",",
"filename",
":",
"str",
",",
"location",
":",
"PostLocation",
",",
"mtime",
":",
"datetime",
")",
"->",
"None",
":",
"filename",
"+=",
"'_location.txt'",
"location_string",
"=",
"(",
"location",
".",
"name",
"+",
"... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_profilepic | Downloads and saves profile pic. | instaloader/instaloader.py | def download_profilepic(self, profile: Profile, _attempt: int = 1) -> None:
"""Downloads and saves profile pic."""
def _epoch_to_string(epoch: datetime) -> str:
return epoch.strftime('%Y-%m-%d_%H-%M-%S_UTC')
profile_pic_response = self.context.get_raw(profile.profile_pic_url)
... | def download_profilepic(self, profile: Profile, _attempt: int = 1) -> None:
"""Downloads and saves profile pic."""
def _epoch_to_string(epoch: datetime) -> str:
return epoch.strftime('%Y-%m-%d_%H-%M-%S_UTC')
profile_pic_response = self.context.get_raw(profile.profile_pic_url)
... | [
"Downloads",
"and",
"saves",
"profile",
"pic",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L335-L367 | [
"def",
"download_profilepic",
"(",
"self",
",",
"profile",
":",
"Profile",
",",
"_attempt",
":",
"int",
"=",
"1",
")",
"->",
"None",
":",
"def",
"_epoch_to_string",
"(",
"epoch",
":",
"datetime",
")",
"->",
"str",
":",
"return",
"epoch",
".",
"strftime",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.save_session_to_file | Saves internally stored :class:`requests.Session` object.
:param filename: Filename, or None to use default filename. | instaloader/instaloader.py | def save_session_to_file(self, filename: Optional[str] = None) -> None:
"""Saves internally stored :class:`requests.Session` object.
:param filename: Filename, or None to use default filename.
"""
if filename is None:
filename = get_default_session_filename(self.context.user... | def save_session_to_file(self, filename: Optional[str] = None) -> None:
"""Saves internally stored :class:`requests.Session` object.
:param filename: Filename, or None to use default filename.
"""
if filename is None:
filename = get_default_session_filename(self.context.user... | [
"Saves",
"internally",
"stored",
":",
"class",
":",
"requests",
".",
"Session",
"object",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L370-L384 | [
"def",
"save_session_to_file",
"(",
"self",
",",
"filename",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"if",
"filename",
"is",
"None",
":",
"filename",
"=",
"get_default_session_filename",
"(",
"self",
".",
"context",
".",
"use... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.load_session_from_file | Internally stores :class:`requests.Session` object loaded from file.
If filename is None, the file with the default session path is loaded.
:raises FileNotFoundError: If the file does not exist. | instaloader/instaloader.py | def load_session_from_file(self, username: str, filename: Optional[str] = None) -> None:
"""Internally stores :class:`requests.Session` object loaded from file.
If filename is None, the file with the default session path is loaded.
:raises FileNotFoundError: If the file does not exist.
... | def load_session_from_file(self, username: str, filename: Optional[str] = None) -> None:
"""Internally stores :class:`requests.Session` object loaded from file.
If filename is None, the file with the default session path is loaded.
:raises FileNotFoundError: If the file does not exist.
... | [
"Internally",
"stores",
":",
"class",
":",
"requests",
".",
"Session",
"object",
"loaded",
"from",
"file",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L386-L397 | [
"def",
"load_session_from_file",
"(",
"self",
",",
"username",
":",
"str",
",",
"filename",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"if",
"filename",
"is",
"None",
":",
"filename",
"=",
"get_default_session_filename",
"(",
"u... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.login | Log in to instagram with given username and password and internally store session object.
:raises InvalidArgumentException: If the provided username does not exist.
:raises BadCredentialsException: If the provided password is wrong.
:raises ConnectionException: If connection to Instagram failed... | instaloader/instaloader.py | def login(self, user: str, passwd: str) -> None:
"""Log in to instagram with given username and password and internally store session object.
:raises InvalidArgumentException: If the provided username does not exist.
:raises BadCredentialsException: If the provided password is wrong.
:r... | def login(self, user: str, passwd: str) -> None:
"""Log in to instagram with given username and password and internally store session object.
:raises InvalidArgumentException: If the provided username does not exist.
:raises BadCredentialsException: If the provided password is wrong.
:r... | [
"Log",
"in",
"to",
"instagram",
"with",
"given",
"username",
"and",
"password",
"and",
"internally",
"store",
"session",
"object",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L403-L410 | [
"def",
"login",
"(",
"self",
",",
"user",
":",
"str",
",",
"passwd",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"context",
".",
"login",
"(",
"user",
",",
"passwd",
")"
] | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.format_filename | Format filename of a :class:`Post` or :class:`StoryItem` according to ``filename-pattern`` parameter.
.. versionadded:: 4.1 | instaloader/instaloader.py | def format_filename(self, item: Union[Post, StoryItem], target: Optional[str] = None):
"""Format filename of a :class:`Post` or :class:`StoryItem` according to ``filename-pattern`` parameter.
.. versionadded:: 4.1"""
return _PostPathFormatter(item).format(self.filename_pattern, target=target) | def format_filename(self, item: Union[Post, StoryItem], target: Optional[str] = None):
"""Format filename of a :class:`Post` or :class:`StoryItem` according to ``filename-pattern`` parameter.
.. versionadded:: 4.1"""
return _PostPathFormatter(item).format(self.filename_pattern, target=target) | [
"Format",
"filename",
"of",
"a",
":",
"class",
":",
"Post",
"or",
":",
"class",
":",
"StoryItem",
"according",
"to",
"filename",
"-",
"pattern",
"parameter",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L422-L426 | [
"def",
"format_filename",
"(",
"self",
",",
"item",
":",
"Union",
"[",
"Post",
",",
"StoryItem",
"]",
",",
"target",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
":",
"return",
"_PostPathFormatter",
"(",
"item",
")",
".",
"format",
"(",
"self",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_post | Download everything associated with one instagram post node, i.e. picture, caption and video.
:param post: Post to download.
:param target: Target name, i.e. profile name, #hashtag, :feed; for filename.
:return: True if something was downloaded, False otherwise, i.e. file was already there | instaloader/instaloader.py | def download_post(self, post: Post, target: str) -> bool:
"""
Download everything associated with one instagram post node, i.e. picture, caption and video.
:param post: Post to download.
:param target: Target name, i.e. profile name, #hashtag, :feed; for filename.
:return: True ... | def download_post(self, post: Post, target: str) -> bool:
"""
Download everything associated with one instagram post node, i.e. picture, caption and video.
:param post: Post to download.
:param target: Target name, i.e. profile name, #hashtag, :feed; for filename.
:return: True ... | [
"Download",
"everything",
"associated",
"with",
"one",
"instagram",
"post",
"node",
"i",
".",
"e",
".",
"picture",
"caption",
"and",
"video",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L428-L487 | [
"def",
"download_post",
"(",
"self",
",",
"post",
":",
"Post",
",",
"target",
":",
"str",
")",
"->",
"bool",
":",
"dirname",
"=",
"_PostPathFormatter",
"(",
"post",
")",
".",
"format",
"(",
"self",
".",
"dirname_pattern",
",",
"target",
"=",
"target",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_stories | Get available stories from followees or all stories of users whose ID are given.
Does not mark stories as seen.
To use this, one needs to be logged in
:param userids: List of user IDs to be processed in terms of downloading their stories, or None. | instaloader/instaloader.py | def get_stories(self, userids: Optional[List[int]] = None) -> Iterator[Story]:
"""Get available stories from followees or all stories of users whose ID are given.
Does not mark stories as seen.
To use this, one needs to be logged in
:param userids: List of user IDs to be processed in te... | def get_stories(self, userids: Optional[List[int]] = None) -> Iterator[Story]:
"""Get available stories from followees or all stories of users whose ID are given.
Does not mark stories as seen.
To use this, one needs to be logged in
:param userids: List of user IDs to be processed in te... | [
"Get",
"available",
"stories",
"from",
"followees",
"or",
"all",
"stories",
"of",
"users",
"whose",
"ID",
"are",
"given",
".",
"Does",
"not",
"mark",
"stories",
"as",
"seen",
".",
"To",
"use",
"this",
"one",
"needs",
"to",
"be",
"logged",
"in"
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L490-L513 | [
"def",
"get_stories",
"(",
"self",
",",
"userids",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"Iterator",
"[",
"Story",
"]",
":",
"if",
"not",
"userids",
":",
"data",
"=",
"self",
".",
"context",
".",
"graphql_query",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_stories | Download available stories from user followees or all stories of users whose ID are given.
Does not mark stories as seen.
To use this, one needs to be logged in
:param userids: List of user IDs or Profiles to be processed in terms of downloading their stories
:param fast_update: If true... | instaloader/instaloader.py | def download_stories(self,
userids: Optional[List[Union[int, Profile]]] = None,
fast_update: bool = False,
filename_target: Optional[str] = ':stories',
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> N... | def download_stories(self,
userids: Optional[List[Union[int, Profile]]] = None,
fast_update: bool = False,
filename_target: Optional[str] = ':stories',
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> N... | [
"Download",
"available",
"stories",
"from",
"user",
"followees",
"or",
"all",
"stories",
"of",
"users",
"whose",
"ID",
"are",
"given",
".",
"Does",
"not",
"mark",
"stories",
"as",
"seen",
".",
"To",
"use",
"this",
"one",
"needs",
"to",
"be",
"logged",
"i... | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L516-L552 | [
"def",
"download_stories",
"(",
"self",
",",
"userids",
":",
"Optional",
"[",
"List",
"[",
"Union",
"[",
"int",
",",
"Profile",
"]",
"]",
"]",
"=",
"None",
",",
"fast_update",
":",
"bool",
"=",
"False",
",",
"filename_target",
":",
"Optional",
"[",
"st... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_storyitem | Download one user story.
:param item: Story item, as in story['items'] for story in :meth:`get_stories`
:param target: Replacement for {target} in dirname_pattern and filename_pattern
:return: True if something was downloaded, False otherwise, i.e. file was already there | instaloader/instaloader.py | def download_storyitem(self, item: StoryItem, target: str) -> bool:
"""Download one user story.
:param item: Story item, as in story['items'] for story in :meth:`get_stories`
:param target: Replacement for {target} in dirname_pattern and filename_pattern
:return: True if something was d... | def download_storyitem(self, item: StoryItem, target: str) -> bool:
"""Download one user story.
:param item: Story item, as in story['items'] for story in :meth:`get_stories`
:param target: Replacement for {target} in dirname_pattern and filename_pattern
:return: True if something was d... | [
"Download",
"one",
"user",
"story",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L554-L580 | [
"def",
"download_storyitem",
"(",
"self",
",",
"item",
":",
"StoryItem",
",",
"target",
":",
"str",
")",
"->",
"bool",
":",
"date_local",
"=",
"item",
".",
"date_local",
"dirname",
"=",
"_PostPathFormatter",
"(",
"item",
")",
".",
"format",
"(",
"self",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_highlights | Get all highlights from a user.
To use this, one needs to be logged in.
.. versionadded:: 4.1
:param user: ID or Profile of the user whose highlights should get fetched. | instaloader/instaloader.py | def get_highlights(self, user: Union[int, Profile]) -> Iterator[Highlight]:
"""Get all highlights from a user.
To use this, one needs to be logged in.
.. versionadded:: 4.1
:param user: ID or Profile of the user whose highlights should get fetched.
"""
userid = user if... | def get_highlights(self, user: Union[int, Profile]) -> Iterator[Highlight]:
"""Get all highlights from a user.
To use this, one needs to be logged in.
.. versionadded:: 4.1
:param user: ID or Profile of the user whose highlights should get fetched.
"""
userid = user if... | [
"Get",
"all",
"highlights",
"from",
"a",
"user",
".",
"To",
"use",
"this",
"one",
"needs",
"to",
"be",
"logged",
"in",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L583-L600 | [
"def",
"get_highlights",
"(",
"self",
",",
"user",
":",
"Union",
"[",
"int",
",",
"Profile",
"]",
")",
"->",
"Iterator",
"[",
"Highlight",
"]",
":",
"userid",
"=",
"user",
"if",
"isinstance",
"(",
"user",
",",
"int",
")",
"else",
"user",
".",
"userid... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_highlights | Download available highlights from a user whose ID is given.
To use this, one needs to be logged in.
.. versionadded:: 4.1
:param user: ID or Profile of the user whose highlights should get downloaded.
:param fast_update: If true, abort when first already-downloaded picture is encounte... | instaloader/instaloader.py | def download_highlights(self,
user: Union[int, Profile],
fast_update: bool = False,
filename_target: Optional[str] = None,
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> None:
"""
... | def download_highlights(self,
user: Union[int, Profile],
fast_update: bool = False,
filename_target: Optional[str] = None,
storyitem_filter: Optional[Callable[[StoryItem], bool]] = None) -> None:
"""
... | [
"Download",
"available",
"highlights",
"from",
"a",
"user",
"whose",
"ID",
"is",
"given",
".",
"To",
"use",
"this",
"one",
"needs",
"to",
"be",
"logged",
"in",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L603-L636 | [
"def",
"download_highlights",
"(",
"self",
",",
"user",
":",
"Union",
"[",
"int",
",",
"Profile",
"]",
",",
"fast_update",
":",
"bool",
"=",
"False",
",",
"filename_target",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"storyitem_filter",
":",
"Op... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_feed_posts | Get Posts of the user's feed.
:return: Iterator over Posts of the user's feed. | instaloader/instaloader.py | def get_feed_posts(self) -> Iterator[Post]:
"""Get Posts of the user's feed.
:return: Iterator over Posts of the user's feed.
"""
data = self.context.graphql_query("d6f4427fbe92d846298cf93df0b937d3", {})["data"]
while True:
feed = data["user"]["edge_web_feed_timeli... | def get_feed_posts(self) -> Iterator[Post]:
"""Get Posts of the user's feed.
:return: Iterator over Posts of the user's feed.
"""
data = self.context.graphql_query("d6f4427fbe92d846298cf93df0b937d3", {})["data"]
while True:
feed = data["user"]["edge_web_feed_timeli... | [
"Get",
"Posts",
"of",
"the",
"user",
"s",
"feed",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L639-L658 | [
"def",
"get_feed_posts",
"(",
"self",
")",
"->",
"Iterator",
"[",
"Post",
"]",
":",
"data",
"=",
"self",
".",
"context",
".",
"graphql_query",
"(",
"\"d6f4427fbe92d846298cf93df0b937d3\"",
",",
"{",
"}",
")",
"[",
"\"data\"",
"]",
"while",
"True",
":",
"fee... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_feed_posts | Download pictures from the user's feed.
Example to download up to the 20 pics the user last liked::
loader = Instaloader()
loader.load_session_from_file('USER')
loader.download_feed_posts(max_count=20, fast_update=True,
post_filter=lam... | instaloader/instaloader.py | def download_feed_posts(self, max_count: int = None, fast_update: bool = False,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""
Download pictures from the user's feed.
Example to download up to the 20 pics the user last liked::
loader ... | def download_feed_posts(self, max_count: int = None, fast_update: bool = False,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""
Download pictures from the user's feed.
Example to download up to the 20 pics the user last liked::
loader ... | [
"Download",
"pictures",
"from",
"the",
"user",
"s",
"feed",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L661-L691 | [
"def",
"download_feed_posts",
"(",
"self",
",",
"max_count",
":",
"int",
"=",
"None",
",",
"fast_update",
":",
"bool",
"=",
"False",
",",
"post_filter",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"Post",
"]",
",",
"bool",
"]",
"]",
"=",
"None",
")",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_saved_posts | Download user's saved pictures.
:param max_count: Maximum count of pictures to download
:param fast_update: If true, abort when first already-downloaded picture is encountered
:param post_filter: function(post), which returns True if given picture should be downloaded | instaloader/instaloader.py | def download_saved_posts(self, max_count: int = None, fast_update: bool = False,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""Download user's saved pictures.
:param max_count: Maximum count of pictures to download
:param fast_update: If true, ab... | def download_saved_posts(self, max_count: int = None, fast_update: bool = False,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""Download user's saved pictures.
:param max_count: Maximum count of pictures to download
:param fast_update: If true, ab... | [
"Download",
"user",
"s",
"saved",
"pictures",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L694-L715 | [
"def",
"download_saved_posts",
"(",
"self",
",",
"max_count",
":",
"int",
"=",
"None",
",",
"fast_update",
":",
"bool",
"=",
"False",
",",
"post_filter",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"Post",
"]",
",",
"bool",
"]",
"]",
"=",
"None",
")",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_location_posts | Get Posts which are listed by Instagram for a given Location.
:return: Iterator over Posts of a location's posts
.. versionadded:: 4.2 | instaloader/instaloader.py | def get_location_posts(self, location: str) -> Iterator[Post]:
"""Get Posts which are listed by Instagram for a given Location.
:return: Iterator over Posts of a location's posts
.. versionadded:: 4.2
"""
has_next_page = True
end_cursor = None
while has_next_pa... | def get_location_posts(self, location: str) -> Iterator[Post]:
"""Get Posts which are listed by Instagram for a given Location.
:return: Iterator over Posts of a location's posts
.. versionadded:: 4.2
"""
has_next_page = True
end_cursor = None
while has_next_pa... | [
"Get",
"Posts",
"which",
"are",
"listed",
"by",
"Instagram",
"for",
"a",
"given",
"Location",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L717-L735 | [
"def",
"get_location_posts",
"(",
"self",
",",
"location",
":",
"str",
")",
"->",
"Iterator",
"[",
"Post",
"]",
":",
"has_next_page",
"=",
"True",
"end_cursor",
"=",
"None",
"while",
"has_next_page",
":",
"if",
"end_cursor",
":",
"params",
"=",
"{",
"'__a'... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_location | Download pictures of one location.
To download the last 30 pictures with location 362629379, do::
loader = Instaloader()
loader.download_location(362629379, max_count=30)
:param location: Location to download, as Instagram numerical ID
:param max_count: Maximum count o... | instaloader/instaloader.py | def download_location(self, location: str,
max_count: Optional[int] = None,
post_filter: Optional[Callable[[Post], bool]] = None,
fast_update: bool = False) -> None:
"""Download pictures of one location.
To download the last ... | def download_location(self, location: str,
max_count: Optional[int] = None,
post_filter: Optional[Callable[[Post], bool]] = None,
fast_update: bool = False) -> None:
"""Download pictures of one location.
To download the last ... | [
"Download",
"pictures",
"of",
"one",
"location",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L737-L768 | [
"def",
"download_location",
"(",
"self",
",",
"location",
":",
"str",
",",
"max_count",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"post_filter",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"Post",
"]",
",",
"bool",
"]",
"]",
"=",
"None",
",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_explore_posts | Get Posts which are worthy of exploring suggested by Instagram.
:return: Iterator over Posts of the user's suggested posts. | instaloader/instaloader.py | def get_explore_posts(self) -> Iterator[Post]:
"""Get Posts which are worthy of exploring suggested by Instagram.
:return: Iterator over Posts of the user's suggested posts.
"""
data = self.context.get_json('explore/', {})
yield from (Post(self.context, node)
... | def get_explore_posts(self) -> Iterator[Post]:
"""Get Posts which are worthy of exploring suggested by Instagram.
:return: Iterator over Posts of the user's suggested posts.
"""
data = self.context.get_json('explore/', {})
yield from (Post(self.context, node)
... | [
"Get",
"Posts",
"which",
"are",
"worthy",
"of",
"exploring",
"suggested",
"by",
"Instagram",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L771-L781 | [
"def",
"get_explore_posts",
"(",
"self",
")",
"->",
"Iterator",
"[",
"Post",
"]",
":",
"data",
"=",
"self",
".",
"context",
".",
"get_json",
"(",
"'explore/'",
",",
"{",
"}",
")",
"yield",
"from",
"(",
"Post",
"(",
"self",
".",
"context",
",",
"node"... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.get_hashtag_posts | Get Posts associated with a #hashtag. | instaloader/instaloader.py | def get_hashtag_posts(self, hashtag: str) -> Iterator[Post]:
"""Get Posts associated with a #hashtag."""
has_next_page = True
end_cursor = None
while has_next_page:
if end_cursor:
params = {'__a': 1, 'max_id': end_cursor}
else:
para... | def get_hashtag_posts(self, hashtag: str) -> Iterator[Post]:
"""Get Posts associated with a #hashtag."""
has_next_page = True
end_cursor = None
while has_next_page:
if end_cursor:
params = {'__a': 1, 'max_id': end_cursor}
else:
para... | [
"Get",
"Posts",
"associated",
"with",
"a",
"#hashtag",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L783-L796 | [
"def",
"get_hashtag_posts",
"(",
"self",
",",
"hashtag",
":",
"str",
")",
"->",
"Iterator",
"[",
"Post",
"]",
":",
"has_next_page",
"=",
"True",
"end_cursor",
"=",
"None",
"while",
"has_next_page",
":",
"if",
"end_cursor",
":",
"params",
"=",
"{",
"'__a'",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_hashtag | Download pictures of one hashtag.
To download the last 30 pictures with hashtag #cat, do::
loader = Instaloader()
loader.download_hashtag('cat', max_count=30)
:param hashtag: Hashtag to download, without leading '#'
:param max_count: Maximum count of pictures to downlo... | instaloader/instaloader.py | def download_hashtag(self, hashtag: str,
max_count: Optional[int] = None,
post_filter: Optional[Callable[[Post], bool]] = None,
fast_update: bool = False) -> None:
"""Download pictures of one hashtag.
To download the last 30 pic... | def download_hashtag(self, hashtag: str,
max_count: Optional[int] = None,
post_filter: Optional[Callable[[Post], bool]] = None,
fast_update: bool = False) -> None:
"""Download pictures of one hashtag.
To download the last 30 pic... | [
"Download",
"pictures",
"of",
"one",
"hashtag",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L798-L828 | [
"def",
"download_hashtag",
"(",
"self",
",",
"hashtag",
":",
"str",
",",
"max_count",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"post_filter",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"Post",
"]",
",",
"bool",
"]",
"]",
"=",
"None",
",",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_tagged | Download all posts where a profile is tagged.
.. versionadded:: 4.1 | instaloader/instaloader.py | def download_tagged(self, profile: Profile, fast_update: bool = False,
target: Optional[str] = None,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""Download all posts where a profile is tagged.
.. versionadded:: 4.1"""
if target... | def download_tagged(self, profile: Profile, fast_update: bool = False,
target: Optional[str] = None,
post_filter: Optional[Callable[[Post], bool]] = None) -> None:
"""Download all posts where a profile is tagged.
.. versionadded:: 4.1"""
if target... | [
"Download",
"all",
"posts",
"where",
"a",
"profile",
"is",
"tagged",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L830-L848 | [
"def",
"download_tagged",
"(",
"self",
",",
"profile",
":",
"Profile",
",",
"fast_update",
":",
"bool",
"=",
"False",
",",
"target",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"post_filter",
":",
"Optional",
"[",
"Callable",
"[",
"[",
"Post",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.save_profile_id | Store ID of profile locally.
.. versionadded:: 4.0.6 | instaloader/instaloader.py | def save_profile_id(self, profile: Profile):
"""
Store ID of profile locally.
.. versionadded:: 4.0.6
"""
os.makedirs(self.dirname_pattern.format(profile=profile.username,
target=profile.username), exist_ok=True)
with open(... | def save_profile_id(self, profile: Profile):
"""
Store ID of profile locally.
.. versionadded:: 4.0.6
"""
os.makedirs(self.dirname_pattern.format(profile=profile.username,
target=profile.username), exist_ok=True)
with open(... | [
"Store",
"ID",
"of",
"profile",
"locally",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L858-L868 | [
"def",
"save_profile_id",
"(",
"self",
",",
"profile",
":",
"Profile",
")",
":",
"os",
".",
"makedirs",
"(",
"self",
".",
"dirname_pattern",
".",
"format",
"(",
"profile",
"=",
"profile",
".",
"username",
",",
"target",
"=",
"profile",
".",
"username",
"... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.check_profile_id | Consult locally stored ID of profile with given name, check whether ID matches and whether name
has changed and return current name of the profile, and store ID of profile.
:param profile_name: Profile name
:return: Instance of current profile | instaloader/instaloader.py | def check_profile_id(self, profile_name: str) -> Profile:
"""
Consult locally stored ID of profile with given name, check whether ID matches and whether name
has changed and return current name of the profile, and store ID of profile.
:param profile_name: Profile name
:return: I... | def check_profile_id(self, profile_name: str) -> Profile:
"""
Consult locally stored ID of profile with given name, check whether ID matches and whether name
has changed and return current name of the profile, and store ID of profile.
:param profile_name: Profile name
:return: I... | [
"Consult",
"locally",
"stored",
"ID",
"of",
"profile",
"with",
"given",
"name",
"check",
"whether",
"ID",
"matches",
"and",
"whether",
"name",
"has",
"changed",
"and",
"return",
"current",
"name",
"of",
"the",
"profile",
"and",
"store",
"ID",
"of",
"profile"... | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L870-L913 | [
"def",
"check_profile_id",
"(",
"self",
",",
"profile_name",
":",
"str",
")",
"->",
"Profile",
":",
"profile",
"=",
"None",
"with",
"suppress",
"(",
"ProfileNotExistsException",
")",
":",
"profile",
"=",
"Profile",
".",
"from_username",
"(",
"self",
".",
"co... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_profiles | High-level method to download set of profiles.
:param profiles: Set of profiles to download.
:param profile_pic: not :option:`--no-profile-pic`.
:param posts: not :option:`--no-posts`.
:param tagged: :option:`--tagged`.
:param highlights: :option:`--highlights`.
:param s... | instaloader/instaloader.py | def download_profiles(self, profiles: Set[Profile],
profile_pic: bool = True, posts: bool = True,
tagged: bool = False, highlights: bool = False, stories: bool = False,
fast_update: bool = False,
post_filter: Optiona... | def download_profiles(self, profiles: Set[Profile],
profile_pic: bool = True, posts: bool = True,
tagged: bool = False, highlights: bool = False, stories: bool = False,
fast_update: bool = False,
post_filter: Optiona... | [
"High",
"-",
"level",
"method",
"to",
"download",
"set",
"of",
"profiles",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L915-L1011 | [
"def",
"download_profiles",
"(",
"self",
",",
"profiles",
":",
"Set",
"[",
"Profile",
"]",
",",
"profile_pic",
":",
"bool",
"=",
"True",
",",
"posts",
":",
"bool",
"=",
"True",
",",
"tagged",
":",
"bool",
"=",
"False",
",",
"highlights",
":",
"bool",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.download_profile | Download one profile
.. deprecated:: 4.1
Use :meth:`Instaloader.download_profiles`. | instaloader/instaloader.py | def download_profile(self, profile_name: Union[str, Profile],
profile_pic: bool = True, profile_pic_only: bool = False,
fast_update: bool = False,
download_stories: bool = False, download_stories_only: bool = False,
down... | def download_profile(self, profile_name: Union[str, Profile],
profile_pic: bool = True, profile_pic_only: bool = False,
fast_update: bool = False,
download_stories: bool = False, download_stories_only: bool = False,
down... | [
"Download",
"one",
"profile"
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L1013-L1095 | [
"def",
"download_profile",
"(",
"self",
",",
"profile_name",
":",
"Union",
"[",
"str",
",",
"Profile",
"]",
",",
"profile_pic",
":",
"bool",
"=",
"True",
",",
"profile_pic_only",
":",
"bool",
"=",
"False",
",",
"fast_update",
":",
"bool",
"=",
"False",
"... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.check_if_committed | Checks to see if the current post has been committed.
A post is considered committed if its json metadata file exists and is not malformed.
.. versionadded:: 4.2 | instaloader/instaloader.py | def check_if_committed(self, filename: str) -> bool:
"""Checks to see if the current post has been committed.
A post is considered committed if its json metadata file exists and is not malformed.
.. versionadded:: 4.2
"""
if os.path.isfile(filename + '.json.xz'):
fi... | def check_if_committed(self, filename: str) -> bool:
"""Checks to see if the current post has been committed.
A post is considered committed if its json metadata file exists and is not malformed.
.. versionadded:: 4.2
"""
if os.path.isfile(filename + '.json.xz'):
fi... | [
"Checks",
"to",
"see",
"if",
"the",
"current",
"post",
"has",
"been",
"committed",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L1097-L1114 | [
"def",
"check_if_committed",
"(",
"self",
",",
"filename",
":",
"str",
")",
"->",
"bool",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
"+",
"'.json.xz'",
")",
":",
"filename",
"+=",
"'.json.xz'",
"elif",
"os",
".",
"path",
".",
"isfile... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | Instaloader.interactive_login | Logs in and internally stores session, asking user for password interactively.
:raises LoginRequiredException: when in quiet mode.
:raises InvalidArgumentException: If the provided username does not exist.
:raises ConnectionException: If connection to Instagram failed. | instaloader/instaloader.py | def interactive_login(self, username: str) -> None:
"""Logs in and internally stores session, asking user for password interactively.
:raises LoginRequiredException: when in quiet mode.
:raises InvalidArgumentException: If the provided username does not exist.
:raises ConnectionExceptio... | def interactive_login(self, username: str) -> None:
"""Logs in and internally stores session, asking user for password interactively.
:raises LoginRequiredException: when in quiet mode.
:raises InvalidArgumentException: If the provided username does not exist.
:raises ConnectionExceptio... | [
"Logs",
"in",
"and",
"internally",
"stores",
"session",
"asking",
"user",
"for",
"password",
"interactively",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/instaloader.py#L1116-L1140 | [
"def",
"interactive_login",
"(",
"self",
",",
"username",
":",
"str",
")",
"->",
"None",
":",
"if",
"self",
".",
"context",
".",
"quiet",
":",
"raise",
"LoginRequiredException",
"(",
"\"Quiet mode requires given password or valid session file.\"",
")",
"try",
":",
... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | filterstr_to_filterfunc | Takes an --post-filter=... or --storyitem-filter=... filter
specification and makes a filter_func Callable out of it. | instaloader/__main__.py | def filterstr_to_filterfunc(filter_str: str, item_type: type):
"""Takes an --post-filter=... or --storyitem-filter=... filter
specification and makes a filter_func Callable out of it."""
# The filter_str is parsed, then all names occurring in its AST are replaced by loads to post.<name>. A
# function ... | def filterstr_to_filterfunc(filter_str: str, item_type: type):
"""Takes an --post-filter=... or --storyitem-filter=... filter
specification and makes a filter_func Callable out of it."""
# The filter_str is parsed, then all names occurring in its AST are replaced by loads to post.<name>. A
# function ... | [
"Takes",
"an",
"--",
"post",
"-",
"filter",
"=",
"...",
"or",
"--",
"storyitem",
"-",
"filter",
"=",
"...",
"filter",
"specification",
"and",
"makes",
"a",
"filter_func",
"Callable",
"out",
"of",
"it",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/__main__.py#L28-L57 | [
"def",
"filterstr_to_filterfunc",
"(",
"filter_str",
":",
"str",
",",
"item_type",
":",
"type",
")",
":",
"# The filter_str is parsed, then all names occurring in its AST are replaced by loads to post.<name>. A",
"# function Post->bool is returned which evaluates the filter with the post a... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | _main | Download set of profiles, hashtags etc. and handle logging in and session files if desired. | instaloader/__main__.py | def _main(instaloader: Instaloader, targetlist: List[str],
username: Optional[str] = None, password: Optional[str] = None,
sessionfile: Optional[str] = None,
download_profile_pic: bool = True, download_posts=True,
download_stories: bool = False, download_highlights: bool = False,... | def _main(instaloader: Instaloader, targetlist: List[str],
username: Optional[str] = None, password: Optional[str] = None,
sessionfile: Optional[str] = None,
download_profile_pic: bool = True, download_posts=True,
download_stories: bool = False, download_highlights: bool = False,... | [
"Download",
"set",
"of",
"profiles",
"hashtags",
"etc",
".",
"and",
"handle",
"logging",
"in",
"and",
"session",
"files",
"if",
"desired",
"."
] | instaloader/instaloader | python | https://github.com/instaloader/instaloader/blob/87d877e650cd8020b04b8b51be120599a441fd5b/instaloader/__main__.py#L60-L206 | [
"def",
"_main",
"(",
"instaloader",
":",
"Instaloader",
",",
"targetlist",
":",
"List",
"[",
"str",
"]",
",",
"username",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"password",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"sessionfile",... | 87d877e650cd8020b04b8b51be120599a441fd5b |
train | exp_comp_ | beta*(1 - np.exp(-alpha*(t-beta))) | lifelines/generate_datasets.py | def exp_comp_(t, alpha=1, beta=1):
"""beta*(1 - np.exp(-alpha*(t-beta)))"""
return beta * (1 - np.exp(-alpha * np.maximum(0, t - 10 * beta))) | def exp_comp_(t, alpha=1, beta=1):
"""beta*(1 - np.exp(-alpha*(t-beta)))"""
return beta * (1 - np.exp(-alpha * np.maximum(0, t - 10 * beta))) | [
"beta",
"*",
"(",
"1",
"-",
"np",
".",
"exp",
"(",
"-",
"alpha",
"*",
"(",
"t",
"-",
"beta",
")))"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L98-L100 | [
"def",
"exp_comp_",
"(",
"t",
",",
"alpha",
"=",
"1",
",",
"beta",
"=",
"1",
")",
":",
"return",
"beta",
"*",
"(",
"1",
"-",
"np",
".",
"exp",
"(",
"-",
"alpha",
"*",
"np",
".",
"maximum",
"(",
"0",
",",
"t",
"-",
"10",
"*",
"beta",
")",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | log_ | beta*np.log(alpha*(t-beta)+1) | lifelines/generate_datasets.py | def log_(t, alpha=1, beta=1):
"""beta*np.log(alpha*(t-beta)+1)"""
return beta * np.log(alpha * np.maximum(0, t - 10 * beta) + 1) | def log_(t, alpha=1, beta=1):
"""beta*np.log(alpha*(t-beta)+1)"""
return beta * np.log(alpha * np.maximum(0, t - 10 * beta) + 1) | [
"beta",
"*",
"np",
".",
"log",
"(",
"alpha",
"*",
"(",
"t",
"-",
"beta",
")",
"+",
"1",
")"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L104-L106 | [
"def",
"log_",
"(",
"t",
",",
"alpha",
"=",
"1",
",",
"beta",
"=",
"1",
")",
":",
"return",
"beta",
"*",
"np",
".",
"log",
"(",
"alpha",
"*",
"np",
".",
"maximum",
"(",
"0",
",",
"t",
"-",
"10",
"*",
"beta",
")",
"+",
"1",
")"
] | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | right_censor_lifetimes | Right censor the deaths, uniformly
lifetimes: (n,) array of positive random variables
max_: the max time a censorship can occur
min_: the min time a censorship can occur
Returns
The actual observations including uniform right censoring, and
D_i (observed death or did not)
I think... | lifelines/generate_datasets.py | def right_censor_lifetimes(lifetimes, max_, min_=0):
"""
Right censor the deaths, uniformly
lifetimes: (n,) array of positive random variables
max_: the max time a censorship can occur
min_: the min time a censorship can occur
Returns
The actual observations including uniform right ... | def right_censor_lifetimes(lifetimes, max_, min_=0):
"""
Right censor the deaths, uniformly
lifetimes: (n,) array of positive random variables
max_: the max time a censorship can occur
min_: the min time a censorship can occur
Returns
The actual observations including uniform right ... | [
"Right",
"censor",
"the",
"deaths",
"uniformly",
"lifetimes",
":",
"(",
"n",
")",
"array",
"of",
"positive",
"random",
"variables",
"max_",
":",
"the",
"max",
"time",
"a",
"censorship",
"can",
"occur",
"min_",
":",
"the",
"min",
"time",
"a",
"censorship",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L130-L146 | [
"def",
"right_censor_lifetimes",
"(",
"lifetimes",
",",
"max_",
",",
"min_",
"=",
"0",
")",
":",
"n",
"=",
"lifetimes",
".",
"shape",
"[",
"0",
"]",
"u",
"=",
"min_",
"+",
"(",
"max_",
"-",
"min_",
")",
"*",
"random",
".",
"rand",
"(",
"n",
")",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | generate_covariates | n: the number of instances, integer
d: the dimension of the covarites, integer
binary: a float between 0 and d the represents the binary covariates
p: in binary, the probability of 1
returns (n, d+1) | lifelines/generate_datasets.py | def generate_covariates(n, d, n_binary=0, p=0.5):
"""
n: the number of instances, integer
d: the dimension of the covarites, integer
binary: a float between 0 and d the represents the binary covariates
p: in binary, the probability of 1
returns (n, d+1)
"""
# pylint: disable=chained-com... | def generate_covariates(n, d, n_binary=0, p=0.5):
"""
n: the number of instances, integer
d: the dimension of the covarites, integer
binary: a float between 0 and d the represents the binary covariates
p: in binary, the probability of 1
returns (n, d+1)
"""
# pylint: disable=chained-com... | [
"n",
":",
"the",
"number",
"of",
"instances",
"integer",
"d",
":",
"the",
"dimension",
"of",
"the",
"covarites",
"integer",
"binary",
":",
"a",
"float",
"between",
"0",
"and",
"d",
"the",
"represents",
"the",
"binary",
"covariates",
"p",
":",
"in",
"bina... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L149-L164 | [
"def",
"generate_covariates",
"(",
"n",
",",
"d",
",",
"n_binary",
"=",
"0",
",",
"p",
"=",
"0.5",
")",
":",
"# pylint: disable=chained-comparison",
"assert",
"n_binary",
">=",
"0",
"and",
"n_binary",
"<=",
"d",
",",
"\"binary must be between 0 and d\"",
"covari... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | constant_coefficients | Proportional hazards model.
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covariate is ind of survival), or
a list of covariates to make indepent.
returns a matrix (t,d+1) of coeff... | lifelines/generate_datasets.py | def constant_coefficients(d, timelines, constant=True, independent=0):
"""
Proportional hazards model.
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covariate is ind of survival), or
... | def constant_coefficients(d, timelines, constant=True, independent=0):
"""
Proportional hazards model.
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covariate is ind of survival), or
... | [
"Proportional",
"hazards",
"model",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L167-L179 | [
"def",
"constant_coefficients",
"(",
"d",
",",
"timelines",
",",
"constant",
"=",
"True",
",",
"independent",
"=",
"0",
")",
":",
"return",
"time_varying_coefficients",
"(",
"d",
",",
"timelines",
",",
"constant",
",",
"independent",
"=",
"independent",
",",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | time_varying_coefficients | Time vary coefficients
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covariate is ind of survival), or
a list of covariates to make indepent.
randgen: how scalar coefficients (betas... | lifelines/generate_datasets.py | def time_varying_coefficients(d, timelines, constant=False, independent=0, randgen=random.exponential):
"""
Time vary coefficients
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covari... | def time_varying_coefficients(d, timelines, constant=False, independent=0, randgen=random.exponential):
"""
Time vary coefficients
d: the dimension of the dataset
timelines: the observational times
constant: True for constant coefficients
independent: the number of coffients to set to 0 (covari... | [
"Time",
"vary",
"coefficients"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L182-L216 | [
"def",
"time_varying_coefficients",
"(",
"d",
",",
"timelines",
",",
"constant",
"=",
"False",
",",
"independent",
"=",
"0",
",",
"randgen",
"=",
"random",
".",
"exponential",
")",
":",
"t",
"=",
"timelines",
".",
"shape",
"[",
"0",
"]",
"try",
":",
"a... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | generate_hazard_rates | n: the number of instances
d: the number of covariates
lifelines: the observational times
constant: make the coeffients constant (not time dependent)
n_binary: the number of binary covariates
model: from ["aalen", "cox"]
Returns:s
hazard rates: (t,n) dataframe,
coefficient... | lifelines/generate_datasets.py | def generate_hazard_rates(n, d, timelines, constant=False, independent=0, n_binary=0, model="aalen"):
"""
n: the number of instances
d: the number of covariates
lifelines: the observational times
constant: make the coeffients constant (not time dependent)
n_binary: the number of binary... | def generate_hazard_rates(n, d, timelines, constant=False, independent=0, n_binary=0, model="aalen"):
"""
n: the number of instances
d: the number of covariates
lifelines: the observational times
constant: make the coeffients constant (not time dependent)
n_binary: the number of binary... | [
"n",
":",
"the",
"number",
"of",
"instances",
"d",
":",
"the",
"number",
"of",
"covariates",
"lifelines",
":",
"the",
"observational",
"times",
"constant",
":",
"make",
"the",
"coeffients",
"constant",
"(",
"not",
"time",
"dependent",
")",
"n_binary",
":",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L219-L246 | [
"def",
"generate_hazard_rates",
"(",
"n",
",",
"d",
",",
"timelines",
",",
"constant",
"=",
"False",
",",
"independent",
"=",
"0",
",",
"n_binary",
"=",
"0",
",",
"model",
"=",
"\"aalen\"",
")",
":",
"covariates",
"=",
"generate_covariates",
"(",
"n",
",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | generate_random_lifetimes | Based on the hazard rates, compute random variables from the survival function
hazard_rates: (n,t) array of hazard rates
timelines: (t,) the observation times
size: the number to return, per hardard rate
censor: If True, adds uniform censoring between timelines.max() and 0
If a po... | lifelines/generate_datasets.py | def generate_random_lifetimes(hazard_rates, timelines, size=1, censor=None):
"""
Based on the hazard rates, compute random variables from the survival function
hazard_rates: (n,t) array of hazard rates
timelines: (t,) the observation times
size: the number to return, per hardard rate
cen... | def generate_random_lifetimes(hazard_rates, timelines, size=1, censor=None):
"""
Based on the hazard rates, compute random variables from the survival function
hazard_rates: (n,t) array of hazard rates
timelines: (t,) the observation times
size: the number to return, per hardard rate
cen... | [
"Based",
"on",
"the",
"hazard",
"rates",
"compute",
"random",
"variables",
"from",
"the",
"survival",
"function",
"hazard_rates",
":",
"(",
"n",
"t",
")",
"array",
"of",
"hazard",
"rates",
"timelines",
":",
"(",
"t",
")",
"the",
"observation",
"times",
"si... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L249-L289 | [
"def",
"generate_random_lifetimes",
"(",
"hazard_rates",
",",
"timelines",
",",
"size",
"=",
"1",
",",
"censor",
"=",
"None",
")",
":",
"n",
"=",
"hazard_rates",
".",
"shape",
"[",
"1",
"]",
"survival_times",
"=",
"np",
".",
"empty",
"(",
"(",
"n",
","... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | construct_survival_curves | Given hazard rates, reconstruct the survival curves
Parameters
----------
hazard_rates: (n,t) array
timelines: (t,) the observational times
Returns
-------
t: survial curves, (n,t) array | lifelines/generate_datasets.py | def construct_survival_curves(hazard_rates, timelines):
"""
Given hazard rates, reconstruct the survival curves
Parameters
----------
hazard_rates: (n,t) array
timelines: (t,) the observational times
Returns
-------
t: survial curves, (n,t) array
"""
cumulative_hazards = cu... | def construct_survival_curves(hazard_rates, timelines):
"""
Given hazard rates, reconstruct the survival curves
Parameters
----------
hazard_rates: (n,t) array
timelines: (t,) the observational times
Returns
-------
t: survial curves, (n,t) array
"""
cumulative_hazards = cu... | [
"Given",
"hazard",
"rates",
"reconstruct",
"the",
"survival",
"curves"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/generate_datasets.py#L314-L328 | [
"def",
"construct_survival_curves",
"(",
"hazard_rates",
",",
"timelines",
")",
":",
"cumulative_hazards",
"=",
"cumulative_integral",
"(",
"hazard_rates",
".",
"values",
",",
"timelines",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"np",
".",
"exp",
"(",
"-",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.fit | Parameters
----------
Fit the Aalen Additive model to a dataset.
Parameters
----------
df: DataFrame
a Pandas DataFrame with necessary columns `duration_col` and
`event_col` (see below), covariates columns, and special columns (weights).
`dura... | lifelines/fitters/aalen_additive_fitter.py | def fit(self, df, duration_col, event_col=None, weights_col=None, show_progress=False):
"""
Parameters
----------
Fit the Aalen Additive model to a dataset.
Parameters
----------
df: DataFrame
a Pandas DataFrame with necessary columns `duration_col` a... | def fit(self, df, duration_col, event_col=None, weights_col=None, show_progress=False):
"""
Parameters
----------
Fit the Aalen Additive model to a dataset.
Parameters
----------
df: DataFrame
a Pandas DataFrame with necessary columns `duration_col` a... | [
"Parameters",
"----------",
"Fit",
"the",
"Aalen",
"Additive",
"model",
"to",
"a",
"dataset",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L97-L191 | [
"def",
"fit",
"(",
"self",
",",
"df",
",",
"duration_col",
",",
"event_col",
"=",
"None",
",",
"weights_col",
"=",
"None",
",",
"show_progress",
"=",
"False",
")",
":",
"self",
".",
"_time_fit_was_called",
"=",
"datetime",
".",
"utcnow",
"(",
")",
".",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.predict_cumulative_hazard | Returns the hazard rates for the individuals
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order as the training data. | lifelines/fitters/aalen_additive_fitter.py | def predict_cumulative_hazard(self, X):
"""
Returns the hazard rates for the individuals
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order ... | def predict_cumulative_hazard(self, X):
"""
Returns the hazard rates for the individuals
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order ... | [
"Returns",
"the",
"hazard",
"rates",
"for",
"the",
"individuals"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L309-L337 | [
"def",
"predict_cumulative_hazard",
"(",
"self",
",",
"X",
")",
":",
"n",
",",
"_",
"=",
"X",
".",
"shape",
"cols",
"=",
"_get_index",
"(",
"X",
")",
"if",
"isinstance",
"(",
"X",
",",
"pd",
".",
"DataFrame",
")",
":",
"order",
"=",
"self",
".",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.predict_expectation | Compute the expected lifetime, E[T], using covariates X.
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame
If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order as the training data.
Return... | lifelines/fitters/aalen_additive_fitter.py | def predict_expectation(self, X):
"""
Compute the expected lifetime, E[T], using covariates X.
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame
If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
... | def predict_expectation(self, X):
"""
Compute the expected lifetime, E[T], using covariates X.
Parameters
----------
X: a (n,d) covariate numpy array or DataFrame
If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
... | [
"Compute",
"the",
"expected",
"lifetime",
"E",
"[",
"T",
"]",
"using",
"covariates",
"X",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L390-L405 | [
"def",
"predict_expectation",
"(",
"self",
",",
"X",
")",
":",
"index",
"=",
"_get_index",
"(",
"X",
")",
"t",
"=",
"self",
".",
"_index",
"return",
"pd",
".",
"DataFrame",
"(",
"trapz",
"(",
"self",
".",
"predict_survival_function",
"(",
"X",
")",
"["... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.plot | A wrapper around plotting. Matplotlib plot arguments can be passed in, plus:
Parameters
-----------
columns: string or list-like, optional
If not empty, plot a subset of columns from the ``cumulative_hazards_``. Default all.
loc:
iloc: slice, optional
specif... | lifelines/fitters/aalen_additive_fitter.py | def plot(self, columns=None, loc=None, iloc=None, **kwargs):
""""
A wrapper around plotting. Matplotlib plot arguments can be passed in, plus:
Parameters
-----------
columns: string or list-like, optional
If not empty, plot a subset of columns from the ``cumulative_haz... | def plot(self, columns=None, loc=None, iloc=None, **kwargs):
""""
A wrapper around plotting. Matplotlib plot arguments can be passed in, plus:
Parameters
-----------
columns: string or list-like, optional
If not empty, plot a subset of columns from the ``cumulative_haz... | [
"A",
"wrapper",
"around",
"plotting",
".",
"Matplotlib",
"plot",
"arguments",
"can",
"be",
"passed",
"in",
"plus",
":"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L417-L471 | [
"def",
"plot",
"(",
"self",
",",
"columns",
"=",
"None",
",",
"loc",
"=",
"None",
",",
"iloc",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"matplotlib",
"import",
"pyplot",
"as",
"plt",
"assert",
"loc",
"is",
"None",
"or",
"iloc",
"is",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.smoothed_hazards_ | Using the epanechnikov kernel to smooth the hazard function, with sigma/bandwidth | lifelines/fitters/aalen_additive_fitter.py | def smoothed_hazards_(self, bandwidth=1):
"""
Using the epanechnikov kernel to smooth the hazard function, with sigma/bandwidth
"""
timeline = self._index.values
return pd.DataFrame(
np.dot(epanechnikov_kernel(timeline[:, None], timeline, bandwidth), self.hazards_.va... | def smoothed_hazards_(self, bandwidth=1):
"""
Using the epanechnikov kernel to smooth the hazard function, with sigma/bandwidth
"""
timeline = self._index.values
return pd.DataFrame(
np.dot(epanechnikov_kernel(timeline[:, None], timeline, bandwidth), self.hazards_.va... | [
"Using",
"the",
"epanechnikov",
"kernel",
"to",
"smooth",
"the",
"hazard",
"function",
"with",
"sigma",
"/",
"bandwidth"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L473-L483 | [
"def",
"smoothed_hazards_",
"(",
"self",
",",
"bandwidth",
"=",
"1",
")",
":",
"timeline",
"=",
"self",
".",
"_index",
".",
"values",
"return",
"pd",
".",
"DataFrame",
"(",
"np",
".",
"dot",
"(",
"epanechnikov_kernel",
"(",
"timeline",
"[",
":",
",",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.score_ | The concordance score (also known as the c-index) of the fit. The c-index is a generalization of the ROC AUC
to survival data, including censorships.
For this purpose, the ``score_`` is a measure of the predictive accuracy of the fitted model
onto the training dataset. It's analogous to the R^... | lifelines/fitters/aalen_additive_fitter.py | def score_(self):
"""
The concordance score (also known as the c-index) of the fit. The c-index is a generalization of the ROC AUC
to survival data, including censorships.
For this purpose, the ``score_`` is a measure of the predictive accuracy of the fitted model
onto the trai... | def score_(self):
"""
The concordance score (also known as the c-index) of the fit. The c-index is a generalization of the ROC AUC
to survival data, including censorships.
For this purpose, the ``score_`` is a measure of the predictive accuracy of the fitted model
onto the trai... | [
"The",
"concordance",
"score",
"(",
"also",
"known",
"as",
"the",
"c",
"-",
"index",
")",
"of",
"the",
"fit",
".",
"The",
"c",
"-",
"index",
"is",
"a",
"generalization",
"of",
"the",
"ROC",
"AUC",
"to",
"survival",
"data",
"including",
"censorships",
"... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L486-L500 | [
"def",
"score_",
"(",
"self",
")",
":",
"# pylint: disable=access-member-before-definition",
"if",
"hasattr",
"(",
"self",
",",
"\"_predicted_hazards_\"",
")",
":",
"self",
".",
"_concordance_score_",
"=",
"concordance_index",
"(",
"self",
".",
"durations",
",",
"-"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.summary | Summary statistics describing the fit.
Returns
-------
df : DataFrame | lifelines/fitters/aalen_additive_fitter.py | def summary(self):
"""Summary statistics describing the fit.
Returns
-------
df : DataFrame
"""
df = pd.DataFrame(index=self.cumulative_hazards_.columns)
betas, se = self._compute_slopes()
df["slope(coef)"] = betas
df["se(slope(coef))"] = se
... | def summary(self):
"""Summary statistics describing the fit.
Returns
-------
df : DataFrame
"""
df = pd.DataFrame(index=self.cumulative_hazards_.columns)
betas, se = self._compute_slopes()
df["slope(coef)"] = betas
df["se(slope(coef))"] = se
... | [
"Summary",
"statistics",
"describing",
"the",
"fit",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L517-L529 | [
"def",
"summary",
"(",
"self",
")",
":",
"df",
"=",
"pd",
".",
"DataFrame",
"(",
"index",
"=",
"self",
".",
"cumulative_hazards_",
".",
"columns",
")",
"betas",
",",
"se",
"=",
"self",
".",
"_compute_slopes",
"(",
")",
"df",
"[",
"\"slope(coef)\"",
"]"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenAdditiveFitter.print_summary | Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
print additional meta data in the output (useful to provide model ... | lifelines/fitters/aalen_additive_fitter.py | def print_summary(self, decimals=2, **kwargs):
"""
Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
... | def print_summary(self, decimals=2, **kwargs):
"""
Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
... | [
"Print",
"summary",
"statistics",
"describing",
"the",
"fit",
"the",
"coefficients",
"and",
"the",
"error",
"bounds",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_additive_fitter.py#L531-L579 | [
"def",
"print_summary",
"(",
"self",
",",
"decimals",
"=",
"2",
",",
"*",
"*",
"kwargs",
")",
":",
"# Print information about data first",
"justify",
"=",
"string_justify",
"(",
"18",
")",
"print",
"(",
"self",
")",
"print",
"(",
"\"{} = '{}'\"",
".",
"forma... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | WeibullAFTFitter.predict_percentile | Returns the median lifetimes for the individuals, by default. If the survival curve of an
individual does not cross 0.5, then the result is infinity.
http://stats.stackexchange.com/questions/102986/percentile-loss-functions
Parameters
----------
X: numpy array or DataFrame
... | lifelines/fitters/weibull_aft_fitter.py | def predict_percentile(self, X, ancillary_X=None, p=0.5):
"""
Returns the median lifetimes for the individuals, by default. If the survival curve of an
individual does not cross 0.5, then the result is infinity.
http://stats.stackexchange.com/questions/102986/percentile-loss-functions
... | def predict_percentile(self, X, ancillary_X=None, p=0.5):
"""
Returns the median lifetimes for the individuals, by default. If the survival curve of an
individual does not cross 0.5, then the result is infinity.
http://stats.stackexchange.com/questions/102986/percentile-loss-functions
... | [
"Returns",
"the",
"median",
"lifetimes",
"for",
"the",
"individuals",
"by",
"default",
".",
"If",
"the",
"survival",
"curve",
"of",
"an",
"individual",
"does",
"not",
"cross",
"0",
".",
"5",
"then",
"the",
"result",
"is",
"infinity",
".",
"http",
":",
"/... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/weibull_aft_fitter.py#L83-L113 | [
"def",
"predict_percentile",
"(",
"self",
",",
"X",
",",
"ancillary_X",
"=",
"None",
",",
"p",
"=",
"0.5",
")",
":",
"lambda_",
",",
"rho_",
"=",
"self",
".",
"_prep_inputs_for_prediction_and_return_scores",
"(",
"X",
",",
"ancillary_X",
")",
"return",
"pd",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | WeibullAFTFitter.predict_expectation | Predict the expectation of lifetimes, :math:`E[T | x]`.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order as the train... | lifelines/fitters/weibull_aft_fitter.py | def predict_expectation(self, X, ancillary_X=None):
"""
Predict the expectation of lifetimes, :math:`E[T | x]`.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a... | def predict_expectation(self, X, ancillary_X=None):
"""
Predict the expectation of lifetimes, :math:`E[T | x]`.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a... | [
"Predict",
"the",
"expectation",
"of",
"lifetimes",
":",
"math",
":",
"E",
"[",
"T",
"|",
"x",
"]",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/weibull_aft_fitter.py#L115-L142 | [
"def",
"predict_expectation",
"(",
"self",
",",
"X",
",",
"ancillary_X",
"=",
"None",
")",
":",
"lambda_",
",",
"rho_",
"=",
"self",
".",
"_prep_inputs_for_prediction_and_return_scores",
"(",
"X",
",",
"ancillary_X",
")",
"return",
"pd",
".",
"DataFrame",
"(",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | WeibullAFTFitter.predict_cumulative_hazard | Return the cumulative hazard rate of subjects in X at time points.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
can be in any order. If a numpy array, columns must be in the
same order a... | lifelines/fitters/weibull_aft_fitter.py | def predict_cumulative_hazard(self, X, times=None, ancillary_X=None):
"""
Return the cumulative hazard rate of subjects in X at time points.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
... | def predict_cumulative_hazard(self, X, times=None, ancillary_X=None):
"""
Return the cumulative hazard rate of subjects in X at time points.
Parameters
----------
X: numpy array or DataFrame
a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
... | [
"Return",
"the",
"cumulative",
"hazard",
"rate",
"of",
"subjects",
"in",
"X",
"at",
"time",
"points",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/weibull_aft_fitter.py#L144-L171 | [
"def",
"predict_cumulative_hazard",
"(",
"self",
",",
"X",
",",
"times",
"=",
"None",
",",
"ancillary_X",
"=",
"None",
")",
":",
"times",
"=",
"coalesce",
"(",
"times",
",",
"self",
".",
"timeline",
",",
"np",
".",
"unique",
"(",
"self",
".",
"duration... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenJohansenFitter.fit | Parameters
----------
durations: an array or pd.Series of length n -- duration of subject was observed for
event_observed: an array, or pd.Series, of length n. Integer indicator of distinct events. Must be
only positive integers, where 0 indicates censoring.
event_of_i... | lifelines/fitters/aalen_johansen_fitter.py | def fit(
self,
durations,
event_observed,
event_of_interest,
timeline=None,
entry=None,
label="AJ_estimate",
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
Paramete... | def fit(
self,
durations,
event_observed,
event_of_interest,
timeline=None,
entry=None,
label="AJ_estimate",
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
Paramete... | [
"Parameters",
"----------",
"durations",
":",
"an",
"array",
"or",
"pd",
".",
"Series",
"of",
"length",
"n",
"--",
"duration",
"of",
"subject",
"was",
"observed",
"for",
"event_observed",
":",
"an",
"array",
"or",
"pd",
".",
"Series",
"of",
"length",
"n",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_johansen_fitter.py#L63-L173 | [
"def",
"fit",
"(",
"self",
",",
"durations",
",",
"event_observed",
",",
"event_of_interest",
",",
"timeline",
"=",
"None",
",",
"entry",
"=",
"None",
",",
"label",
"=",
"\"AJ_estimate\"",
",",
"alpha",
"=",
"None",
",",
"ci_labels",
"=",
"None",
",",
"w... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenJohansenFitter._jitter | Determine extent to jitter tied event times. Automatically called by fit if tied event times are detected | lifelines/fitters/aalen_johansen_fitter.py | def _jitter(self, durations, event, jitter_level, seed=None):
"""Determine extent to jitter tied event times. Automatically called by fit if tied event times are detected
"""
np.random.seed(seed)
if jitter_level <= 0:
raise ValueError("The jitter level is less than zero, ple... | def _jitter(self, durations, event, jitter_level, seed=None):
"""Determine extent to jitter tied event times. Automatically called by fit if tied event times are detected
"""
np.random.seed(seed)
if jitter_level <= 0:
raise ValueError("The jitter level is less than zero, ple... | [
"Determine",
"extent",
"to",
"jitter",
"tied",
"event",
"times",
".",
"Automatically",
"called",
"by",
"fit",
"if",
"tied",
"event",
"times",
"are",
"detected"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_johansen_fitter.py#L175-L194 | [
"def",
"_jitter",
"(",
"self",
",",
"durations",
",",
"event",
",",
"jitter_level",
",",
"seed",
"=",
"None",
")",
":",
"np",
".",
"random",
".",
"seed",
"(",
"seed",
")",
"if",
"jitter_level",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"\"The jitter ... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenJohansenFitter._bounds | Bounds are based on pg 411 of "Modelling Survival Data in Medical Research" David Collett 3rd Edition, which
is derived from Greenwood's variance estimator. Confidence intervals are obtained using the delta method
transformation of SE(log(-log(F_j))). This ensures that the confidence intervals all lie b... | lifelines/fitters/aalen_johansen_fitter.py | def _bounds(self, lagged_survival, alpha, ci_labels):
"""Bounds are based on pg 411 of "Modelling Survival Data in Medical Research" David Collett 3rd Edition, which
is derived from Greenwood's variance estimator. Confidence intervals are obtained using the delta method
transformation of SE(log(... | def _bounds(self, lagged_survival, alpha, ci_labels):
"""Bounds are based on pg 411 of "Modelling Survival Data in Medical Research" David Collett 3rd Edition, which
is derived from Greenwood's variance estimator. Confidence intervals are obtained using the delta method
transformation of SE(log(... | [
"Bounds",
"are",
"based",
"on",
"pg",
"411",
"of",
"Modelling",
"Survival",
"Data",
"in",
"Medical",
"Research",
"David",
"Collett",
"3rd",
"Edition",
"which",
"is",
"derived",
"from",
"Greenwood",
"s",
"variance",
"estimator",
".",
"Confidence",
"intervals",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_johansen_fitter.py#L196-L253 | [
"def",
"_bounds",
"(",
"self",
",",
"lagged_survival",
",",
"alpha",
",",
"ci_labels",
")",
":",
"# Preparing environment",
"ci",
"=",
"1",
"-",
"alpha",
"df",
"=",
"self",
".",
"event_table",
".",
"copy",
"(",
")",
"df",
"[",
"\"Ft\"",
"]",
"=",
"self... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | AalenJohansenFitter._check_for_duplicates | Checks for duplicated event times in the data set. This is narrowed to detecting duplicated event times
where the events are of different types | lifelines/fitters/aalen_johansen_fitter.py | def _check_for_duplicates(durations, events):
"""Checks for duplicated event times in the data set. This is narrowed to detecting duplicated event times
where the events are of different types
"""
# Setting up DataFrame to detect duplicates
df = pd.DataFrame({"t": durations, "e":... | def _check_for_duplicates(durations, events):
"""Checks for duplicated event times in the data set. This is narrowed to detecting duplicated event times
where the events are of different types
"""
# Setting up DataFrame to detect duplicates
df = pd.DataFrame({"t": durations, "e":... | [
"Checks",
"for",
"duplicated",
"event",
"times",
"in",
"the",
"data",
"set",
".",
"This",
"is",
"narrowed",
"to",
"detecting",
"duplicated",
"event",
"times",
"where",
"the",
"events",
"are",
"of",
"different",
"types"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/aalen_johansen_fitter.py#L256-L270 | [
"def",
"_check_for_duplicates",
"(",
"durations",
",",
"events",
")",
":",
"# Setting up DataFrame to detect duplicates",
"df",
"=",
"pd",
".",
"DataFrame",
"(",
"{",
"\"t\"",
":",
"durations",
",",
"\"e\"",
":",
"events",
"}",
")",
"# Finding duplicated event times... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | sample_size_necessary_under_cph | This computes the sample size for needed power to compare two groups under a Cox
Proportional Hazard model.
Parameters
----------
power : float
power to detect the magnitude of the hazard ratio as small as that specified by postulated_hazard_ratio.
ratio_of_participants: ratio of participa... | lifelines/statistics.py | def sample_size_necessary_under_cph(power, ratio_of_participants, p_exp, p_con, postulated_hazard_ratio, alpha=0.05):
"""
This computes the sample size for needed power to compare two groups under a Cox
Proportional Hazard model.
Parameters
----------
power : float
power to detect the ... | def sample_size_necessary_under_cph(power, ratio_of_participants, p_exp, p_con, postulated_hazard_ratio, alpha=0.05):
"""
This computes the sample size for needed power to compare two groups under a Cox
Proportional Hazard model.
Parameters
----------
power : float
power to detect the ... | [
"This",
"computes",
"the",
"sample",
"size",
"for",
"needed",
"power",
"to",
"compare",
"two",
"groups",
"under",
"a",
"Cox",
"Proportional",
"Hazard",
"model",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/statistics.py#L33-L102 | [
"def",
"sample_size_necessary_under_cph",
"(",
"power",
",",
"ratio_of_participants",
",",
"p_exp",
",",
"p_con",
",",
"postulated_hazard_ratio",
",",
"alpha",
"=",
"0.05",
")",
":",
"def",
"z",
"(",
"p",
")",
":",
"return",
"stats",
".",
"norm",
".",
"ppf",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | power_under_cph | This computes the power of the hypothesis test that the two groups, experiment and control,
have different hazards (that is, the relative hazard ratio is different from 1.)
Parameters
----------
n_exp : integer
size of the experiment group.
n_con : integer
size of the control grou... | lifelines/statistics.py | def power_under_cph(n_exp, n_con, p_exp, p_con, postulated_hazard_ratio, alpha=0.05):
"""
This computes the power of the hypothesis test that the two groups, experiment and control,
have different hazards (that is, the relative hazard ratio is different from 1.)
Parameters
----------
n_exp : i... | def power_under_cph(n_exp, n_con, p_exp, p_con, postulated_hazard_ratio, alpha=0.05):
"""
This computes the power of the hypothesis test that the two groups, experiment and control,
have different hazards (that is, the relative hazard ratio is different from 1.)
Parameters
----------
n_exp : i... | [
"This",
"computes",
"the",
"power",
"of",
"the",
"hypothesis",
"test",
"that",
"the",
"two",
"groups",
"experiment",
"and",
"control",
"have",
"different",
"hazards",
"(",
"that",
"is",
"the",
"relative",
"hazard",
"ratio",
"is",
"different",
"from",
"1",
".... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/statistics.py#L105-L155 | [
"def",
"power_under_cph",
"(",
"n_exp",
",",
"n_con",
",",
"p_exp",
",",
"p_con",
",",
"postulated_hazard_ratio",
",",
"alpha",
"=",
"0.05",
")",
":",
"def",
"z",
"(",
"p",
")",
":",
"return",
"stats",
".",
"norm",
".",
"ppf",
"(",
"p",
")",
"m",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | lowess | lowess(x, y, f=2./3., iter=3) -> yest
Lowess smoother: Robust locally weighted regression.
The lowess function fits a nonparametric regression curve to a scatterplot.
The arrays x and y contain an equal number of elements; each pair
(x[i], y[i]) defines a data point in the scatterplot. The function retu... | lifelines/utils/lowess.py | def lowess(x, y, f=2.0 / 3.0, iterations=3):
"""lowess(x, y, f=2./3., iter=3) -> yest
Lowess smoother: Robust locally weighted regression.
The lowess function fits a nonparametric regression curve to a scatterplot.
The arrays x and y contain an equal number of elements; each pair
(x[i], y[i]) define... | def lowess(x, y, f=2.0 / 3.0, iterations=3):
"""lowess(x, y, f=2./3., iter=3) -> yest
Lowess smoother: Robust locally weighted regression.
The lowess function fits a nonparametric regression curve to a scatterplot.
The arrays x and y contain an equal number of elements; each pair
(x[i], y[i]) define... | [
"lowess",
"(",
"x",
"y",
"f",
"=",
"2",
".",
"/",
"3",
".",
"iter",
"=",
"3",
")",
"-",
">",
"yest",
"Lowess",
"smoother",
":",
"Robust",
"locally",
"weighted",
"regression",
".",
"The",
"lowess",
"function",
"fits",
"a",
"nonparametric",
"regression",... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/lowess.py#L26-L59 | [
"def",
"lowess",
"(",
"x",
",",
"y",
",",
"f",
"=",
"2.0",
"/",
"3.0",
",",
"iterations",
"=",
"3",
")",
":",
"n",
"=",
"len",
"(",
"x",
")",
"r",
"=",
"int",
"(",
"ceil",
"(",
"f",
"*",
"n",
")",
")",
"h",
"=",
"[",
"np",
".",
"sort",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | qth_survival_times | Find the times when one or more survival functions reach the qth percentile.
Parameters
----------
q: float or array
a float between 0 and 1 that represents the time when the survival function hits the qth percentile.
survival_functions: a (n,d) DataFrame or numpy array.
If DataFrame, will ... | lifelines/utils/__init__.py | def qth_survival_times(q, survival_functions, cdf=False):
"""
Find the times when one or more survival functions reach the qth percentile.
Parameters
----------
q: float or array
a float between 0 and 1 that represents the time when the survival function hits the qth percentile.
survival_... | def qth_survival_times(q, survival_functions, cdf=False):
"""
Find the times when one or more survival functions reach the qth percentile.
Parameters
----------
q: float or array
a float between 0 and 1 that represents the time when the survival function hits the qth percentile.
survival_... | [
"Find",
"the",
"times",
"when",
"one",
"or",
"more",
"survival",
"functions",
"reach",
"the",
"qth",
"percentile",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L58-L107 | [
"def",
"qth_survival_times",
"(",
"q",
",",
"survival_functions",
",",
"cdf",
"=",
"False",
")",
":",
"# pylint: disable=cell-var-from-loop,misplaced-comparison-constant,no-else-return",
"q",
"=",
"pd",
".",
"Series",
"(",
"q",
")",
"if",
"not",
"(",
"(",
"q",
"<=... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | qth_survival_time | Returns the time when a single survival function reaches the qth percentile.
Parameters
----------
q: float
a float between 0 and 1 that represents the time when the survival function hit's the qth percentile.
survival_function: Series or single-column DataFrame.
cdf: boolean, optional
... | lifelines/utils/__init__.py | def qth_survival_time(q, survival_function, cdf=False):
"""
Returns the time when a single survival function reaches the qth percentile.
Parameters
----------
q: float
a float between 0 and 1 that represents the time when the survival function hit's the qth percentile.
survival_function: ... | def qth_survival_time(q, survival_function, cdf=False):
"""
Returns the time when a single survival function reaches the qth percentile.
Parameters
----------
q: float
a float between 0 and 1 that represents the time when the survival function hit's the qth percentile.
survival_function: ... | [
"Returns",
"the",
"time",
"when",
"a",
"single",
"survival",
"function",
"reaches",
"the",
"qth",
"percentile",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L110-L145 | [
"def",
"qth_survival_time",
"(",
"q",
",",
"survival_function",
",",
"cdf",
"=",
"False",
")",
":",
"if",
"type",
"(",
"survival_function",
")",
"is",
"pd",
".",
"DataFrame",
":",
"# pylint: disable=unidiomatic-typecheck",
"if",
"survival_function",
".",
"shape",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | group_survival_table_from_events | Joins multiple event series together into DataFrames. A generalization of
`survival_table_from_events` to data with groups. Previously called `group_event_series` pre 0.2.3.
Parameters
----------
groups: a (n,) array
individuals' group ids.
durations: a (n,) array
durations of each ind... | lifelines/utils/__init__.py | def group_survival_table_from_events(
groups, durations, event_observed, birth_times=None, limit=-1
): # pylint: disable=too-many-locals
"""
Joins multiple event series together into DataFrames. A generalization of
`survival_table_from_events` to data with groups. Previously called `group_event_series`... | def group_survival_table_from_events(
groups, durations, event_observed, birth_times=None, limit=-1
): # pylint: disable=too-many-locals
"""
Joins multiple event series together into DataFrames. A generalization of
`survival_table_from_events` to data with groups. Previously called `group_event_series`... | [
"Joins",
"multiple",
"event",
"series",
"together",
"into",
"DataFrames",
".",
"A",
"generalization",
"of",
"survival_table_from_events",
"to",
"data",
"with",
"groups",
".",
"Previously",
"called",
"group_event_series",
"pre",
"0",
".",
"2",
".",
"3",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L152-L259 | [
"def",
"group_survival_table_from_events",
"(",
"groups",
",",
"durations",
",",
"event_observed",
",",
"birth_times",
"=",
"None",
",",
"limit",
"=",
"-",
"1",
")",
":",
"# pylint: disable=too-many-locals",
"n",
"=",
"np",
".",
"max",
"(",
"groups",
".",
"sha... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | survival_table_from_events | Parameters
----------
death_times: (n,) array
represent the event times
event_observed: (n,) array
1 if observed event, 0 is censored event.
birth_times: a (n,) array, optional
representing when the subject was first observed. A subject's death event is then at [birth times + duration ... | lifelines/utils/__init__.py | def survival_table_from_events(
death_times,
event_observed,
birth_times=None,
columns=["removed", "observed", "censored", "entrance", "at_risk"],
weights=None,
collapse=False,
intervals=None,
): # pylint: disable=dangerous-default-value,too-many-locals
"""
Parameters
----------... | def survival_table_from_events(
death_times,
event_observed,
birth_times=None,
columns=["removed", "observed", "censored", "entrance", "at_risk"],
weights=None,
collapse=False,
intervals=None,
): # pylint: disable=dangerous-default-value,too-many-locals
"""
Parameters
----------... | [
"Parameters",
"----------",
"death_times",
":",
"(",
"n",
")",
"array",
"represent",
"the",
"event",
"times",
"event_observed",
":",
"(",
"n",
")",
"array",
"1",
"if",
"observed",
"event",
"0",
"is",
"censored",
"event",
".",
"birth_times",
":",
"a",
"(",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L262-L361 | [
"def",
"survival_table_from_events",
"(",
"death_times",
",",
"event_observed",
",",
"birth_times",
"=",
"None",
",",
"columns",
"=",
"[",
"\"removed\"",
",",
"\"observed\"",
",",
"\"censored\"",
",",
"\"entrance\"",
",",
"\"at_risk\"",
"]",
",",
"weights",
"=",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | survival_events_from_table | This is the inverse of the function ``survival_table_from_events``.
Parameters
----------
survival_table: DataFrame
a pandas DataFrame with index as the durations and columns "observed" and "censored", referring to
the number of individuals that died and were censored at time t.
obse... | lifelines/utils/__init__.py | def survival_events_from_table(survival_table, observed_deaths_col="observed", censored_col="censored"):
"""
This is the inverse of the function ``survival_table_from_events``.
Parameters
----------
survival_table: DataFrame
a pandas DataFrame with index as the durations and columns "observ... | def survival_events_from_table(survival_table, observed_deaths_col="observed", censored_col="censored"):
"""
This is the inverse of the function ``survival_table_from_events``.
Parameters
----------
survival_table: DataFrame
a pandas DataFrame with index as the durations and columns "observ... | [
"This",
"is",
"the",
"inverse",
"of",
"the",
"function",
"survival_table_from_events",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L387-L442 | [
"def",
"survival_events_from_table",
"(",
"survival_table",
",",
"observed_deaths_col",
"=",
"\"observed\"",
",",
"censored_col",
"=",
"\"censored\"",
")",
":",
"T_",
"=",
"[",
"]",
"E_",
"=",
"[",
"]",
"W_",
"=",
"[",
"]",
"for",
"t",
",",
"row",
"in",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | datetimes_to_durations | This is a very flexible function for transforming arrays of start_times and end_times
to the proper format for lifelines: duration and event observation arrays.
Parameters
----------
start_times: an array, Series or DataFrame
iterable representing start times. These can be strings, or datetime ... | lifelines/utils/__init__.py | def datetimes_to_durations(
start_times, end_times, fill_date=datetime.today(), freq="D", dayfirst=False, na_values=None
):
"""
This is a very flexible function for transforming arrays of start_times and end_times
to the proper format for lifelines: duration and event observation arrays.
Parameters... | def datetimes_to_durations(
start_times, end_times, fill_date=datetime.today(), freq="D", dayfirst=False, na_values=None
):
"""
This is a very flexible function for transforming arrays of start_times and end_times
to the proper format for lifelines: duration and event observation arrays.
Parameters... | [
"This",
"is",
"a",
"very",
"flexible",
"function",
"for",
"transforming",
"arrays",
"of",
"start_times",
"and",
"end_times",
"to",
"the",
"proper",
"format",
"for",
"lifelines",
":",
"duration",
"and",
"event",
"observation",
"arrays",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L445-L503 | [
"def",
"datetimes_to_durations",
"(",
"start_times",
",",
"end_times",
",",
"fill_date",
"=",
"datetime",
".",
"today",
"(",
")",
",",
"freq",
"=",
"\"D\"",
",",
"dayfirst",
"=",
"False",
",",
"na_values",
"=",
"None",
")",
":",
"fill_date",
"=",
"pd",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | l1_log_loss | r"""
Calculates the l1 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} |log(t_i) - log(q_i)|
Parameters
----------
event_times: a (n,) array of observed survival times.
predicted_event_times: a (n,) array of predicted s... | lifelines/utils/__init__.py | def l1_log_loss(event_times, predicted_event_times, event_observed=None):
r"""
Calculates the l1 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} |log(t_i) - log(q_i)|
Parameters
----------
event_times: a (n,) array of obs... | def l1_log_loss(event_times, predicted_event_times, event_observed=None):
r"""
Calculates the l1 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} |log(t_i) - log(q_i)|
Parameters
----------
event_times: a (n,) array of obs... | [
"r",
"Calculates",
"the",
"l1",
"log",
"-",
"loss",
"of",
"predicted",
"event",
"times",
"to",
"true",
"event",
"times",
"for",
"*",
"non",
"-",
"censored",
"*",
"individuals",
"only",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L506-L528 | [
"def",
"l1_log_loss",
"(",
"event_times",
",",
"predicted_event_times",
",",
"event_observed",
"=",
"None",
")",
":",
"if",
"event_observed",
"is",
"None",
":",
"event_observed",
"=",
"np",
".",
"ones_like",
"(",
"event_times",
")",
"ix",
"=",
"event_observed",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | l2_log_loss | r"""
Calculates the l2 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} (log(t_i) - log(q_i))**2
Parameters
----------
event_times: a (n,) array of observed survival times.
predicted_event_times: a (n,) array of predicte... | lifelines/utils/__init__.py | def l2_log_loss(event_times, predicted_event_times, event_observed=None):
r"""
Calculates the l2 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} (log(t_i) - log(q_i))**2
Parameters
----------
event_times: a (n,) array of ... | def l2_log_loss(event_times, predicted_event_times, event_observed=None):
r"""
Calculates the l2 log-loss of predicted event times to true event times for *non-censored*
individuals only.
.. math:: 1/N \sum_{i} (log(t_i) - log(q_i))**2
Parameters
----------
event_times: a (n,) array of ... | [
"r",
"Calculates",
"the",
"l2",
"log",
"-",
"loss",
"of",
"predicted",
"event",
"times",
"to",
"true",
"event",
"times",
"for",
"*",
"non",
"-",
"censored",
"*",
"individuals",
"only",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L531-L553 | [
"def",
"l2_log_loss",
"(",
"event_times",
",",
"predicted_event_times",
",",
"event_observed",
"=",
"None",
")",
":",
"if",
"event_observed",
"is",
"None",
":",
"event_observed",
"=",
"np",
".",
"ones_like",
"(",
"event_times",
")",
"ix",
"=",
"event_observed",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | k_fold_cross_validation | Perform cross validation on a dataset. If multiple models are provided,
all models will train on each of the k subsets.
Parameters
----------
fitters: model
one or several objects which possess a method: ``fit(self, data, duration_col, event_col)``
Note that the last two arguments will be g... | lifelines/utils/__init__.py | def k_fold_cross_validation(
fitters,
df,
duration_col,
event_col=None,
k=5,
evaluation_measure=concordance_index,
predictor="predict_expectation",
predictor_kwargs={},
fitter_kwargs={},
): # pylint: disable=dangerous-default-value,too-many-arguments,too-many-locals
"""
Perf... | def k_fold_cross_validation(
fitters,
df,
duration_col,
event_col=None,
k=5,
evaluation_measure=concordance_index,
predictor="predict_expectation",
predictor_kwargs={},
fitter_kwargs={},
): # pylint: disable=dangerous-default-value,too-many-arguments,too-many-locals
"""
Perf... | [
"Perform",
"cross",
"validation",
"on",
"a",
"dataset",
".",
"If",
"multiple",
"models",
"are",
"provided",
"all",
"models",
"will",
"train",
"on",
"each",
"of",
"the",
"k",
"subsets",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L567-L666 | [
"def",
"k_fold_cross_validation",
"(",
"fitters",
",",
"df",
",",
"duration_col",
",",
"event_col",
"=",
"None",
",",
"k",
"=",
"5",
",",
"evaluation_measure",
"=",
"concordance_index",
",",
"predictor",
"=",
"\"predict_expectation\"",
",",
"predictor_kwargs",
"="... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | normalize | Normalize X. If mean OR std is None, normalizes
X to have mean 0 and std 1. | lifelines/utils/__init__.py | def normalize(X, mean=None, std=None):
"""
Normalize X. If mean OR std is None, normalizes
X to have mean 0 and std 1.
"""
if mean is None or std is None:
mean = X.mean(0)
std = X.std(0)
return (X - mean) / std | def normalize(X, mean=None, std=None):
"""
Normalize X. If mean OR std is None, normalizes
X to have mean 0 and std 1.
"""
if mean is None or std is None:
mean = X.mean(0)
std = X.std(0)
return (X - mean) / std | [
"Normalize",
"X",
".",
"If",
"mean",
"OR",
"std",
"is",
"None",
"normalizes",
"X",
"to",
"have",
"mean",
"0",
"and",
"std",
"1",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L669-L677 | [
"def",
"normalize",
"(",
"X",
",",
"mean",
"=",
"None",
",",
"std",
"=",
"None",
")",
":",
"if",
"mean",
"is",
"None",
"or",
"std",
"is",
"None",
":",
"mean",
"=",
"X",
".",
"mean",
"(",
"0",
")",
"std",
"=",
"X",
".",
"std",
"(",
"0",
")",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | ridge_regression | Also known as Tikhonov regularization. This solves the minimization problem:
min_{beta} ||(beta X - Y)||^2 + c1||beta||^2 + c2||beta - offset||^2
One can find more information here: http://en.wikipedia.org/wiki/Tikhonov_regularization
Parameters
----------
X: a (n,d) numpy array
Y: a (n,) num... | lifelines/utils/__init__.py | def ridge_regression(X, Y, c1=0.0, c2=0.0, offset=None, ix=None):
"""
Also known as Tikhonov regularization. This solves the minimization problem:
min_{beta} ||(beta X - Y)||^2 + c1||beta||^2 + c2||beta - offset||^2
One can find more information here: http://en.wikipedia.org/wiki/Tikhonov_regularizati... | def ridge_regression(X, Y, c1=0.0, c2=0.0, offset=None, ix=None):
"""
Also known as Tikhonov regularization. This solves the minimization problem:
min_{beta} ||(beta X - Y)||^2 + c1||beta||^2 + c2||beta - offset||^2
One can find more information here: http://en.wikipedia.org/wiki/Tikhonov_regularizati... | [
"Also",
"known",
"as",
"Tikhonov",
"regularization",
".",
"This",
"solves",
"the",
"minimization",
"problem",
":"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L694-L734 | [
"def",
"ridge_regression",
"(",
"X",
",",
"Y",
",",
"c1",
"=",
"0.0",
",",
"c2",
"=",
"0.0",
",",
"offset",
"=",
"None",
",",
"ix",
"=",
"None",
")",
":",
"_",
",",
"d",
"=",
"X",
".",
"shape",
"if",
"c1",
">",
"0",
"or",
"c2",
">",
"0",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | _additive_estimate | Called to compute the Kaplan Meier and Nelson-Aalen estimates. | lifelines/utils/__init__.py | def _additive_estimate(events, timeline, _additive_f, _additive_var, reverse):
"""
Called to compute the Kaplan Meier and Nelson-Aalen estimates.
"""
if reverse:
events = events.sort_index(ascending=False)
at_risk = events["entrance"].sum() - events["removed"].cumsum().shift(1).fillna(0... | def _additive_estimate(events, timeline, _additive_f, _additive_var, reverse):
"""
Called to compute the Kaplan Meier and Nelson-Aalen estimates.
"""
if reverse:
events = events.sort_index(ascending=False)
at_risk = events["entrance"].sum() - events["removed"].cumsum().shift(1).fillna(0... | [
"Called",
"to",
"compute",
"the",
"Kaplan",
"Meier",
"and",
"Nelson",
"-",
"Aalen",
"estimates",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L737-L770 | [
"def",
"_additive_estimate",
"(",
"events",
",",
"timeline",
",",
"_additive_f",
",",
"_additive_var",
",",
"reverse",
")",
":",
"if",
"reverse",
":",
"events",
"=",
"events",
".",
"sort_index",
"(",
"ascending",
"=",
"False",
")",
"at_risk",
"=",
"events",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | _preprocess_inputs | Cleans and confirms input to what lifelines expects downstream | lifelines/utils/__init__.py | def _preprocess_inputs(durations, event_observed, timeline, entry, weights):
"""
Cleans and confirms input to what lifelines expects downstream
"""
n = len(durations)
durations = np.asarray(pass_for_numeric_dtypes_or_raise_array(durations)).reshape((n,))
# set to all observed if event_observed... | def _preprocess_inputs(durations, event_observed, timeline, entry, weights):
"""
Cleans and confirms input to what lifelines expects downstream
"""
n = len(durations)
durations = np.asarray(pass_for_numeric_dtypes_or_raise_array(durations)).reshape((n,))
# set to all observed if event_observed... | [
"Cleans",
"and",
"confirms",
"input",
"to",
"what",
"lifelines",
"expects",
"downstream"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L773-L796 | [
"def",
"_preprocess_inputs",
"(",
"durations",
",",
"event_observed",
",",
"timeline",
",",
"entry",
",",
"weights",
")",
":",
"n",
"=",
"len",
"(",
"durations",
")",
"durations",
"=",
"np",
".",
"asarray",
"(",
"pass_for_numeric_dtypes_or_raise_array",
"(",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | pass_for_numeric_dtypes_or_raise_array | Use the utility `to_numeric` to check that x is convertible to numeric values, and then convert. Any errors
are reported back to the user.
Parameters
----------
x: list, array, Series, DataFrame
Notes
------
This actually allows objects like timedeltas (converted to microseconds), and stri... | lifelines/utils/__init__.py | def pass_for_numeric_dtypes_or_raise_array(x):
"""
Use the utility `to_numeric` to check that x is convertible to numeric values, and then convert. Any errors
are reported back to the user.
Parameters
----------
x: list, array, Series, DataFrame
Notes
------
This actually allows ob... | def pass_for_numeric_dtypes_or_raise_array(x):
"""
Use the utility `to_numeric` to check that x is convertible to numeric values, and then convert. Any errors
are reported back to the user.
Parameters
----------
x: list, array, Series, DataFrame
Notes
------
This actually allows ob... | [
"Use",
"the",
"utility",
"to_numeric",
"to",
"check",
"that",
"x",
"is",
"convertible",
"to",
"numeric",
"values",
"and",
"then",
"convert",
".",
"Any",
"errors",
"are",
"reported",
"back",
"to",
"the",
"user",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L809-L834 | [
"def",
"pass_for_numeric_dtypes_or_raise_array",
"(",
"x",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"x",
",",
"(",
"pd",
".",
"Series",
",",
"pd",
".",
"DataFrame",
")",
")",
":",
"v",
"=",
"pd",
".",
"to_numeric",
"(",
"x",
".",
"squeeze",
"("... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | to_episodic_format | This function takes a "flat" dataset (that is, non-time-varying), and converts it into a time-varying dataset
with static variables.
Useful if your dataset has variables that do not satisfy the proportional hazard assumption, and you need to create a
time-varying dataset to include interaction terms with t... | lifelines/utils/__init__.py | def to_episodic_format(df, duration_col, event_col, id_col=None, time_gaps=1):
"""
This function takes a "flat" dataset (that is, non-time-varying), and converts it into a time-varying dataset
with static variables.
Useful if your dataset has variables that do not satisfy the proportional hazard assump... | def to_episodic_format(df, duration_col, event_col, id_col=None, time_gaps=1):
"""
This function takes a "flat" dataset (that is, non-time-varying), and converts it into a time-varying dataset
with static variables.
Useful if your dataset has variables that do not satisfy the proportional hazard assump... | [
"This",
"function",
"takes",
"a",
"flat",
"dataset",
"(",
"that",
"is",
"non",
"-",
"time",
"-",
"varying",
")",
"and",
"converts",
"it",
"into",
"a",
"time",
"-",
"varying",
"dataset",
"with",
"static",
"variables",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L987-L1095 | [
"def",
"to_episodic_format",
"(",
"df",
",",
"duration_col",
",",
"event_col",
",",
"id_col",
"=",
"None",
",",
"time_gaps",
"=",
"1",
")",
":",
"df",
"=",
"df",
".",
"copy",
"(",
")",
"df",
"[",
"duration_col",
"]",
"/=",
"time_gaps",
"df",
"=",
"to... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | to_long_format | This function converts a survival analysis DataFrame to a lifelines "long" format. The lifelines "long"
format is used in a common next function, ``add_covariate_to_timeline``.
Parameters
----------
df: DataFrame
a DataFrame in the standard survival analysis form (one for per observation, with ... | lifelines/utils/__init__.py | def to_long_format(df, duration_col):
"""
This function converts a survival analysis DataFrame to a lifelines "long" format. The lifelines "long"
format is used in a common next function, ``add_covariate_to_timeline``.
Parameters
----------
df: DataFrame
a DataFrame in the standard surv... | def to_long_format(df, duration_col):
"""
This function converts a survival analysis DataFrame to a lifelines "long" format. The lifelines "long"
format is used in a common next function, ``add_covariate_to_timeline``.
Parameters
----------
df: DataFrame
a DataFrame in the standard surv... | [
"This",
"function",
"converts",
"a",
"survival",
"analysis",
"DataFrame",
"to",
"a",
"lifelines",
"long",
"format",
".",
"The",
"lifelines",
"long",
"format",
"is",
"used",
"in",
"a",
"common",
"next",
"function",
"add_covariate_to_timeline",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L1098-L1120 | [
"def",
"to_long_format",
"(",
"df",
",",
"duration_col",
")",
":",
"return",
"df",
".",
"assign",
"(",
"start",
"=",
"0",
",",
"stop",
"=",
"lambda",
"s",
":",
"s",
"[",
"duration_col",
"]",
")",
".",
"drop",
"(",
"duration_col",
",",
"axis",
"=",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | add_covariate_to_timeline | This is a util function to help create a long form table tracking subjects' covariate changes over time. It is meant
to be used iteratively as one adds more and more covariates to track over time. Before using this function, it is recommended
to view the documentation at https://lifelines.readthedocs.io/en/late... | lifelines/utils/__init__.py | def add_covariate_to_timeline(
long_form_df,
cv,
id_col,
duration_col,
event_col,
start_col="start",
stop_col="stop",
add_enum=False,
overwrite=True,
cumulative_sum=False,
cumulative_sum_prefix="cumsum_",
delay=0,
): # pylint: disable=too-many-arguments
"""
This ... | def add_covariate_to_timeline(
long_form_df,
cv,
id_col,
duration_col,
event_col,
start_col="start",
stop_col="stop",
add_enum=False,
overwrite=True,
cumulative_sum=False,
cumulative_sum_prefix="cumsum_",
delay=0,
): # pylint: disable=too-many-arguments
"""
This ... | [
"This",
"is",
"a",
"util",
"function",
"to",
"help",
"create",
"a",
"long",
"form",
"table",
"tracking",
"subjects",
"covariate",
"changes",
"over",
"time",
".",
"It",
"is",
"meant",
"to",
"be",
"used",
"iteratively",
"as",
"one",
"adds",
"more",
"and",
... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L1123-L1257 | [
"def",
"add_covariate_to_timeline",
"(",
"long_form_df",
",",
"cv",
",",
"id_col",
",",
"duration_col",
",",
"event_col",
",",
"start_col",
"=",
"\"start\"",
",",
"stop_col",
"=",
"\"stop\"",
",",
"add_enum",
"=",
"False",
",",
"overwrite",
"=",
"True",
",",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | covariates_from_event_matrix | This is a helper function to handle binary event datastreams in a specific format and convert
it to a format that add_covariate_to_timeline will accept. For example, suppose you have a
dataset that looks like:
.. code:: python
id promotion movement raise
0 1 1.0 NaN ... | lifelines/utils/__init__.py | def covariates_from_event_matrix(df, id_col):
"""
This is a helper function to handle binary event datastreams in a specific format and convert
it to a format that add_covariate_to_timeline will accept. For example, suppose you have a
dataset that looks like:
.. code:: python
id promot... | def covariates_from_event_matrix(df, id_col):
"""
This is a helper function to handle binary event datastreams in a specific format and convert
it to a format that add_covariate_to_timeline will accept. For example, suppose you have a
dataset that looks like:
.. code:: python
id promot... | [
"This",
"is",
"a",
"helper",
"function",
"to",
"handle",
"binary",
"event",
"datastreams",
"in",
"a",
"specific",
"format",
"and",
"convert",
"it",
"to",
"a",
"format",
"that",
"add_covariate_to_timeline",
"will",
"accept",
".",
"For",
"example",
"suppose",
"y... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L1260-L1299 | [
"def",
"covariates_from_event_matrix",
"(",
"df",
",",
"id_col",
")",
":",
"df",
"=",
"df",
".",
"set_index",
"(",
"id_col",
")",
"df",
"=",
"df",
".",
"stack",
"(",
")",
".",
"reset_index",
"(",
")",
"df",
".",
"columns",
"=",
"[",
"id_col",
",",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | format_exp_floats | sometimes the exp. column can be too large | lifelines/utils/__init__.py | def format_exp_floats(decimals):
"""
sometimes the exp. column can be too large
"""
threshold = 10 ** 5
return (
lambda n: "{:.{prec}e}".format(n, prec=decimals) if n > threshold else "{:4.{prec}f}".format(n, prec=decimals)
) | def format_exp_floats(decimals):
"""
sometimes the exp. column can be too large
"""
threshold = 10 ** 5
return (
lambda n: "{:.{prec}e}".format(n, prec=decimals) if n > threshold else "{:4.{prec}f}".format(n, prec=decimals)
) | [
"sometimes",
"the",
"exp",
".",
"column",
"can",
"be",
"too",
"large"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/utils/__init__.py#L1383-L1390 | [
"def",
"format_exp_floats",
"(",
"decimals",
")",
":",
"threshold",
"=",
"10",
"**",
"5",
"return",
"(",
"lambda",
"n",
":",
"\"{:.{prec}e}\"",
".",
"format",
"(",
"n",
",",
"prec",
"=",
"decimals",
")",
"if",
"n",
">",
"threshold",
"else",
"\"{:4.{prec}... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | BreslowFlemingHarringtonFitter.fit | Parameters
----------
durations: an array, or pd.Series, of length n
duration subject was observed for
timeline:
return the best estimate at the values in timelines (positively increasing)
event_observed: an array, or pd.Series, of length n
True if the... | lifelines/fitters/breslow_fleming_harrington_fitter.py | def fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="BFH_estimate",
alpha=None,
ci_labels=None,
): # pylint: disable=too-many-arguments
"""
Parameters
----------
durations: an array, or pd.Se... | def fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="BFH_estimate",
alpha=None,
ci_labels=None,
): # pylint: disable=too-many-arguments
"""
Parameters
----------
durations: an array, or pd.Se... | [
"Parameters",
"----------",
"durations",
":",
"an",
"array",
"or",
"pd",
".",
"Series",
"of",
"length",
"n",
"duration",
"subject",
"was",
"observed",
"for",
"timeline",
":",
"return",
"the",
"best",
"estimate",
"at",
"the",
"values",
"in",
"timelines",
"(",... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/breslow_fleming_harrington_fitter.py#L31-L96 | [
"def",
"fit",
"(",
"self",
",",
"durations",
",",
"event_observed",
"=",
"None",
",",
"timeline",
"=",
"None",
",",
"entry",
"=",
"None",
",",
"label",
"=",
"\"BFH_estimate\"",
",",
"alpha",
"=",
"None",
",",
"ci_labels",
"=",
"None",
",",
")",
":",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter.fit | Fit the model to a right-censored dataset
Parameters
----------
durations: an array, list, pd.DataFrame or pd.Series
length n -- duration subject was observed for
event_observed: an array, list, pd.DataFrame, or pd.Series, optional
True if the the death was ... | lifelines/fitters/kaplan_meier_fitter.py | def fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
left_censorship=False,
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
... | def fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
left_censorship=False,
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
... | [
"Fit",
"the",
"model",
"to",
"a",
"right",
"-",
"censored",
"dataset"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L71-L123 | [
"def",
"fit",
"(",
"self",
",",
"durations",
",",
"event_observed",
"=",
"None",
",",
"timeline",
"=",
"None",
",",
"entry",
"=",
"None",
",",
"label",
"=",
"\"KM_estimate\"",
",",
"left_censorship",
"=",
"False",
",",
"alpha",
"=",
"None",
",",
"ci_labe... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter.fit_left_censoring | Fit the model to a left-censored dataset
Parameters
----------
durations: an array, list, pd.DataFrame or pd.Series
length n -- duration subject was observed for
event_observed: an array, list, pd.DataFrame, or pd.Series, optional
True if the the death was o... | lifelines/fitters/kaplan_meier_fitter.py | def fit_left_censoring(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
alpha=None,
ci_labels=None,
weights=None,
):
"""
Fit the model to a left-censored dataset
Parameters
... | def fit_left_censoring(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
alpha=None,
ci_labels=None,
weights=None,
):
"""
Fit the model to a left-censored dataset
Parameters
... | [
"Fit",
"the",
"model",
"to",
"a",
"left",
"-",
"censored",
"dataset"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L125-L170 | [
"def",
"fit_left_censoring",
"(",
"self",
",",
"durations",
",",
"event_observed",
"=",
"None",
",",
"timeline",
"=",
"None",
",",
"entry",
"=",
"None",
",",
"label",
"=",
"\"KM_estimate\"",
",",
"alpha",
"=",
"None",
",",
"ci_labels",
"=",
"None",
",",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter._fit | Parameters
----------
durations: an array, list, pd.DataFrame or pd.Series
length n -- duration subject was observed for
event_observed: an array, list, pd.DataFrame, or pd.Series, optional
True if the the death was observed, False if the event was lost (right-censor... | lifelines/fitters/kaplan_meier_fitter.py | def _fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
Parameters
----------... | def _fit(
self,
durations,
event_observed=None,
timeline=None,
entry=None,
label="KM_estimate",
alpha=None,
ci_labels=None,
weights=None,
): # pylint: disable=too-many-arguments,too-many-locals
"""
Parameters
----------... | [
"Parameters",
"----------",
"durations",
":",
"an",
"array",
"list",
"pd",
".",
"DataFrame",
"or",
"pd",
".",
"Series",
"length",
"n",
"--",
"duration",
"subject",
"was",
"observed",
"for",
"event_observed",
":",
"an",
"array",
"list",
"pd",
".",
"DataFrame"... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L172-L277 | [
"def",
"_fit",
"(",
"self",
",",
"durations",
",",
"event_observed",
"=",
"None",
",",
"timeline",
"=",
"None",
",",
"entry",
"=",
"None",
",",
"label",
"=",
"\"KM_estimate\"",
",",
"alpha",
"=",
"None",
",",
"ci_labels",
"=",
"None",
",",
"weights",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter.cumulative_density_at_times | Return a Pandas series of the predicted cumulative density at specific times
Parameters
-----------
times: iterable or float
Returns
--------
pd.Series | lifelines/fitters/kaplan_meier_fitter.py | def cumulative_density_at_times(self, times, label=None):
"""
Return a Pandas series of the predicted cumulative density at specific times
Parameters
-----------
times: iterable or float
Returns
--------
pd.Series
"""
label = coalesce(la... | def cumulative_density_at_times(self, times, label=None):
"""
Return a Pandas series of the predicted cumulative density at specific times
Parameters
-----------
times: iterable or float
Returns
--------
pd.Series
"""
label = coalesce(la... | [
"Return",
"a",
"Pandas",
"series",
"of",
"the",
"predicted",
"cumulative",
"density",
"at",
"specific",
"times"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L304-L318 | [
"def",
"cumulative_density_at_times",
"(",
"self",
",",
"times",
",",
"label",
"=",
"None",
")",
":",
"label",
"=",
"coalesce",
"(",
"label",
",",
"self",
".",
"_label",
")",
"return",
"pd",
".",
"Series",
"(",
"1",
"-",
"self",
".",
"predict",
"(",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter.plot_survival_function | Alias of ``plot`` | lifelines/fitters/kaplan_meier_fitter.py | def plot_survival_function(self, **kwargs):
"""Alias of ``plot``"""
return _plot_estimate(
self,
estimate=self.survival_function_,
confidence_intervals=self.confidence_interval_survival_function_,
**kwargs
) | def plot_survival_function(self, **kwargs):
"""Alias of ``plot``"""
return _plot_estimate(
self,
estimate=self.survival_function_,
confidence_intervals=self.confidence_interval_survival_function_,
**kwargs
) | [
"Alias",
"of",
"plot"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L320-L327 | [
"def",
"plot_survival_function",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_plot_estimate",
"(",
"self",
",",
"estimate",
"=",
"self",
".",
"survival_function_",
",",
"confidence_intervals",
"=",
"self",
".",
"confidence_interval_survival_function_"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | KaplanMeierFitter.plot_cumulative_density | Plots a pretty figure of {0}.{1}
Matplotlib plot arguments can be passed in inside the kwargs, plus
Parameters
-----------
show_censors: bool
place markers at censorship events. Default: False
censor_styles: bool
If show_censors, this dictionary will be ... | lifelines/fitters/kaplan_meier_fitter.py | def plot_cumulative_density(self, **kwargs):
"""
Plots a pretty figure of {0}.{1}
Matplotlib plot arguments can be passed in inside the kwargs, plus
Parameters
-----------
show_censors: bool
place markers at censorship events. Default: False
censor_s... | def plot_cumulative_density(self, **kwargs):
"""
Plots a pretty figure of {0}.{1}
Matplotlib plot arguments can be passed in inside the kwargs, plus
Parameters
-----------
show_censors: bool
place markers at censorship events. Default: False
censor_s... | [
"Plots",
"a",
"pretty",
"figure",
"of",
"{",
"0",
"}",
".",
"{",
"1",
"}"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/kaplan_meier_fitter.py#L329-L376 | [
"def",
"plot_cumulative_density",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"_plot_estimate",
"(",
"self",
",",
"estimate",
"=",
"self",
".",
"cumulative_density_",
",",
"confidence_intervals",
"=",
"self",
".",
"confidence_interval_cumulative_densit... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter.fit | Fit the Cox Proportional Hazard model to a time varying dataset. Tied survival times
are handled using Efron's tie-method.
Parameters
-----------
df: DataFrame
a Pandas DataFrame with necessary columns `duration_col` and
`event_col`, plus other covariates. `durati... | lifelines/fitters/cox_time_varying_fitter.py | def fit(
self,
df,
id_col,
event_col,
start_col="start",
stop_col="stop",
weights_col=None,
show_progress=False,
step_size=None,
robust=False,
strata=None,
initial_point=None,
): # pylint: disable=too-many-arguments
... | def fit(
self,
df,
id_col,
event_col,
start_col="start",
stop_col="stop",
weights_col=None,
show_progress=False,
step_size=None,
robust=False,
strata=None,
initial_point=None,
): # pylint: disable=too-many-arguments
... | [
"Fit",
"the",
"Cox",
"Proportional",
"Hazard",
"model",
"to",
"a",
"time",
"varying",
"dataset",
".",
"Tied",
"survival",
"times",
"are",
"handled",
"using",
"Efron",
"s",
"tie",
"-",
"method",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L92-L227 | [
"def",
"fit",
"(",
"self",
",",
"df",
",",
"id_col",
",",
"event_col",
",",
"start_col",
"=",
"\"start\"",
",",
"stop_col",
"=",
"\"stop\"",
",",
"weights_col",
"=",
"None",
",",
"show_progress",
"=",
"False",
",",
"step_size",
"=",
"None",
",",
"robust"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter._newton_rhaphson | Newton Rhaphson algorithm for fitting CPH model.
Parameters
----------
df: DataFrame
stop_times_events: DataFrame
meta information about the subjects history
show_progress: boolean, optional (default: True)
to show verbose output of convergence
s... | lifelines/fitters/cox_time_varying_fitter.py | def _newton_rhaphson(
self,
df,
events,
start,
stop,
weights,
show_progress=False,
step_size=None,
precision=10e-6,
max_steps=50,
initial_point=None,
): # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too... | def _newton_rhaphson(
self,
df,
events,
start,
stop,
weights,
show_progress=False,
step_size=None,
precision=10e-6,
max_steps=50,
initial_point=None,
): # pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too... | [
"Newton",
"Rhaphson",
"algorithm",
"for",
"fitting",
"CPH",
"model",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L296-L462 | [
"def",
"_newton_rhaphson",
"(",
"self",
",",
"df",
",",
"events",
",",
"start",
",",
"stop",
",",
"weights",
",",
"show_progress",
"=",
"False",
",",
"step_size",
"=",
"None",
",",
"precision",
"=",
"10e-6",
",",
"max_steps",
"=",
"50",
",",
"initial_poi... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter._get_gradients | Calculates the first and second order vector differentials, with respect to beta.
Returns
-------
hessian: (d, d) numpy array,
gradient: (d,) numpy array
log_likelihood: float | lifelines/fitters/cox_time_varying_fitter.py | def _get_gradients(self, X, events, start, stop, weights, beta): # pylint: disable=too-many-locals
"""
Calculates the first and second order vector differentials, with respect to beta.
Returns
-------
hessian: (d, d) numpy array,
gradient: (d,) numpy array
log_l... | def _get_gradients(self, X, events, start, stop, weights, beta): # pylint: disable=too-many-locals
"""
Calculates the first and second order vector differentials, with respect to beta.
Returns
-------
hessian: (d, d) numpy array,
gradient: (d,) numpy array
log_l... | [
"Calculates",
"the",
"first",
"and",
"second",
"order",
"vector",
"differentials",
"with",
"respect",
"to",
"beta",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L464-L551 | [
"def",
"_get_gradients",
"(",
"self",
",",
"X",
",",
"events",
",",
"start",
",",
"stop",
",",
"weights",
",",
"beta",
")",
":",
"# pylint: disable=too-many-locals",
"_",
",",
"d",
"=",
"X",
".",
"shape",
"hessian",
"=",
"np",
".",
"zeros",
"(",
"(",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter.predict_log_partial_hazard | r"""
This is equivalent to R's linear.predictors.
Returns the log of the partial hazard for the individuals, partial since the
baseline hazard is not included. Equal to :math:`(x - \bar{x})'\beta `
Parameters
----------
X: numpy array or DataFrame
a (n,d) co... | lifelines/fitters/cox_time_varying_fitter.py | def predict_log_partial_hazard(self, X):
r"""
This is equivalent to R's linear.predictors.
Returns the log of the partial hazard for the individuals, partial since the
baseline hazard is not included. Equal to :math:`(x - \bar{x})'\beta `
Parameters
----------
X... | def predict_log_partial_hazard(self, X):
r"""
This is equivalent to R's linear.predictors.
Returns the log of the partial hazard for the individuals, partial since the
baseline hazard is not included. Equal to :math:`(x - \bar{x})'\beta `
Parameters
----------
X... | [
"r",
"This",
"is",
"equivalent",
"to",
"R",
"s",
"linear",
".",
"predictors",
".",
"Returns",
"the",
"log",
"of",
"the",
"partial",
"hazard",
"for",
"the",
"individuals",
"partial",
"since",
"the",
"baseline",
"hazard",
"is",
"not",
"included",
".",
"Equal... | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L553-L585 | [
"def",
"predict_log_partial_hazard",
"(",
"self",
",",
"X",
")",
":",
"if",
"isinstance",
"(",
"X",
",",
"pd",
".",
"DataFrame",
")",
":",
"order",
"=",
"self",
".",
"hazards_",
".",
"index",
"X",
"=",
"X",
"[",
"order",
"]",
"check_for_numeric_dtypes_or... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter.print_summary | Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
print additional meta data in the output (useful to provide model ... | lifelines/fitters/cox_time_varying_fitter.py | def print_summary(self, decimals=2, **kwargs):
"""
Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
... | def print_summary(self, decimals=2, **kwargs):
"""
Print summary statistics describing the fit, the coefficients, and the error bounds.
Parameters
-----------
decimals: int, optional (default=2)
specify the number of decimal places to show
kwargs:
... | [
"Print",
"summary",
"statistics",
"describing",
"the",
"fit",
"the",
"coefficients",
"and",
"the",
"error",
"bounds",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L612-L668 | [
"def",
"print_summary",
"(",
"self",
",",
"decimals",
"=",
"2",
",",
"*",
"*",
"kwargs",
")",
":",
"# Print information about data first",
"justify",
"=",
"string_justify",
"(",
"18",
")",
"print",
"(",
"self",
")",
"print",
"(",
"\"{} = '{}'\"",
".",
"forma... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter.plot | Produces a visual representation of the coefficients, including their standard errors and magnitudes.
Parameters
----------
columns : list, optional
specify a subset of the columns to plot
errorbar_kwargs:
pass in additional plotting commands to matplotlib errorb... | lifelines/fitters/cox_time_varying_fitter.py | def plot(self, columns=None, **errorbar_kwargs):
"""
Produces a visual representation of the coefficients, including their standard errors and magnitudes.
Parameters
----------
columns : list, optional
specify a subset of the columns to plot
errorbar_kwargs:
... | def plot(self, columns=None, **errorbar_kwargs):
"""
Produces a visual representation of the coefficients, including their standard errors and magnitudes.
Parameters
----------
columns : list, optional
specify a subset of the columns to plot
errorbar_kwargs:
... | [
"Produces",
"a",
"visual",
"representation",
"of",
"the",
"coefficients",
"including",
"their",
"standard",
"errors",
"and",
"magnitudes",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L707-L757 | [
"def",
"plot",
"(",
"self",
",",
"columns",
"=",
"None",
",",
"*",
"*",
"errorbar_kwargs",
")",
":",
"from",
"matplotlib",
"import",
"pyplot",
"as",
"plt",
"ax",
"=",
"errorbar_kwargs",
".",
"pop",
"(",
"\"ax\"",
",",
"None",
")",
"or",
"plt",
".",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxTimeVaryingFitter._compute_delta_beta | approximate change in betas as a result of excluding ith row | lifelines/fitters/cox_time_varying_fitter.py | def _compute_delta_beta(self, df, events, start, stop, weights):
""" approximate change in betas as a result of excluding ith row"""
score_residuals = self._compute_residuals(df, events, start, stop, weights) * weights[:, None]
naive_var = inv(self._hessian_)
delta_betas = -score_resid... | def _compute_delta_beta(self, df, events, start, stop, weights):
""" approximate change in betas as a result of excluding ith row"""
score_residuals = self._compute_residuals(df, events, start, stop, weights) * weights[:, None]
naive_var = inv(self._hessian_)
delta_betas = -score_resid... | [
"approximate",
"change",
"in",
"betas",
"as",
"a",
"result",
"of",
"excluding",
"ith",
"row"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/cox_time_varying_fitter.py#L805-L813 | [
"def",
"_compute_delta_beta",
"(",
"self",
",",
"df",
",",
"events",
",",
"start",
",",
"stop",
",",
"weights",
")",
":",
"score_residuals",
"=",
"self",
".",
"_compute_residuals",
"(",
"df",
",",
"events",
",",
"start",
",",
"stop",
",",
"weights",
")",... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxPHFitter.fit | Fit the Cox proportional hazard model to a dataset.
Parameters
----------
df: DataFrame
a Pandas DataFrame with necessary columns `duration_col` and
`event_col` (see below), covariates columns, and special columns (weights, strata).
`duration_col` refers to
... | lifelines/fitters/coxph_fitter.py | def fit(
self,
df,
duration_col=None,
event_col=None,
show_progress=False,
initial_point=None,
strata=None,
step_size=None,
weights_col=None,
cluster_col=None,
robust=False,
batch_mode=None,
):
"""
Fit th... | def fit(
self,
df,
duration_col=None,
event_col=None,
show_progress=False,
initial_point=None,
strata=None,
step_size=None,
weights_col=None,
cluster_col=None,
robust=False,
batch_mode=None,
):
"""
Fit th... | [
"Fit",
"the",
"Cox",
"proportional",
"hazard",
"model",
"to",
"a",
"dataset",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/coxph_fitter.py#L142-L311 | [
"def",
"fit",
"(",
"self",
",",
"df",
",",
"duration_col",
"=",
"None",
",",
"event_col",
"=",
"None",
",",
"show_progress",
"=",
"False",
",",
"initial_point",
"=",
"None",
",",
"strata",
"=",
"None",
",",
"step_size",
"=",
"None",
",",
"weights_col",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxPHFitter._fit_model | Newton Rhaphson algorithm for fitting CPH model.
Note
----
The data is assumed to be sorted on T!
Parameters
----------
X: (n,d) Pandas DataFrame of observations.
T: (n) Pandas Series representing observed durations.
E: (n) Pandas Series representing dea... | lifelines/fitters/coxph_fitter.py | def _fit_model(
self,
X,
T,
E,
weights=None,
initial_point=None,
step_size=None,
precision=1e-07,
show_progress=True,
max_steps=50,
): # pylint: disable=too-many-statements,too-many-branches
"""
Newton Rhaphson algorith... | def _fit_model(
self,
X,
T,
E,
weights=None,
initial_point=None,
step_size=None,
precision=1e-07,
show_progress=True,
max_steps=50,
): # pylint: disable=too-many-statements,too-many-branches
"""
Newton Rhaphson algorith... | [
"Newton",
"Rhaphson",
"algorithm",
"for",
"fitting",
"CPH",
"model",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/coxph_fitter.py#L371-L559 | [
"def",
"_fit_model",
"(",
"self",
",",
"X",
",",
"T",
",",
"E",
",",
"weights",
"=",
"None",
",",
"initial_point",
"=",
"None",
",",
"step_size",
"=",
"None",
",",
"precision",
"=",
"1e-07",
",",
"show_progress",
"=",
"True",
",",
"max_steps",
"=",
"... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxPHFitter._get_efron_values_single | Calculates the first and second order vector differentials, with respect to beta.
Note that X, T, E are assumed to be sorted on T!
A good explanation for Efron. Consider three of five subjects who fail at the time.
As it is not known a priori that who is the first to fail, so one-third of
... | lifelines/fitters/coxph_fitter.py | def _get_efron_values_single(self, X, T, E, weights, beta):
"""
Calculates the first and second order vector differentials, with respect to beta.
Note that X, T, E are assumed to be sorted on T!
A good explanation for Efron. Consider three of five subjects who fail at the time.
... | def _get_efron_values_single(self, X, T, E, weights, beta):
"""
Calculates the first and second order vector differentials, with respect to beta.
Note that X, T, E are assumed to be sorted on T!
A good explanation for Efron. Consider three of five subjects who fail at the time.
... | [
"Calculates",
"the",
"first",
"and",
"second",
"order",
"vector",
"differentials",
"with",
"respect",
"to",
"beta",
".",
"Note",
"that",
"X",
"T",
"E",
"are",
"assumed",
"to",
"be",
"sorted",
"on",
"T!"
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/coxph_fitter.py#L561-L686 | [
"def",
"_get_efron_values_single",
"(",
"self",
",",
"X",
",",
"T",
",",
"E",
",",
"weights",
",",
"beta",
")",
":",
"n",
",",
"d",
"=",
"X",
".",
"shape",
"hessian",
"=",
"np",
".",
"zeros",
"(",
"(",
"d",
",",
"d",
")",
")",
"gradient",
"=",
... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
train | CoxPHFitter._get_efron_values_batch | Assumes sorted on ascending on T
Calculates the first and second order vector differentials, with respect to beta.
A good explanation for how Efron handles ties. Consider three of five subjects who fail at the time.
As it is not known a priori that who is the first to fail, so one-third of
... | lifelines/fitters/coxph_fitter.py | def _get_efron_values_batch(self, X, T, E, weights, beta): # pylint: disable=too-many-locals
"""
Assumes sorted on ascending on T
Calculates the first and second order vector differentials, with respect to beta.
A good explanation for how Efron handles ties. Consider three of five subj... | def _get_efron_values_batch(self, X, T, E, weights, beta): # pylint: disable=too-many-locals
"""
Assumes sorted on ascending on T
Calculates the first and second order vector differentials, with respect to beta.
A good explanation for how Efron handles ties. Consider three of five subj... | [
"Assumes",
"sorted",
"on",
"ascending",
"on",
"T",
"Calculates",
"the",
"first",
"and",
"second",
"order",
"vector",
"differentials",
"with",
"respect",
"to",
"beta",
"."
] | CamDavidsonPilon/lifelines | python | https://github.com/CamDavidsonPilon/lifelines/blob/bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8/lifelines/fitters/coxph_fitter.py#L784-L891 | [
"def",
"_get_efron_values_batch",
"(",
"self",
",",
"X",
",",
"T",
",",
"E",
",",
"weights",
",",
"beta",
")",
":",
"# pylint: disable=too-many-locals",
"n",
",",
"d",
"=",
"X",
".",
"shape",
"hessian",
"=",
"np",
".",
"zeros",
"(",
"(",
"d",
",",
"d... | bdf6be6f1d10eea4c46365ee0ee6a47d8c30edf8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.