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
get_factors
[summary] Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors of the number n]
algorithms/dfs/all_factors.py
def get_factors(n): """[summary] Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors of the number n] """ def factor(n, i, combi, res): """[summary] helper function Arguments: n {[int]} -- [number] ...
def get_factors(n): """[summary] Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors of the number n] """ def factor(n, i, combi, res): """[summary] helper function Arguments: n {[int]} -- [number] ...
[ "[", "summary", "]", "Arguments", ":", "n", "{", "[", "int", "]", "}", "--", "[", "to", "analysed", "number", "]", "Returns", ":", "[", "list", "of", "lists", "]", "--", "[", "all", "factors", "of", "the", "number", "n", "]" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/dfs/all_factors.py#L30-L60
[ "def", "get_factors", "(", "n", ")", ":", "def", "factor", "(", "n", ",", "i", ",", "combi", ",", "res", ")", ":", "\"\"\"[summary]\n helper function\n\n Arguments:\n n {[int]} -- [number]\n i {[int]} -- [to tested divisor]\n combi {...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
get_factors_iterative1
[summary] Computes all factors of n. Translated the function get_factors(...) in a call-stack modell. Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors]
algorithms/dfs/all_factors.py
def get_factors_iterative1(n): """[summary] Computes all factors of n. Translated the function get_factors(...) in a call-stack modell. Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors] """ todo, res = [(n, 2, [])], [] while...
def get_factors_iterative1(n): """[summary] Computes all factors of n. Translated the function get_factors(...) in a call-stack modell. Arguments: n {[int]} -- [to analysed number] Returns: [list of lists] -- [all factors] """ todo, res = [(n, 2, [])], [] while...
[ "[", "summary", "]", "Computes", "all", "factors", "of", "n", ".", "Translated", "the", "function", "get_factors", "(", "...", ")", "in", "a", "call", "-", "stack", "modell", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/dfs/all_factors.py#L63-L84
[ "def", "get_factors_iterative1", "(", "n", ")", ":", "todo", ",", "res", "=", "[", "(", "n", ",", "2", ",", "[", "]", ")", "]", ",", "[", "]", "while", "todo", ":", "n", ",", "i", ",", "combi", "=", "todo", ".", "pop", "(", ")", "while", "i...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
get_factors_iterative2
[summary] analog as above Arguments: n {[int]} -- [description] Returns: [list of lists] -- [all factors of n]
algorithms/dfs/all_factors.py
def get_factors_iterative2(n): """[summary] analog as above Arguments: n {[int]} -- [description] Returns: [list of lists] -- [all factors of n] """ ans, stack, x = [], [], 2 while True: if x > n // x: if not stack: return ans ...
def get_factors_iterative2(n): """[summary] analog as above Arguments: n {[int]} -- [description] Returns: [list of lists] -- [all factors of n] """ ans, stack, x = [], [], 2 while True: if x > n // x: if not stack: return ans ...
[ "[", "summary", "]", "analog", "as", "above" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/dfs/all_factors.py#L87-L111
[ "def", "get_factors_iterative2", "(", "n", ")", ":", "ans", ",", "stack", ",", "x", "=", "[", "]", ",", "[", "]", ",", "2", "while", "True", ":", "if", "x", ">", "n", "//", "x", ":", "if", "not", "stack", ":", "return", "ans", "ans", ".", "ap...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
longest_increasing_subsequence
Dynamic Programming Algorithm for counting the length of longest increasing subsequence type sequence: List[int]
algorithms/dp/longest_increasing.py
def longest_increasing_subsequence(sequence): """ Dynamic Programming Algorithm for counting the length of longest increasing subsequence type sequence: List[int] """ length = len(sequence) counts = [1 for _ in range(length)] for i in range(1, length): for j in range(0, i): ...
def longest_increasing_subsequence(sequence): """ Dynamic Programming Algorithm for counting the length of longest increasing subsequence type sequence: List[int] """ length = len(sequence) counts = [1 for _ in range(length)] for i in range(1, length): for j in range(0, i): ...
[ "Dynamic", "Programming", "Algorithm", "for", "counting", "the", "length", "of", "longest", "increasing", "subsequence", "type", "sequence", ":", "List", "[", "int", "]" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/dp/longest_increasing.py#L13-L26
[ "def", "longest_increasing_subsequence", "(", "sequence", ")", ":", "length", "=", "len", "(", "sequence", ")", "counts", "=", "[", "1", "for", "_", "in", "range", "(", "length", ")", "]", "for", "i", "in", "range", "(", "1", ",", "length", ")", ":",...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
single_number3
:type nums: List[int] :rtype: List[int]
algorithms/bit/single_number3.py
def single_number3(nums): """ :type nums: List[int] :rtype: List[int] """ # isolate a^b from pairs using XOR ab = 0 for n in nums: ab ^= n # isolate right most bit from a^b right_most = ab & (-ab) # isolate a and b from a^b a, b = 0, 0 for n in nums: if ...
def single_number3(nums): """ :type nums: List[int] :rtype: List[int] """ # isolate a^b from pairs using XOR ab = 0 for n in nums: ab ^= n # isolate right most bit from a^b right_most = ab & (-ab) # isolate a and b from a^b a, b = 0, 0 for n in nums: if ...
[ ":", "type", "nums", ":", "List", "[", "int", "]", ":", "rtype", ":", "List", "[", "int", "]" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/bit/single_number3.py#L29-L49
[ "def", "single_number3", "(", "nums", ")", ":", "# isolate a^b from pairs using XOR", "ab", "=", "0", "for", "n", "in", "nums", ":", "ab", "^=", "n", "# isolate right most bit from a^b", "right_most", "=", "ab", "&", "(", "-", "ab", ")", "# isolate a and b from ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
distance
[summary] HELPER-FUNCTION calculates the (eulidean) distance between vector x and y. Arguments: x {[tuple]} -- [vector] y {[tuple]} -- [vector]
algorithms/ml/nearest_neighbor.py
def distance(x,y): """[summary] HELPER-FUNCTION calculates the (eulidean) distance between vector x and y. Arguments: x {[tuple]} -- [vector] y {[tuple]} -- [vector] """ assert len(x) == len(y), "The vector must have same length" result = () sum = 0 for i in range(le...
def distance(x,y): """[summary] HELPER-FUNCTION calculates the (eulidean) distance between vector x and y. Arguments: x {[tuple]} -- [vector] y {[tuple]} -- [vector] """ assert len(x) == len(y), "The vector must have same length" result = () sum = 0 for i in range(le...
[ "[", "summary", "]", "HELPER", "-", "FUNCTION", "calculates", "the", "(", "eulidean", ")", "distance", "between", "vector", "x", "and", "y", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/ml/nearest_neighbor.py#L3-L19
[ "def", "distance", "(", "x", ",", "y", ")", ":", "assert", "len", "(", "x", ")", "==", "len", "(", "y", ")", ",", "\"The vector must have same length\"", "result", "=", "(", ")", "sum", "=", "0", "for", "i", "in", "range", "(", "len", "(", "x", "...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
nearest_neighbor
[summary] Implements the nearest neighbor algorithm Arguments: x {[tupel]} -- [vector] tSet {[dict]} -- [training set] Returns: [type] -- [result of the AND-function]
algorithms/ml/nearest_neighbor.py
def nearest_neighbor(x, tSet): """[summary] Implements the nearest neighbor algorithm Arguments: x {[tupel]} -- [vector] tSet {[dict]} -- [training set] Returns: [type] -- [result of the AND-function] """ assert isinstance(x, tuple) and isinstance(tSet, dict) curren...
def nearest_neighbor(x, tSet): """[summary] Implements the nearest neighbor algorithm Arguments: x {[tupel]} -- [vector] tSet {[dict]} -- [training set] Returns: [type] -- [result of the AND-function] """ assert isinstance(x, tuple) and isinstance(tSet, dict) curren...
[ "[", "summary", "]", "Implements", "the", "nearest", "neighbor", "algorithm" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/ml/nearest_neighbor.py#L22-L41
[ "def", "nearest_neighbor", "(", "x", ",", "tSet", ")", ":", "assert", "isinstance", "(", "x", ",", "tuple", ")", "and", "isinstance", "(", "tSet", ",", "dict", ")", "current_key", "=", "(", ")", "min_d", "=", "float", "(", "'inf'", ")", "for", "key",...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
is_strobogrammatic
:type num: str :rtype: bool
algorithms/maths/is_strobogrammatic.py
def is_strobogrammatic(num): """ :type num: str :rtype: bool """ comb = "00 11 88 69 96" i = 0 j = len(num) - 1 while i <= j: x = comb.find(num[i]+num[j]) if x == -1: return False i += 1 j -= 1 return True
def is_strobogrammatic(num): """ :type num: str :rtype: bool """ comb = "00 11 88 69 96" i = 0 j = len(num) - 1 while i <= j: x = comb.find(num[i]+num[j]) if x == -1: return False i += 1 j -= 1 return True
[ ":", "type", "num", ":", "str", ":", "rtype", ":", "bool" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/is_strobogrammatic.py#L12-L26
[ "def", "is_strobogrammatic", "(", "num", ")", ":", "comb", "=", "\"00 11 88 69 96\"", "i", "=", "0", "j", "=", "len", "(", "num", ")", "-", "1", "while", "i", "<=", "j", ":", "x", "=", "comb", ".", "find", "(", "num", "[", "i", "]", "+", "num",...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
merge_sort
Merge Sort Complexity: O(n log(n))
algorithms/sort/merge_sort.py
def merge_sort(arr): """ Merge Sort Complexity: O(n log(n)) """ # Our recursive base case if len(arr) <= 1: return arr mid = len(arr) // 2 # Perform merge_sort recursively on both halves left, right = merge_sort(arr[:mid]), merge_sort(arr[mid:]) # Merge each side togethe...
def merge_sort(arr): """ Merge Sort Complexity: O(n log(n)) """ # Our recursive base case if len(arr) <= 1: return arr mid = len(arr) // 2 # Perform merge_sort recursively on both halves left, right = merge_sort(arr[:mid]), merge_sort(arr[mid:]) # Merge each side togethe...
[ "Merge", "Sort", "Complexity", ":", "O", "(", "n", "log", "(", "n", "))" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/merge_sort.py#L1-L13
[ "def", "merge_sort", "(", "arr", ")", ":", "# Our recursive base case", "if", "len", "(", "arr", ")", "<=", "1", ":", "return", "arr", "mid", "=", "len", "(", "arr", ")", "//", "2", "# Perform merge_sort recursively on both halves", "left", ",", "right", "="...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
merge
Merge helper Complexity: O(n)
algorithms/sort/merge_sort.py
def merge(left, right, merged): """ Merge helper Complexity: O(n) """ left_cursor, right_cursor = 0, 0 while left_cursor < len(left) and right_cursor < len(right): # Sort each one and place into the result if left[left_cursor] <= right[right_cursor]: merged[left_curs...
def merge(left, right, merged): """ Merge helper Complexity: O(n) """ left_cursor, right_cursor = 0, 0 while left_cursor < len(left) and right_cursor < len(right): # Sort each one and place into the result if left[left_cursor] <= right[right_cursor]: merged[left_curs...
[ "Merge", "helper", "Complexity", ":", "O", "(", "n", ")" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/merge_sort.py#L16-L38
[ "def", "merge", "(", "left", ",", "right", ",", "merged", ")", ":", "left_cursor", ",", "right_cursor", "=", "0", ",", "0", "while", "left_cursor", "<", "len", "(", "left", ")", "and", "right_cursor", "<", "len", "(", "right", ")", ":", "# Sort each on...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
bucket_sort
Bucket Sort Complexity: O(n^2) The complexity is dominated by nextSort
algorithms/sort/bucket_sort.py
def bucket_sort(arr): ''' Bucket Sort Complexity: O(n^2) The complexity is dominated by nextSort ''' # The number of buckets and make buckets num_buckets = len(arr) buckets = [[] for bucket in range(num_buckets)] # Assign values into bucket_sort for value in arr: inde...
def bucket_sort(arr): ''' Bucket Sort Complexity: O(n^2) The complexity is dominated by nextSort ''' # The number of buckets and make buckets num_buckets = len(arr) buckets = [[] for bucket in range(num_buckets)] # Assign values into bucket_sort for value in arr: inde...
[ "Bucket", "Sort", "Complexity", ":", "O", "(", "n^2", ")", "The", "complexity", "is", "dominated", "by", "nextSort" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/sort/bucket_sort.py#L1-L17
[ "def", "bucket_sort", "(", "arr", ")", ":", "# The number of buckets and make buckets", "num_buckets", "=", "len", "(", "arr", ")", "buckets", "=", "[", "[", "]", "for", "bucket", "in", "range", "(", "num_buckets", ")", "]", "# Assign values into bucket_sort", "...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
k_closest
Initialize max heap with first k points. Python does not support a max heap; thus we can use the default min heap where the keys (distance) are negated.
algorithms/heap/k_closest_points.py
def k_closest(points, k, origin=(0, 0)): # Time: O(k+(n-k)logk) # Space: O(k) """Initialize max heap with first k points. Python does not support a max heap; thus we can use the default min heap where the keys (distance) are negated. """ heap = [(-distance(p, origin), p) for p in points[:k]] ...
def k_closest(points, k, origin=(0, 0)): # Time: O(k+(n-k)logk) # Space: O(k) """Initialize max heap with first k points. Python does not support a max heap; thus we can use the default min heap where the keys (distance) are negated. """ heap = [(-distance(p, origin), p) for p in points[:k]] ...
[ "Initialize", "max", "heap", "with", "first", "k", "points", ".", "Python", "does", "not", "support", "a", "max", "heap", ";", "thus", "we", "can", "use", "the", "default", "min", "heap", "where", "the", "keys", "(", "distance", ")", "are", "negated", ...
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/heap/k_closest_points.py#L13-L40
[ "def", "k_closest", "(", "points", ",", "k", ",", "origin", "=", "(", "0", ",", "0", ")", ")", ":", "# Time: O(k+(n-k)logk)", "# Space: O(k)", "heap", "=", "[", "(", "-", "distance", "(", "p", ",", "origin", ")", ",", "p", ")", "for", "p", "in", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
reverse_list
:type head: ListNode :rtype: ListNode
algorithms/linkedlist/reverse.py
def reverse_list(head): """ :type head: ListNode :rtype: ListNode """ if not head or not head.next: return head prev = None while head: current = head head = head.next current.next = prev prev = current return prev
def reverse_list(head): """ :type head: ListNode :rtype: ListNode """ if not head or not head.next: return head prev = None while head: current = head head = head.next current.next = prev prev = current return prev
[ ":", "type", "head", ":", "ListNode", ":", "rtype", ":", "ListNode" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/reverse.py#L12-L25
[ "def", "reverse_list", "(", "head", ")", ":", "if", "not", "head", "or", "not", "head", ".", "next", ":", "return", "head", "prev", "=", "None", "while", "head", ":", "current", "=", "head", "head", "=", "head", ".", "next", "current", ".", "next", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
reverse_list_recursive
:type head: ListNode :rtype: ListNode
algorithms/linkedlist/reverse.py
def reverse_list_recursive(head): """ :type head: ListNode :rtype: ListNode """ if head is None or head.next is None: return head p = head.next head.next = None revrest = reverse_list_recursive(p) p.next = head return revrest
def reverse_list_recursive(head): """ :type head: ListNode :rtype: ListNode """ if head is None or head.next is None: return head p = head.next head.next = None revrest = reverse_list_recursive(p) p.next = head return revrest
[ ":", "type", "head", ":", "ListNode", ":", "rtype", ":", "ListNode" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/reverse.py#L32-L43
[ "def", "reverse_list_recursive", "(", "head", ")", ":", "if", "head", "is", "None", "or", "head", ".", "next", "is", "None", ":", "return", "head", "p", "=", "head", ".", "next", "head", ".", "next", "=", "None", "revrest", "=", "reverse_list_recursive",...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
has_path_sum
:type root: TreeNode :type sum: int :rtype: bool
algorithms/tree/path_sum.py
def has_path_sum(root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if root is None: return False if root.left is None and root.right is None and root.val == sum: return True sum -= root.val return has_path_sum(root.left, sum) or has_path_sum(root.ri...
def has_path_sum(root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if root is None: return False if root.left is None and root.right is None and root.val == sum: return True sum -= root.val return has_path_sum(root.left, sum) or has_path_sum(root.ri...
[ ":", "type", "root", ":", "TreeNode", ":", "type", "sum", ":", "int", ":", "rtype", ":", "bool" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/path_sum.py#L18-L29
[ "def", "has_path_sum", "(", "root", ",", "sum", ")", ":", "if", "root", "is", "None", ":", "return", "False", "if", "root", ".", "left", "is", "None", "and", "root", ".", "right", "is", "None", "and", "root", ".", "val", "==", "sum", ":", "return",...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
int_to_base
:type n: int :type base: int :rtype: str
algorithms/maths/base_conversion.py
def int_to_base(n, base): """ :type n: int :type base: int :rtype: str """ is_negative = False if n == 0: return '0' elif n < 0: is_negative = True n *= -1 digit = string.digits + string.ascii_uppercase res = '' while n > 0: res += ...
def int_to_base(n, base): """ :type n: int :type base: int :rtype: str """ is_negative = False if n == 0: return '0' elif n < 0: is_negative = True n *= -1 digit = string.digits + string.ascii_uppercase res = '' while n > 0: res += ...
[ ":", "type", "n", ":", "int", ":", "type", "base", ":", "int", ":", "rtype", ":", "str" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/base_conversion.py#L11-L31
[ "def", "int_to_base", "(", "n", ",", "base", ")", ":", "is_negative", "=", "False", "if", "n", "==", "0", ":", "return", "'0'", "elif", "n", "<", "0", ":", "is_negative", "=", "True", "n", "*=", "-", "1", "digit", "=", "string", ".", "digits", "+...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
base_to_int
Note : You can use int() built-in function instread of this. :type s: str :type base: int :rtype: int
algorithms/maths/base_conversion.py
def base_to_int(s, base): """ Note : You can use int() built-in function instread of this. :type s: str :type base: int :rtype: int """ digit = {} for i,c in enumerate(string.digits + string.ascii_uppercase): digit[c] = i multiplier = 1 res = 0 fo...
def base_to_int(s, base): """ Note : You can use int() built-in function instread of this. :type s: str :type base: int :rtype: int """ digit = {} for i,c in enumerate(string.digits + string.ascii_uppercase): digit[c] = i multiplier = 1 res = 0 fo...
[ "Note", ":", "You", "can", "use", "int", "()", "built", "-", "in", "function", "instread", "of", "this", ".", ":", "type", "s", ":", "str", ":", "type", "base", ":", "int", ":", "rtype", ":", "int" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/base_conversion.py#L34-L50
[ "def", "base_to_int", "(", "s", ",", "base", ")", ":", "digit", "=", "{", "}", "for", "i", ",", "c", "in", "enumerate", "(", "string", ".", "digits", "+", "string", ".", "ascii_uppercase", ")", ":", "digit", "[", "c", "]", "=", "i", "multiplier", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
is_cyclic
:type head: Node :rtype: bool
algorithms/linkedlist/is_cyclic.py
def is_cyclic(head): """ :type head: Node :rtype: bool """ if not head: return False runner = head walker = head while runner.next and runner.next.next: runner = runner.next.next walker = walker.next if runner == walker: return True return ...
def is_cyclic(head): """ :type head: Node :rtype: bool """ if not head: return False runner = head walker = head while runner.next and runner.next.next: runner = runner.next.next walker = walker.next if runner == walker: return True return ...
[ ":", "type", "head", ":", "Node", ":", "rtype", ":", "bool" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/linkedlist/is_cyclic.py#L13-L27
[ "def", "is_cyclic", "(", "head", ")", ":", "if", "not", "head", ":", "return", "False", "runner", "=", "head", "walker", "=", "head", "while", "runner", ".", "next", "and", "runner", ".", "next", ".", "next", ":", "runner", "=", "runner", ".", "next"...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
decode_string
:type s: str :rtype: str
algorithms/strings/decode_string.py
def decode_string(s): """ :type s: str :rtype: str """ stack = []; cur_num = 0; cur_string = '' for c in s: if c == '[': stack.append((cur_string, cur_num)) cur_string = '' cur_num = 0 elif c == ']': prev_string, num = stack.pop() ...
def decode_string(s): """ :type s: str :rtype: str """ stack = []; cur_num = 0; cur_string = '' for c in s: if c == '[': stack.append((cur_string, cur_num)) cur_string = '' cur_num = 0 elif c == ']': prev_string, num = stack.pop() ...
[ ":", "type", "s", ":", "str", ":", "rtype", ":", "str" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/strings/decode_string.py#L20-L38
[ "def", "decode_string", "(", "s", ")", ":", "stack", "=", "[", "]", "cur_num", "=", "0", "cur_string", "=", "''", "for", "c", "in", "s", ":", "if", "c", "==", "'['", ":", "stack", ".", "append", "(", "(", "cur_string", ",", "cur_num", ")", ")", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
palindromic_substrings_iter
A slightly more Pythonic approach with a recursive generator
algorithms/backtrack/palindrome_partitioning.py
def palindromic_substrings_iter(s): """ A slightly more Pythonic approach with a recursive generator """ if not s: yield [] return for i in range(len(s), 0, -1): sub = s[:i] if sub == sub[::-1]: for rest in palindromic_substrings_iter(s[i:]): ...
def palindromic_substrings_iter(s): """ A slightly more Pythonic approach with a recursive generator """ if not s: yield [] return for i in range(len(s), 0, -1): sub = s[:i] if sub == sub[::-1]: for rest in palindromic_substrings_iter(s[i:]): ...
[ "A", "slightly", "more", "Pythonic", "approach", "with", "a", "recursive", "generator" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/palindrome_partitioning.py#L34-L45
[ "def", "palindromic_substrings_iter", "(", "s", ")", ":", "if", "not", "s", ":", "yield", "[", "]", "return", "for", "i", "in", "range", "(", "len", "(", "s", ")", ",", "0", ",", "-", "1", ")", ":", "sub", "=", "s", "[", ":", "i", "]", "if", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
is_isomorphic
:type s: str :type t: str :rtype: bool
algorithms/map/is_isomorphic.py
def is_isomorphic(s, t): """ :type s: str :type t: str :rtype: bool """ if len(s) != len(t): return False dict = {} set_value = set() for i in range(len(s)): if s[i] not in dict: if t[i] in set_value: return False dict[s[i]] = t...
def is_isomorphic(s, t): """ :type s: str :type t: str :rtype: bool """ if len(s) != len(t): return False dict = {} set_value = set() for i in range(len(s)): if s[i] not in dict: if t[i] in set_value: return False dict[s[i]] = t...
[ ":", "type", "s", ":", "str", ":", "type", "t", ":", "str", ":", "rtype", ":", "bool" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/map/is_isomorphic.py#L21-L40
[ "def", "is_isomorphic", "(", "s", ",", "t", ")", ":", "if", "len", "(", "s", ")", "!=", "len", "(", "t", ")", ":", "return", "False", "dict", "=", "{", "}", "set_value", "=", "set", "(", ")", "for", "i", "in", "range", "(", "len", "(", "s", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
calc
Calculate operation result n2 Number: Number 2 n1 Number: Number 1 operator Char: Operation to calculate
algorithms/calculator/math_parser.py
def calc(n2, n1, operator): """ Calculate operation result n2 Number: Number 2 n1 Number: Number 1 operator Char: Operation to calculate """ if operator == '-': return n1 - n2 elif operator == '+': return n1 + n2 elif operator == '*': return n1 * n2 elif operator == '...
def calc(n2, n1, operator): """ Calculate operation result n2 Number: Number 2 n1 Number: Number 1 operator Char: Operation to calculate """ if operator == '-': return n1 - n2 elif operator == '+': return n1 + n2 elif operator == '*': return n1 * n2 elif operator == '...
[ "Calculate", "operation", "result", "n2", "Number", ":", "Number", "2", "n1", "Number", ":", "Number", "1", "operator", "Char", ":", "Operation", "to", "calculate" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L53-L66
[ "def", "calc", "(", "n2", ",", "n1", ",", "operator", ")", ":", "if", "operator", "==", "'-'", ":", "return", "n1", "-", "n2", "elif", "operator", "==", "'+'", ":", "return", "n1", "+", "n2", "elif", "operator", "==", "'*'", ":", "return", "n1", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
apply_operation
Apply operation to the first 2 items of the output queue op_stack Deque (reference) out_stack Deque (reference)
algorithms/calculator/math_parser.py
def apply_operation(op_stack, out_stack): """ Apply operation to the first 2 items of the output queue op_stack Deque (reference) out_stack Deque (reference) """ out_stack.append(calc(out_stack.pop(), out_stack.pop(), op_stack.pop()))
def apply_operation(op_stack, out_stack): """ Apply operation to the first 2 items of the output queue op_stack Deque (reference) out_stack Deque (reference) """ out_stack.append(calc(out_stack.pop(), out_stack.pop(), op_stack.pop()))
[ "Apply", "operation", "to", "the", "first", "2", "items", "of", "the", "output", "queue", "op_stack", "Deque", "(", "reference", ")", "out_stack", "Deque", "(", "reference", ")" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L68-L75
[ "def", "apply_operation", "(", "op_stack", ",", "out_stack", ")", ":", "out_stack", ".", "append", "(", "calc", "(", "out_stack", ".", "pop", "(", ")", ",", "out_stack", ".", "pop", "(", ")", ",", "op_stack", ".", "pop", "(", ")", ")", ")" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
parse
Return array of parsed tokens in the expression expression String: Math expression to parse in infix notation
algorithms/calculator/math_parser.py
def parse(expression): """ Return array of parsed tokens in the expression expression String: Math expression to parse in infix notation """ result = [] current = "" for i in expression: if i.isdigit() or i == '.': current += i else: if le...
def parse(expression): """ Return array of parsed tokens in the expression expression String: Math expression to parse in infix notation """ result = [] current = "" for i in expression: if i.isdigit() or i == '.': current += i else: if le...
[ "Return", "array", "of", "parsed", "tokens", "in", "the", "expression", "expression", "String", ":", "Math", "expression", "to", "parse", "in", "infix", "notation" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L77-L99
[ "def", "parse", "(", "expression", ")", ":", "result", "=", "[", "]", "current", "=", "\"\"", "for", "i", "in", "expression", ":", "if", "i", ".", "isdigit", "(", ")", "or", "i", "==", "'.'", ":", "current", "+=", "i", "else", ":", "if", "len", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
evaluate
Calculate result of expression expression String: The expression type Type (optional): Number type [int, float]
algorithms/calculator/math_parser.py
def evaluate(expression): """ Calculate result of expression expression String: The expression type Type (optional): Number type [int, float] """ op_stack = deque() # operator stack out_stack = deque() # output stack (values) tokens = parse(expression) # calls the function onl...
def evaluate(expression): """ Calculate result of expression expression String: The expression type Type (optional): Number type [int, float] """ op_stack = deque() # operator stack out_stack = deque() # output stack (values) tokens = parse(expression) # calls the function onl...
[ "Calculate", "result", "of", "expression", "expression", "String", ":", "The", "expression", "type", "Type", "(", "optional", ")", ":", "Number", "type", "[", "int", "float", "]" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L101-L128
[ "def", "evaluate", "(", "expression", ")", ":", "op_stack", "=", "deque", "(", ")", "# operator stack\r", "out_stack", "=", "deque", "(", ")", "# output stack (values)\r", "tokens", "=", "parse", "(", "expression", ")", "# calls the function only once!\r", "for", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
main
simple user-interface
algorithms/calculator/math_parser.py
def main(): """ simple user-interface """ print("\t\tCalculator\n\n") while True: user_input = input("expression or exit: ") if user_input == "exit": break try: print("The result is {0}".format(evaluate(user_input))) except Excep...
def main(): """ simple user-interface """ print("\t\tCalculator\n\n") while True: user_input = input("expression or exit: ") if user_input == "exit": break try: print("The result is {0}".format(evaluate(user_input))) except Excep...
[ "simple", "user", "-", "interface" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/calculator/math_parser.py#L131-L145
[ "def", "main", "(", ")", ":", "print", "(", "\"\\t\\tCalculator\\n\\n\"", ")", "while", "True", ":", "user_input", "=", "input", "(", "\"expression or exit: \"", ")", "if", "user_input", "==", "\"exit\"", ":", "break", "try", ":", "print", "(", "\"The result i...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
closest_value
:type root: TreeNode :type target: float :rtype: int
algorithms/tree/bst/bst_closest_value.py
def closest_value(root, target): """ :type root: TreeNode :type target: float :rtype: int """ a = root.val kid = root.left if target < a else root.right if not kid: return a b = closest_value(kid, target) return min((a,b), key=lambda x: abs(target-x))
def closest_value(root, target): """ :type root: TreeNode :type target: float :rtype: int """ a = root.val kid = root.left if target < a else root.right if not kid: return a b = closest_value(kid, target) return min((a,b), key=lambda x: abs(target-x))
[ ":", "type", "root", ":", "TreeNode", ":", "type", "target", ":", "float", ":", "rtype", ":", "int" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/bst/bst_closest_value.py#L17-L28
[ "def", "closest_value", "(", "root", ",", "target", ")", ":", "a", "=", "root", ".", "val", "kid", "=", "root", ".", "left", "if", "target", "<", "a", "else", "root", ".", "right", "if", "not", "kid", ":", "return", "a", "b", "=", "closest_value", ...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
get_primes
Return list of all primes less than n, Using sieve of Eratosthenes.
algorithms/maths/primes_sieve_of_eratosthenes.py
def get_primes(n): """Return list of all primes less than n, Using sieve of Eratosthenes. """ if n <= 0: raise ValueError("'n' must be a positive integer.") # If x is even, exclude x from list (-1): sieve_size = (n // 2 - 1) if n % 2 == 0 else (n // 2) sieve = [True for _ in range(si...
def get_primes(n): """Return list of all primes less than n, Using sieve of Eratosthenes. """ if n <= 0: raise ValueError("'n' must be a positive integer.") # If x is even, exclude x from list (-1): sieve_size = (n // 2 - 1) if n % 2 == 0 else (n // 2) sieve = [True for _ in range(si...
[ "Return", "list", "of", "all", "primes", "less", "than", "n", "Using", "sieve", "of", "Eratosthenes", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/primes_sieve_of_eratosthenes.py#L28-L46
[ "def", "get_primes", "(", "n", ")", ":", "if", "n", "<=", "0", ":", "raise", "ValueError", "(", "\"'n' must be a positive integer.\"", ")", "# If x is even, exclude x from list (-1):", "sieve_size", "=", "(", "n", "//", "2", "-", "1", ")", "if", "n", "%", "2...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
permute
returns a list with the permuations.
algorithms/backtrack/permute.py
def permute(elements): """ returns a list with the permuations. """ if len(elements) <= 1: return [elements] else: tmp = [] for perm in permute(elements[1:]): for i in range(len(elements)): tmp.append(perm[:i] + elements[0:1] + perm[i:]) ...
def permute(elements): """ returns a list with the permuations. """ if len(elements) <= 1: return [elements] else: tmp = [] for perm in permute(elements[1:]): for i in range(len(elements)): tmp.append(perm[:i] + elements[0:1] + perm[i:]) ...
[ "returns", "a", "list", "with", "the", "permuations", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/permute.py#L17-L28
[ "def", "permute", "(", "elements", ")", ":", "if", "len", "(", "elements", ")", "<=", "1", ":", "return", "[", "elements", "]", "else", ":", "tmp", "=", "[", "]", "for", "perm", "in", "permute", "(", "elements", "[", "1", ":", "]", ")", ":", "f...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
permute_iter
iterator: returns a perumation by each call.
algorithms/backtrack/permute.py
def permute_iter(elements): """ iterator: returns a perumation by each call. """ if len(elements) <= 1: yield elements else: for perm in permute_iter(elements[1:]): for i in range(len(elements)): yield perm[:i] + elements[0:1] + perm[i:]
def permute_iter(elements): """ iterator: returns a perumation by each call. """ if len(elements) <= 1: yield elements else: for perm in permute_iter(elements[1:]): for i in range(len(elements)): yield perm[:i] + elements[0:1] + perm[i:]
[ "iterator", ":", "returns", "a", "perumation", "by", "each", "call", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/permute.py#L31-L40
[ "def", "permute_iter", "(", "elements", ")", ":", "if", "len", "(", "elements", ")", "<=", "1", ":", "yield", "elements", "else", ":", "for", "perm", "in", "permute_iter", "(", "elements", "[", "1", ":", "]", ")", ":", "for", "i", "in", "range", "(...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
extended_gcd
Extended GCD algorithm. Return s, t, g such that a * s + b * t = GCD(a, b) and s and t are co-prime.
algorithms/maths/extended_gcd.py
def extended_gcd(a, b): """Extended GCD algorithm. Return s, t, g such that a * s + b * t = GCD(a, b) and s and t are co-prime. """ old_s, s = 1, 0 old_t, t = 0, 1 old_r, r = a, b while r != 0: quotient = old_r / r old_r, r = r, old_r - quotient * r ...
def extended_gcd(a, b): """Extended GCD algorithm. Return s, t, g such that a * s + b * t = GCD(a, b) and s and t are co-prime. """ old_s, s = 1, 0 old_t, t = 0, 1 old_r, r = a, b while r != 0: quotient = old_r / r old_r, r = r, old_r - quotient * r ...
[ "Extended", "GCD", "algorithm", ".", "Return", "s", "t", "g", "such", "that", "a", "*", "s", "+", "b", "*", "t", "=", "GCD", "(", "a", "b", ")", "and", "s", "and", "t", "are", "co", "-", "prime", "." ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/maths/extended_gcd.py#L1-L19
[ "def", "extended_gcd", "(", "a", ",", "b", ")", ":", "old_s", ",", "s", "=", "1", ",", "0", "old_t", ",", "t", "=", "0", ",", "1", "old_r", ",", "r", "=", "a", ",", "b", "while", "r", "!=", "0", ":", "quotient", "=", "old_r", "/", "r", "o...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
bin_tree_to_list
type root: root class
algorithms/tree/bin_tree_to_list.py
def bin_tree_to_list(root): """ type root: root class """ if not root: return root root = bin_tree_to_list_util(root) while root.left: root = root.left return root
def bin_tree_to_list(root): """ type root: root class """ if not root: return root root = bin_tree_to_list_util(root) while root.left: root = root.left return root
[ "type", "root", ":", "root", "class" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/tree/bin_tree_to_list.py#L4-L13
[ "def", "bin_tree_to_list", "(", "root", ")", ":", "if", "not", "root", ":", "return", "root", "root", "=", "bin_tree_to_list_util", "(", "root", ")", "while", "root", ".", "left", ":", "root", "=", "root", ".", "left", "return", "root" ]
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
add_operators
:type num: str :type target: int :rtype: List[str]
algorithms/backtrack/add_operators.py
def add_operators(num, target): """ :type num: str :type target: int :rtype: List[str] """ def dfs(res, path, num, target, pos, prev, multed): if pos == len(num): if target == prev: res.append(path) return for i in range(pos, len(num)): ...
def add_operators(num, target): """ :type num: str :type target: int :rtype: List[str] """ def dfs(res, path, num, target, pos, prev, multed): if pos == len(num): if target == prev: res.append(path) return for i in range(pos, len(num)): ...
[ ":", "type", "num", ":", "str", ":", "type", "target", ":", "int", ":", "rtype", ":", "List", "[", "str", "]" ]
keon/algorithms
python
https://github.com/keon/algorithms/blob/4d6569464a62a75c1357acc97e2dd32ee2f9f4a3/algorithms/backtrack/add_operators.py#L15-L45
[ "def", "add_operators", "(", "num", ",", "target", ")", ":", "def", "dfs", "(", "res", ",", "path", ",", "num", ",", "target", ",", "pos", ",", "prev", ",", "multed", ")", ":", "if", "pos", "==", "len", "(", "num", ")", ":", "if", "target", "==...
4d6569464a62a75c1357acc97e2dd32ee2f9f4a3
train
_init_rabit
internal library initializer.
python-package/xgboost/rabit.py
def _init_rabit(): """internal library initializer.""" if _LIB is not None: _LIB.RabitGetRank.restype = ctypes.c_int _LIB.RabitGetWorldSize.restype = ctypes.c_int _LIB.RabitIsDistributed.restype = ctypes.c_int _LIB.RabitVersionNumber.restype = ctypes.c_int
def _init_rabit(): """internal library initializer.""" if _LIB is not None: _LIB.RabitGetRank.restype = ctypes.c_int _LIB.RabitGetWorldSize.restype = ctypes.c_int _LIB.RabitIsDistributed.restype = ctypes.c_int _LIB.RabitVersionNumber.restype = ctypes.c_int
[ "internal", "library", "initializer", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L14-L20
[ "def", "_init_rabit", "(", ")", ":", "if", "_LIB", "is", "not", "None", ":", "_LIB", ".", "RabitGetRank", ".", "restype", "=", "ctypes", ".", "c_int", "_LIB", ".", "RabitGetWorldSize", ".", "restype", "=", "ctypes", ".", "c_int", "_LIB", ".", "RabitIsDis...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
init
Initialize the rabit library with arguments
python-package/xgboost/rabit.py
def init(args=None): """Initialize the rabit library with arguments""" if args is None: args = [] arr = (ctypes.c_char_p * len(args))() arr[:] = args _LIB.RabitInit(len(arr), arr)
def init(args=None): """Initialize the rabit library with arguments""" if args is None: args = [] arr = (ctypes.c_char_p * len(args))() arr[:] = args _LIB.RabitInit(len(arr), arr)
[ "Initialize", "the", "rabit", "library", "with", "arguments" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L23-L29
[ "def", "init", "(", "args", "=", "None", ")", ":", "if", "args", "is", "None", ":", "args", "=", "[", "]", "arr", "=", "(", "ctypes", ".", "c_char_p", "*", "len", "(", "args", ")", ")", "(", ")", "arr", "[", ":", "]", "=", "args", "_LIB", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
tracker_print
Print message to the tracker. This function can be used to communicate the information of the progress to the tracker Parameters ---------- msg : str The message to be printed to tracker.
python-package/xgboost/rabit.py
def tracker_print(msg): """Print message to the tracker. This function can be used to communicate the information of the progress to the tracker Parameters ---------- msg : str The message to be printed to tracker. """ if not isinstance(msg, STRING_TYPES): msg = str(msg...
def tracker_print(msg): """Print message to the tracker. This function can be used to communicate the information of the progress to the tracker Parameters ---------- msg : str The message to be printed to tracker. """ if not isinstance(msg, STRING_TYPES): msg = str(msg...
[ "Print", "message", "to", "the", "tracker", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L61-L79
[ "def", "tracker_print", "(", "msg", ")", ":", "if", "not", "isinstance", "(", "msg", ",", "STRING_TYPES", ")", ":", "msg", "=", "str", "(", "msg", ")", "is_dist", "=", "_LIB", ".", "RabitIsDistributed", "(", ")", "if", "is_dist", "!=", "0", ":", "_LI...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
get_processor_name
Get the processor name. Returns ------- name : str the name of processor(host)
python-package/xgboost/rabit.py
def get_processor_name(): """Get the processor name. Returns ------- name : str the name of processor(host) """ mxlen = 256 length = ctypes.c_ulong() buf = ctypes.create_string_buffer(mxlen) _LIB.RabitGetProcessorName(buf, ctypes.byref(length), mxlen) return buf.value
def get_processor_name(): """Get the processor name. Returns ------- name : str the name of processor(host) """ mxlen = 256 length = ctypes.c_ulong() buf = ctypes.create_string_buffer(mxlen) _LIB.RabitGetProcessorName(buf, ctypes.byref(length), mxlen) return buf.value
[ "Get", "the", "processor", "name", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L82-L94
[ "def", "get_processor_name", "(", ")", ":", "mxlen", "=", "256", "length", "=", "ctypes", ".", "c_ulong", "(", ")", "buf", "=", "ctypes", ".", "create_string_buffer", "(", "mxlen", ")", "_LIB", ".", "RabitGetProcessorName", "(", "buf", ",", "ctypes", ".", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
broadcast
Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- object : int the result...
python-package/xgboost/rabit.py
def broadcast(data, root): """Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- ...
def broadcast(data, root): """Broadcast object from one node to all other nodes. Parameters ---------- data : any type that can be pickled Input data, if current rank does not equal root, this can be None root : int Rank of the node to broadcast data from. Returns ------- ...
[ "Broadcast", "object", "from", "one", "node", "to", "all", "other", "nodes", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/rabit.py#L97-L132
[ "def", "broadcast", "(", "data", ",", "root", ")", ":", "rank", "=", "get_rank", "(", ")", "length", "=", "ctypes", ".", "c_ulong", "(", ")", "if", "root", "==", "rank", ":", "assert", "data", "is", "not", "None", ",", "'need to pass in data when broadca...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
normpath
Normalize UNIX path to a native path.
jvm-packages/create_jni.py
def normpath(path): """Normalize UNIX path to a native path.""" normalized = os.path.join(*path.split("/")) if os.path.isabs(path): return os.path.abspath("/") + normalized else: return normalized
def normpath(path): """Normalize UNIX path to a native path.""" normalized = os.path.join(*path.split("/")) if os.path.isabs(path): return os.path.abspath("/") + normalized else: return normalized
[ "Normalize", "UNIX", "path", "to", "a", "native", "path", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/jvm-packages/create_jni.py#L61-L67
[ "def", "normpath", "(", "path", ")", ":", "normalized", "=", "os", ".", "path", ".", "join", "(", "*", "path", ".", "split", "(", "\"/\"", ")", ")", "if", "os", ".", "path", ".", "isabs", "(", "path", ")", ":", "return", "os", ".", "path", ".",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_train_internal
internal training function
python-package/xgboost/training.py
def _train_internal(params, dtrain, num_boost_round=10, evals=(), obj=None, feval=None, xgb_model=None, callbacks=None): """internal training function""" callbacks = [] if callbacks is None else callbacks evals = list(evals) if isinstance(param...
def _train_internal(params, dtrain, num_boost_round=10, evals=(), obj=None, feval=None, xgb_model=None, callbacks=None): """internal training function""" callbacks = [] if callbacks is None else callbacks evals = list(evals) if isinstance(param...
[ "internal", "training", "function" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L15-L112
[ "def", "_train_internal", "(", "params", ",", "dtrain", ",", "num_boost_round", "=", "10", ",", "evals", "=", "(", ")", ",", "obj", "=", "None", ",", "feval", "=", "None", ",", "xgb_model", "=", "None", ",", "callbacks", "=", "None", ")", ":", "callb...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
train
Train a booster with given parameters. Parameters ---------- params : dict Booster params. dtrain : DMatrix Data to be trained. num_boost_round: int Number of boosting iterations. evals: list of pairs (DMatrix, string) List of items to be evaluated during trainin...
python-package/xgboost/training.py
def train(params, dtrain, num_boost_round=10, evals=(), obj=None, feval=None, maximize=False, early_stopping_rounds=None, evals_result=None, verbose_eval=True, xgb_model=None, callbacks=None, learning_rates=None): # pylint: disable=too-many-statements,too-many-branches, attribute-defined-outside...
def train(params, dtrain, num_boost_round=10, evals=(), obj=None, feval=None, maximize=False, early_stopping_rounds=None, evals_result=None, verbose_eval=True, xgb_model=None, callbacks=None, learning_rates=None): # pylint: disable=too-many-statements,too-many-branches, attribute-defined-outside...
[ "Train", "a", "booster", "with", "given", "parameters", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L115-L216
[ "def", "train", "(", "params", ",", "dtrain", ",", "num_boost_round", "=", "10", ",", "evals", "=", "(", ")", ",", "obj", "=", "None", ",", "feval", "=", "None", ",", "maximize", "=", "False", ",", "early_stopping_rounds", "=", "None", ",", "evals_resu...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
mknfold
Make an n-fold list of CVPack from random indices.
python-package/xgboost/training.py
def mknfold(dall, nfold, param, seed, evals=(), fpreproc=None, stratified=False, folds=None, shuffle=True): """ Make an n-fold list of CVPack from random indices. """ evals = list(evals) np.random.seed(seed) if stratified is False and folds is None: # Do standard k-fold cros...
def mknfold(dall, nfold, param, seed, evals=(), fpreproc=None, stratified=False, folds=None, shuffle=True): """ Make an n-fold list of CVPack from random indices. """ evals = list(evals) np.random.seed(seed) if stratified is False and folds is None: # Do standard k-fold cros...
[ "Make", "an", "n", "-", "fold", "list", "of", "CVPack", "from", "random", "indices", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L237-L286
[ "def", "mknfold", "(", "dall", ",", "nfold", ",", "param", ",", "seed", ",", "evals", "=", "(", ")", ",", "fpreproc", "=", "None", ",", "stratified", "=", "False", ",", "folds", "=", "None", ",", "shuffle", "=", "True", ")", ":", "evals", "=", "l...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
aggcv
Aggregate cross-validation results. If verbose_eval is true, progress is displayed in every call. If verbose_eval is an integer, progress will only be displayed every `verbose_eval` trees, tracked via trial.
python-package/xgboost/training.py
def aggcv(rlist): # pylint: disable=invalid-name """ Aggregate cross-validation results. If verbose_eval is true, progress is displayed in every call. If verbose_eval is an integer, progress will only be displayed every `verbose_eval` trees, tracked via trial. """ cvmap = {} idx = r...
def aggcv(rlist): # pylint: disable=invalid-name """ Aggregate cross-validation results. If verbose_eval is true, progress is displayed in every call. If verbose_eval is an integer, progress will only be displayed every `verbose_eval` trees, tracked via trial. """ cvmap = {} idx = r...
[ "Aggregate", "cross", "-", "validation", "results", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L289-L318
[ "def", "aggcv", "(", "rlist", ")", ":", "# pylint: disable=invalid-name", "cvmap", "=", "{", "}", "idx", "=", "rlist", "[", "0", "]", ".", "split", "(", ")", "[", "0", "]", "for", "line", "in", "rlist", ":", "arr", "=", "line", ".", "split", "(", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
cv
Cross-validation with given parameters. Parameters ---------- params : dict Booster params. dtrain : DMatrix Data to be trained. num_boost_round : int Number of boosting iterations. nfold : int Number of folds in CV. stratified : bool Perform stratifi...
python-package/xgboost/training.py
def cv(params, dtrain, num_boost_round=10, nfold=3, stratified=False, folds=None, metrics=(), obj=None, feval=None, maximize=False, early_stopping_rounds=None, fpreproc=None, as_pandas=True, verbose_eval=None, show_stdv=True, seed=0, callbacks=None, shuffle=True): # pylint: disable = invalid-na...
def cv(params, dtrain, num_boost_round=10, nfold=3, stratified=False, folds=None, metrics=(), obj=None, feval=None, maximize=False, early_stopping_rounds=None, fpreproc=None, as_pandas=True, verbose_eval=None, show_stdv=True, seed=0, callbacks=None, shuffle=True): # pylint: disable = invalid-na...
[ "Cross", "-", "validation", "with", "given", "parameters", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L321-L474
[ "def", "cv", "(", "params", ",", "dtrain", ",", "num_boost_round", "=", "10", ",", "nfold", "=", "3", ",", "stratified", "=", "False", ",", "folds", "=", "None", ",", "metrics", "=", "(", ")", ",", "obj", "=", "None", ",", "feval", "=", "None", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
CVPack.update
Update the boosters for one iteration
python-package/xgboost/training.py
def update(self, iteration, fobj): """"Update the boosters for one iteration""" self.bst.update(self.dtrain, iteration, fobj)
def update(self, iteration, fobj): """"Update the boosters for one iteration""" self.bst.update(self.dtrain, iteration, fobj)
[ "Update", "the", "boosters", "for", "one", "iteration" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L228-L230
[ "def", "update", "(", "self", ",", "iteration", ",", "fobj", ")", ":", "self", ".", "bst", ".", "update", "(", "self", ".", "dtrain", ",", "iteration", ",", "fobj", ")" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
CVPack.eval
Evaluate the CVPack for one iteration.
python-package/xgboost/training.py
def eval(self, iteration, feval): """"Evaluate the CVPack for one iteration.""" return self.bst.eval_set(self.watchlist, iteration, feval)
def eval(self, iteration, feval): """"Evaluate the CVPack for one iteration.""" return self.bst.eval_set(self.watchlist, iteration, feval)
[ "Evaluate", "the", "CVPack", "for", "one", "iteration", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/training.py#L232-L234
[ "def", "eval", "(", "self", ",", "iteration", ",", "feval", ")", ":", "return", "self", ".", "bst", ".", "eval_set", "(", "self", ".", "watchlist", ",", "iteration", ",", "feval", ")" ]
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_get_callback_context
return whether the current callback context is cv or train
python-package/xgboost/callback.py
def _get_callback_context(env): """return whether the current callback context is cv or train""" if env.model is not None and env.cvfolds is None: context = 'train' elif env.model is None and env.cvfolds is not None: context = 'cv' return context
def _get_callback_context(env): """return whether the current callback context is cv or train""" if env.model is not None and env.cvfolds is None: context = 'train' elif env.model is None and env.cvfolds is not None: context = 'cv' return context
[ "return", "whether", "the", "current", "callback", "context", "is", "cv", "or", "train" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L10-L16
[ "def", "_get_callback_context", "(", "env", ")", ":", "if", "env", ".", "model", "is", "not", "None", "and", "env", ".", "cvfolds", "is", "None", ":", "context", "=", "'train'", "elif", "env", ".", "model", "is", "None", "and", "env", ".", "cvfolds", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_fmt_metric
format metric string
python-package/xgboost/callback.py
def _fmt_metric(value, show_stdv=True): """format metric string""" if len(value) == 2: return '%s:%g' % (value[0], value[1]) if len(value) == 3: if show_stdv: return '%s:%g+%g' % (value[0], value[1], value[2]) return '%s:%g' % (value[0], value[1]) raise ValueError("wr...
def _fmt_metric(value, show_stdv=True): """format metric string""" if len(value) == 2: return '%s:%g' % (value[0], value[1]) if len(value) == 3: if show_stdv: return '%s:%g+%g' % (value[0], value[1], value[2]) return '%s:%g' % (value[0], value[1]) raise ValueError("wr...
[ "format", "metric", "string" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L19-L27
[ "def", "_fmt_metric", "(", "value", ",", "show_stdv", "=", "True", ")", ":", "if", "len", "(", "value", ")", "==", "2", ":", "return", "'%s:%g'", "%", "(", "value", "[", "0", "]", ",", "value", "[", "1", "]", ")", "if", "len", "(", "value", ")"...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
print_evaluation
Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show_stdv : bool, optional Whether show stdv if pr...
python-package/xgboost/callback.py
def print_evaluation(period=1, show_stdv=True): """Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show...
def print_evaluation(period=1, show_stdv=True): """Create a callback that print evaluation result. We print the evaluation results every **period** iterations and on the first and the last iterations. Parameters ---------- period : int The period to log the evaluation results show...
[ "Create", "a", "callback", "that", "print", "evaluation", "result", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L30-L57
[ "def", "print_evaluation", "(", "period", "=", "1", ",", "show_stdv", "=", "True", ")", ":", "def", "callback", "(", "env", ")", ":", "\"\"\"internal function\"\"\"", "if", "env", ".", "rank", "!=", "0", "or", "(", "not", "env", ".", "evaluation_result_lis...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
record_evaluation
Create a call back that records the evaluation history into **eval_result**. Parameters ---------- eval_result : dict A dictionary to store the evaluation results. Returns ------- callback : function The requested callback function.
python-package/xgboost/callback.py
def record_evaluation(eval_result): """Create a call back that records the evaluation history into **eval_result**. Parameters ---------- eval_result : dict A dictionary to store the evaluation results. Returns ------- callback : function The requested callback function. ...
def record_evaluation(eval_result): """Create a call back that records the evaluation history into **eval_result**. Parameters ---------- eval_result : dict A dictionary to store the evaluation results. Returns ------- callback : function The requested callback function. ...
[ "Create", "a", "call", "back", "that", "records", "the", "evaluation", "history", "into", "**", "eval_result", "**", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L60-L97
[ "def", "record_evaluation", "(", "eval_result", ")", ":", "if", "not", "isinstance", "(", "eval_result", ",", "dict", ")", ":", "raise", "TypeError", "(", "'eval_result has to be a dictionary'", ")", "eval_result", ".", "clear", "(", ")", "def", "init", "(", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
reset_learning_rate
Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized function that calculates eta in terms of curr...
python-package/xgboost/callback.py
def reset_learning_rate(learning_rates): """Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized funct...
def reset_learning_rate(learning_rates): """Reset learning rate after iteration 1 NOTE: the initial learning rate will still take in-effect on first iteration. Parameters ---------- learning_rates: list or function List of learning rate for each boosting round or a customized funct...
[ "Reset", "learning", "rate", "after", "iteration", "1" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L100-L145
[ "def", "reset_learning_rate", "(", "learning_rates", ")", ":", "def", "get_learning_rate", "(", "i", ",", "n", ",", "learning_rates", ")", ":", "\"\"\"helper providing the learning rate\"\"\"", "if", "isinstance", "(", "learning_rates", ",", "list", ")", ":", "if", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
early_stop
Create a callback that activates early stoppping. Validation error needs to decrease at least every **stopping_rounds** round(s) to continue training. Requires at least one item in **evals**. If there's more than one, will use the last. Returns the model from the last iteration (not the best one). ...
python-package/xgboost/callback.py
def early_stop(stopping_rounds, maximize=False, verbose=True): """Create a callback that activates early stoppping. Validation error needs to decrease at least every **stopping_rounds** round(s) to continue training. Requires at least one item in **evals**. If there's more than one, will use the la...
def early_stop(stopping_rounds, maximize=False, verbose=True): """Create a callback that activates early stoppping. Validation error needs to decrease at least every **stopping_rounds** round(s) to continue training. Requires at least one item in **evals**. If there's more than one, will use the la...
[ "Create", "a", "callback", "that", "activates", "early", "stoppping", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/callback.py#L148-L250
[ "def", "early_stop", "(", "stopping_rounds", ",", "maximize", "=", "False", ",", "verbose", "=", "True", ")", ":", "state", "=", "{", "}", "def", "init", "(", "env", ")", ":", "\"\"\"internal function\"\"\"", "bst", "=", "env", ".", "model", "if", "not",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
run_doxygen
Run the doxygen make command in the designated folder.
doc/conf.py
def run_doxygen(folder): """Run the doxygen make command in the designated folder.""" try: retcode = subprocess.call("cd %s; make doxygen" % folder, shell=True) if retcode < 0: sys.stderr.write("doxygen terminated by signal %s" % (-retcode)) except OSError as e: sys.stderr.write("doxygen executi...
def run_doxygen(folder): """Run the doxygen make command in the designated folder.""" try: retcode = subprocess.call("cd %s; make doxygen" % folder, shell=True) if retcode < 0: sys.stderr.write("doxygen terminated by signal %s" % (-retcode)) except OSError as e: sys.stderr.write("doxygen executi...
[ "Run", "the", "doxygen", "make", "command", "in", "the", "designated", "folder", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/doc/conf.py#L196-L203
[ "def", "run_doxygen", "(", "folder", ")", ":", "try", ":", "retcode", "=", "subprocess", ".", "call", "(", "\"cd %s; make doxygen\"", "%", "folder", ",", "shell", "=", "True", ")", "if", "retcode", "<", "0", ":", "sys", ".", "stderr", ".", "write", "("...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_objective_decorator
Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred)``: y_true: array_like of sha...
python-package/xgboost/sklearn.py
def _objective_decorator(func): """Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred...
def _objective_decorator(func): """Decorate an objective function Converts an objective function using the typical sklearn metrics signature so that it is usable with ``xgboost.training.train`` Parameters ---------- func: callable Expects a callable with signature ``func(y_true, y_pred...
[ "Decorate", "an", "objective", "function" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L18-L50
[ "def", "_objective_decorator", "(", "func", ")", ":", "def", "inner", "(", "preds", ",", "dmatrix", ")", ":", "\"\"\"internal function\"\"\"", "labels", "=", "dmatrix", ".", "get_label", "(", ")", "return", "func", "(", "labels", ",", "preds", ")", "return",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.set_params
Set the parameters of this estimator. Modification of the sklearn method to allow unknown kwargs. This allows using the full range of xgboost parameters that are not defined as member variables in sklearn grid search. Returns ------- self
python-package/xgboost/sklearn.py
def set_params(self, **params): """Set the parameters of this estimator. Modification of the sklearn method to allow unknown kwargs. This allows using the full range of xgboost parameters that are not defined as member variables in sklearn grid search. Returns ------- ...
def set_params(self, **params): """Set the parameters of this estimator. Modification of the sklearn method to allow unknown kwargs. This allows using the full range of xgboost parameters that are not defined as member variables in sklearn grid search. Returns ------- ...
[ "Set", "the", "parameters", "of", "this", "estimator", ".", "Modification", "of", "the", "sklearn", "method", "to", "allow", "unknown", "kwargs", ".", "This", "allows", "using", "the", "full", "range", "of", "xgboost", "parameters", "that", "are", "not", "de...
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L196-L215
[ "def", "set_params", "(", "self", ",", "*", "*", "params", ")", ":", "if", "not", "params", ":", "# Simple optimization to gain speed (inspect is slow)", "return", "self", "for", "key", ",", "value", "in", "params", ".", "items", "(", ")", ":", "if", "hasatt...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.get_params
Get parameters.
python-package/xgboost/sklearn.py
def get_params(self, deep=False): """Get parameters.""" params = super(XGBModel, self).get_params(deep=deep) if isinstance(self.kwargs, dict): # if kwargs is a dict, update params accordingly params.update(self.kwargs) if params['missing'] is np.nan: params['miss...
def get_params(self, deep=False): """Get parameters.""" params = super(XGBModel, self).get_params(deep=deep) if isinstance(self.kwargs, dict): # if kwargs is a dict, update params accordingly params.update(self.kwargs) if params['missing'] is np.nan: params['miss...
[ "Get", "parameters", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L217-L226
[ "def", "get_params", "(", "self", ",", "deep", "=", "False", ")", ":", "params", "=", "super", "(", "XGBModel", ",", "self", ")", ".", "get_params", "(", "deep", "=", "deep", ")", "if", "isinstance", "(", "self", ".", "kwargs", ",", "dict", ")", ":...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.get_xgb_params
Get xgboost type parameters.
python-package/xgboost/sklearn.py
def get_xgb_params(self): """Get xgboost type parameters.""" xgb_params = self.get_params() random_state = xgb_params.pop('random_state') if 'seed' in xgb_params and xgb_params['seed'] is not None: warnings.warn('The seed parameter is deprecated as of version .6.' ...
def get_xgb_params(self): """Get xgboost type parameters.""" xgb_params = self.get_params() random_state = xgb_params.pop('random_state') if 'seed' in xgb_params and xgb_params['seed'] is not None: warnings.warn('The seed parameter is deprecated as of version .6.' ...
[ "Get", "xgboost", "type", "parameters", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L228-L258
[ "def", "get_xgb_params", "(", "self", ")", ":", "xgb_params", "=", "self", ".", "get_params", "(", ")", "random_state", "=", "xgb_params", ".", "pop", "(", "'random_state'", ")", "if", "'seed'", "in", "xgb_params", "and", "xgb_params", "[", "'seed'", "]", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.load_model
Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature names) will not be loaded. Label encodings (text labels to numeric labels) w...
python-package/xgboost/sklearn.py
def load_model(self, fname): """ Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature names) will not be loaded. ...
def load_model(self, fname): """ Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature names) will not be loaded. ...
[ "Load", "the", "model", "from", "a", "file", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L282-L300
[ "def", "load_model", "(", "self", ",", "fname", ")", ":", "if", "self", ".", "_Booster", "is", "None", ":", "self", ".", "_Booster", "=", "Booster", "(", "{", "'nthread'", ":", "self", ".", "n_jobs", "}", ")", "self", ".", "_Booster", ".", "load_mode...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.fit
Fit the gradient boosting model Parameters ---------- X : array_like Feature matrix y : array_like Labels sample_weight : array_like instance weights eval_set : list, optional A list of (X, y) tuple pairs to use as a valida...
python-package/xgboost/sklearn.py
def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None, early_stopping_rounds=None, verbose=True, xgb_model=None, sample_weight_eval_set=None, callbacks=None): # pylint: disable=missing-docstring,invalid-name,attribute-defined-outside-init """ Fit the gra...
def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None, early_stopping_rounds=None, verbose=True, xgb_model=None, sample_weight_eval_set=None, callbacks=None): # pylint: disable=missing-docstring,invalid-name,attribute-defined-outside-init """ Fit the gra...
[ "Fit", "the", "gradient", "boosting", "model" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L302-L408
[ "def", "fit", "(", "self", ",", "X", ",", "y", ",", "sample_weight", "=", "None", ",", "eval_set", "=", "None", ",", "eval_metric", "=", "None", ",", "early_stopping_rounds", "=", "None", ",", "verbose", "=", "True", ",", "xgb_model", "=", "None", ",",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.predict
Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thread, call ``xgb.copy()`` to make copies of model object and then call ``predict()``. .. n...
python-package/xgboost/sklearn.py
def predict(self, data, output_margin=False, ntree_limit=None, validate_features=True): """ Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thr...
def predict(self, data, output_margin=False, ntree_limit=None, validate_features=True): """ Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thr...
[ "Predict", "with", "data", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L410-L456
[ "def", "predict", "(", "self", ",", "data", ",", "output_margin", "=", "False", ",", "ntree_limit", "=", "None", ",", "validate_features", "=", "True", ")", ":", "# pylint: disable=missing-docstring,invalid-name", "test_dmatrix", "=", "DMatrix", "(", "data", ",", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.apply
Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to 0 (use all trees). Returns --...
python-package/xgboost/sklearn.py
def apply(self, X, ntree_limit=0): """Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to ...
def apply(self, X, ntree_limit=0): """Return the predicted leaf every tree for each sample. Parameters ---------- X : array_like, shape=[n_samples, n_features] Input features matrix. ntree_limit : int Limit number of trees in the prediction; defaults to ...
[ "Return", "the", "predicted", "leaf", "every", "tree", "for", "each", "sample", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L458-L479
[ "def", "apply", "(", "self", ",", "X", ",", "ntree_limit", "=", "0", ")", ":", "test_dmatrix", "=", "DMatrix", "(", "X", ",", "missing", "=", "self", ".", "missing", ",", "nthread", "=", "self", ".", "n_jobs", ")", "return", "self", ".", "get_booster...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.feature_importances_
Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base learner types, such as linear learners ...
python-package/xgboost/sklearn.py
def feature_importances_(self): """ Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base...
def feature_importances_(self): """ Feature importances property .. note:: Feature importance is defined only for tree boosters Feature importance is only defined when the decision tree model is chosen as base learner (`booster=gbtree`). It is not defined for other base...
[ "Feature", "importances", "property" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L524-L546
[ "def", "feature_importances_", "(", "self", ")", ":", "if", "getattr", "(", "self", ",", "'booster'", ",", "None", ")", "is", "not", "None", "and", "self", ".", "booster", "!=", "'gbtree'", ":", "raise", "AttributeError", "(", "'Feature importance is not defin...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.coef_
Coefficients property .. note:: Coefficients are defined only for linear learners Coefficients are only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such as tree learners (`booster=gbtree`). ...
python-package/xgboost/sklearn.py
def coef_(self): """ Coefficients property .. note:: Coefficients are defined only for linear learners Coefficients are only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such as...
def coef_(self): """ Coefficients property .. note:: Coefficients are defined only for linear learners Coefficients are only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such as...
[ "Coefficients", "property" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L549-L575
[ "def", "coef_", "(", "self", ")", ":", "if", "getattr", "(", "self", ",", "'booster'", ",", "None", ")", "is", "not", "None", "and", "self", ".", "booster", "!=", "'gblinear'", ":", "raise", "AttributeError", "(", "'Coefficients are not defined for Booster typ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBModel.intercept_
Intercept (bias) property .. note:: Intercept is defined only for linear learners Intercept (bias) is only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such as tree learners (`booster=gbtree`)....
python-package/xgboost/sklearn.py
def intercept_(self): """ Intercept (bias) property .. note:: Intercept is defined only for linear learners Intercept (bias) is only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such ...
def intercept_(self): """ Intercept (bias) property .. note:: Intercept is defined only for linear learners Intercept (bias) is only defined when the linear model is chosen as base learner (`booster=gblinear`). It is not defined for other base learner types, such ...
[ "Intercept", "(", "bias", ")", "property" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L578-L596
[ "def", "intercept_", "(", "self", ")", ":", "if", "getattr", "(", "self", ",", "'booster'", ",", "None", ")", "is", "not", "None", "and", "self", ".", "booster", "!=", "'gblinear'", ":", "raise", "AttributeError", "(", "'Intercept (bias) is not defined for Boo...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBClassifier.fit
Fit gradient boosting classifier Parameters ---------- X : array_like Feature matrix y : array_like Labels sample_weight : array_like Weight for each instance eval_set : list, optional A list of (X, y) pairs to use as a val...
python-package/xgboost/sklearn.py
def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None, early_stopping_rounds=None, verbose=True, xgb_model=None, sample_weight_eval_set=None, callbacks=None): # pylint: disable = attribute-defined-outside-init,arguments-differ """ Fit gradient boosting c...
def fit(self, X, y, sample_weight=None, eval_set=None, eval_metric=None, early_stopping_rounds=None, verbose=True, xgb_model=None, sample_weight_eval_set=None, callbacks=None): # pylint: disable = attribute-defined-outside-init,arguments-differ """ Fit gradient boosting c...
[ "Fit", "gradient", "boosting", "classifier" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L622-L746
[ "def", "fit", "(", "self", ",", "X", ",", "y", ",", "sample_weight", "=", "None", ",", "eval_set", "=", "None", ",", "eval_metric", "=", "None", ",", "early_stopping_rounds", "=", "None", ",", "verbose", "=", "True", ",", "xgb_model", "=", "None", ",",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBClassifier.predict
Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thread, call ``xgb.copy()`` to make copies of model object and then call ``predict()``. .. n...
python-package/xgboost/sklearn.py
def predict(self, data, output_margin=False, ntree_limit=None, validate_features=True): """ Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thr...
def predict(self, data, output_margin=False, ntree_limit=None, validate_features=True): """ Predict with `data`. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thr...
[ "Predict", "with", "data", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L748-L801
[ "def", "predict", "(", "self", ",", "data", ",", "output_margin", "=", "False", ",", "ntree_limit", "=", "None", ",", "validate_features", "=", "True", ")", ":", "test_dmatrix", "=", "DMatrix", "(", "data", ",", "missing", "=", "self", ".", "missing", ",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBClassifier.predict_proba
Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thread, call ``xgb.copy()`` to make copies of ...
python-package/xgboost/sklearn.py
def predict_proba(self, data, ntree_limit=None, validate_features=True): """ Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you wan...
def predict_proba(self, data, ntree_limit=None, validate_features=True): """ Predict the probability of each `data` example being of a given class. .. note:: This function is not thread safe For each booster object, predict can only be called from one thread. If you wan...
[ "Predict", "the", "probability", "of", "each", "data", "example", "being", "of", "a", "given", "class", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L803-L839
[ "def", "predict_proba", "(", "self", ",", "data", ",", "ntree_limit", "=", "None", ",", "validate_features", "=", "True", ")", ":", "test_dmatrix", "=", "DMatrix", "(", "data", ",", "missing", "=", "self", ".", "missing", ",", "nthread", "=", "self", "."...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
XGBRanker.fit
Fit the gradient boosting model Parameters ---------- X : array_like Feature matrix y : array_like Labels group : array_like group size of training data sample_weight : array_like group weights .. note:: Weight...
python-package/xgboost/sklearn.py
def fit(self, X, y, group, sample_weight=None, eval_set=None, sample_weight_eval_set=None, eval_group=None, eval_metric=None, early_stopping_rounds=None, verbose=False, xgb_model=None, callbacks=None): # pylint: disable = attribute-defined-outside-init,arguments-differ """ ...
def fit(self, X, y, group, sample_weight=None, eval_set=None, sample_weight_eval_set=None, eval_group=None, eval_metric=None, early_stopping_rounds=None, verbose=False, xgb_model=None, callbacks=None): # pylint: disable = attribute-defined-outside-init,arguments-differ """ ...
[ "Fit", "the", "gradient", "boosting", "model" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/sklearn.py#L1078-L1220
[ "def", "fit", "(", "self", ",", "X", ",", "y", ",", "group", ",", "sample_weight", "=", "None", ",", "eval_set", "=", "None", ",", "sample_weight_eval_set", "=", "None", ",", "eval_group", "=", "None", ",", "eval_metric", "=", "None", ",", "early_stoppin...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
from_pystr_to_cstr
Convert a list of Python str to C pointer Parameters ---------- data : list list of str
python-package/xgboost/core.py
def from_pystr_to_cstr(data): """Convert a list of Python str to C pointer Parameters ---------- data : list list of str """ if not isinstance(data, list): raise NotImplementedError pointers = (ctypes.c_char_p * len(data))() if PY3: data = [bytes(d, 'utf-8') for...
def from_pystr_to_cstr(data): """Convert a list of Python str to C pointer Parameters ---------- data : list list of str """ if not isinstance(data, list): raise NotImplementedError pointers = (ctypes.c_char_p * len(data))() if PY3: data = [bytes(d, 'utf-8') for...
[ "Convert", "a", "list", "of", "Python", "str", "to", "C", "pointer" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L60-L78
[ "def", "from_pystr_to_cstr", "(", "data", ")", ":", "if", "not", "isinstance", "(", "data", ",", "list", ")", ":", "raise", "NotImplementedError", "pointers", "=", "(", "ctypes", ".", "c_char_p", "*", "len", "(", "data", ")", ")", "(", ")", "if", "PY3"...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
from_cstr_to_pystr
Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data
python-package/xgboost/core.py
def from_cstr_to_pystr(data, length): """Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data """ if PY3: res = [] for i in range(length.value): try: ...
def from_cstr_to_pystr(data, length): """Revert C pointer to Python str Parameters ---------- data : ctypes pointer pointer to data length : ctypes pointer pointer to length of data """ if PY3: res = [] for i in range(length.value): try: ...
[ "Revert", "C", "pointer", "to", "Python", "str" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L81-L106
[ "def", "from_cstr_to_pystr", "(", "data", ",", "length", ")", ":", "if", "PY3", ":", "res", "=", "[", "]", "for", "i", "in", "range", "(", "length", ".", "value", ")", ":", "try", ":", "res", ".", "append", "(", "str", "(", "data", "[", "i", "]...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_load_lib
Load xgboost Library.
python-package/xgboost/core.py
def _load_lib(): """Load xgboost Library.""" lib_paths = find_lib_path() if not lib_paths: return None try: pathBackup = os.environ['PATH'].split(os.pathsep) except KeyError: pathBackup = [] lib_success = False os_error_list = [] for lib_path in lib_paths: ...
def _load_lib(): """Load xgboost Library.""" lib_paths = find_lib_path() if not lib_paths: return None try: pathBackup = os.environ['PATH'].split(os.pathsep) except KeyError: pathBackup = [] lib_success = False os_error_list = [] for lib_path in lib_paths: ...
[ "Load", "xgboost", "Library", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L121-L157
[ "def", "_load_lib", "(", ")", ":", "lib_paths", "=", "find_lib_path", "(", ")", "if", "not", "lib_paths", ":", "return", "None", "try", ":", "pathBackup", "=", "os", ".", "environ", "[", "'PATH'", "]", ".", "split", "(", "os", ".", "pathsep", ")", "e...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
ctypes2numpy
Convert a ctypes pointer array to a numpy array.
python-package/xgboost/core.py
def ctypes2numpy(cptr, length, dtype): """Convert a ctypes pointer array to a numpy array. """ NUMPY_TO_CTYPES_MAPPING = { np.float32: ctypes.c_float, np.uint32: ctypes.c_uint, } if dtype not in NUMPY_TO_CTYPES_MAPPING: raise RuntimeError('Supported types: {}'.format(NUMPY_TO...
def ctypes2numpy(cptr, length, dtype): """Convert a ctypes pointer array to a numpy array. """ NUMPY_TO_CTYPES_MAPPING = { np.float32: ctypes.c_float, np.uint32: ctypes.c_uint, } if dtype not in NUMPY_TO_CTYPES_MAPPING: raise RuntimeError('Supported types: {}'.format(NUMPY_TO...
[ "Convert", "a", "ctypes", "pointer", "array", "to", "a", "numpy", "array", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L179-L194
[ "def", "ctypes2numpy", "(", "cptr", ",", "length", ",", "dtype", ")", ":", "NUMPY_TO_CTYPES_MAPPING", "=", "{", "np", ".", "float32", ":", "ctypes", ".", "c_float", ",", "np", ".", "uint32", ":", "ctypes", ".", "c_uint", ",", "}", "if", "dtype", "not",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
ctypes2buffer
Convert ctypes pointer to buffer type.
python-package/xgboost/core.py
def ctypes2buffer(cptr, length): """Convert ctypes pointer to buffer type.""" if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)): raise RuntimeError('expected char pointer') res = bytearray(length) rptr = (ctypes.c_char * length).from_buffer(res) if not ctypes.memmove(rptr, cptr, length)...
def ctypes2buffer(cptr, length): """Convert ctypes pointer to buffer type.""" if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)): raise RuntimeError('expected char pointer') res = bytearray(length) rptr = (ctypes.c_char * length).from_buffer(res) if not ctypes.memmove(rptr, cptr, length)...
[ "Convert", "ctypes", "pointer", "to", "buffer", "type", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L197-L205
[ "def", "ctypes2buffer", "(", "cptr", ",", "length", ")", ":", "if", "not", "isinstance", "(", "cptr", ",", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char", ")", ")", ":", "raise", "RuntimeError", "(", "'expected char pointer'", ")", "res", "=", "b...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
c_array
Convert a python string to c array.
python-package/xgboost/core.py
def c_array(ctype, values): """Convert a python string to c array.""" if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype): return (ctype * len(values)).from_buffer_copy(values) return (ctype * len(values))(*values)
def c_array(ctype, values): """Convert a python string to c array.""" if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype): return (ctype * len(values)).from_buffer_copy(values) return (ctype * len(values))(*values)
[ "Convert", "a", "python", "string", "to", "c", "array", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L213-L217
[ "def", "c_array", "(", "ctype", ",", "values", ")", ":", "if", "isinstance", "(", "values", ",", "np", ".", "ndarray", ")", "and", "values", ".", "dtype", ".", "itemsize", "==", "ctypes", ".", "sizeof", "(", "ctype", ")", ":", "return", "(", "ctype",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_maybe_pandas_data
Extract internal data from pd.DataFrame for DMatrix data
python-package/xgboost/core.py
def _maybe_pandas_data(data, feature_names, feature_types): """ Extract internal data from pd.DataFrame for DMatrix data """ if not isinstance(data, DataFrame): return data, feature_names, feature_types data_dtypes = data.dtypes if not all(dtype.name in PANDAS_DTYPE_MAPPER for dtype in data_dt...
def _maybe_pandas_data(data, feature_names, feature_types): """ Extract internal data from pd.DataFrame for DMatrix data """ if not isinstance(data, DataFrame): return data, feature_names, feature_types data_dtypes = data.dtypes if not all(dtype.name in PANDAS_DTYPE_MAPPER for dtype in data_dt...
[ "Extract", "internal", "data", "from", "pd", ".", "DataFrame", "for", "DMatrix", "data" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L226-L255
[ "def", "_maybe_pandas_data", "(", "data", ",", "feature_names", ",", "feature_types", ")", ":", "if", "not", "isinstance", "(", "data", ",", "DataFrame", ")", ":", "return", "data", ",", "feature_names", ",", "feature_types", "data_dtypes", "=", "data", ".", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_maybe_dt_data
Validate feature names and types if data table
python-package/xgboost/core.py
def _maybe_dt_data(data, feature_names, feature_types): """ Validate feature names and types if data table """ if not isinstance(data, DataTable): return data, feature_names, feature_types data_types_names = tuple(lt.name for lt in data.ltypes) bad_fields = [data.names[i] ...
def _maybe_dt_data(data, feature_names, feature_types): """ Validate feature names and types if data table """ if not isinstance(data, DataTable): return data, feature_names, feature_types data_types_names = tuple(lt.name for lt in data.ltypes) bad_fields = [data.names[i] ...
[ "Validate", "feature", "names", "and", "types", "if", "data", "table" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L279-L303
[ "def", "_maybe_dt_data", "(", "data", ",", "feature_names", ",", "feature_types", ")", ":", "if", "not", "isinstance", "(", "data", ",", "DataTable", ")", ":", "return", "data", ",", "feature_names", ",", "feature_types", "data_types_names", "=", "tuple", "(",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
_maybe_dt_array
Extract numpy array from single column data table
python-package/xgboost/core.py
def _maybe_dt_array(array): """ Extract numpy array from single column data table """ if not isinstance(array, DataTable) or array is None: return array if array.shape[1] > 1: raise ValueError('DataTable for label or weight cannot have multiple columns') # below requires new dt version...
def _maybe_dt_array(array): """ Extract numpy array from single column data table """ if not isinstance(array, DataTable) or array is None: return array if array.shape[1] > 1: raise ValueError('DataTable for label or weight cannot have multiple columns') # below requires new dt version...
[ "Extract", "numpy", "array", "from", "single", "column", "data", "table" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L306-L318
[ "def", "_maybe_dt_array", "(", "array", ")", ":", "if", "not", "isinstance", "(", "array", ",", "DataTable", ")", "or", "array", "is", "None", ":", "return", "array", "if", "array", ".", "shape", "[", "1", "]", ">", "1", ":", "raise", "ValueError", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix._init_from_csr
Initialize data from a CSR matrix.
python-package/xgboost/core.py
def _init_from_csr(self, csr): """ Initialize data from a CSR matrix. """ if len(csr.indices) != len(csr.data): raise ValueError('length mismatch: {} vs {}'.format(len(csr.indices), len(csr.data))) handle = ctypes.c_void_p() _check_call(_LIB.XGDMatrixCreateFro...
def _init_from_csr(self, csr): """ Initialize data from a CSR matrix. """ if len(csr.indices) != len(csr.data): raise ValueError('length mismatch: {} vs {}'.format(len(csr.indices), len(csr.data))) handle = ctypes.c_void_p() _check_call(_LIB.XGDMatrixCreateFro...
[ "Initialize", "data", "from", "a", "CSR", "matrix", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L429-L443
[ "def", "_init_from_csr", "(", "self", ",", "csr", ")", ":", "if", "len", "(", "csr", ".", "indices", ")", "!=", "len", "(", "csr", ".", "data", ")", ":", "raise", "ValueError", "(", "'length mismatch: {} vs {}'", ".", "format", "(", "len", "(", "csr", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix._init_from_csc
Initialize data from a CSC matrix.
python-package/xgboost/core.py
def _init_from_csc(self, csc): """ Initialize data from a CSC matrix. """ if len(csc.indices) != len(csc.data): raise ValueError('length mismatch: {} vs {}'.format(len(csc.indices), len(csc.data))) handle = ctypes.c_void_p() _check_call(_LIB.XGDMatrixCreateFro...
def _init_from_csc(self, csc): """ Initialize data from a CSC matrix. """ if len(csc.indices) != len(csc.data): raise ValueError('length mismatch: {} vs {}'.format(len(csc.indices), len(csc.data))) handle = ctypes.c_void_p() _check_call(_LIB.XGDMatrixCreateFro...
[ "Initialize", "data", "from", "a", "CSC", "matrix", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L445-L459
[ "def", "_init_from_csc", "(", "self", ",", "csc", ")", ":", "if", "len", "(", "csc", ".", "indices", ")", "!=", "len", "(", "csc", ".", "data", ")", ":", "raise", "ValueError", "(", "'length mismatch: {} vs {}'", ".", "format", "(", "len", "(", "csc", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix._init_from_npy2d
Initialize data from a 2-D numpy matrix. If ``mat`` does not have ``order='C'`` (aka row-major) or is not contiguous, a temporary copy will be made. If ``mat`` does not have ``dtype=numpy.float32``, a temporary copy will be made. So there could be as many as two temporary data copies;...
python-package/xgboost/core.py
def _init_from_npy2d(self, mat, missing, nthread): """ Initialize data from a 2-D numpy matrix. If ``mat`` does not have ``order='C'`` (aka row-major) or is not contiguous, a temporary copy will be made. If ``mat`` does not have ``dtype=numpy.float32``, a temporary copy will be...
def _init_from_npy2d(self, mat, missing, nthread): """ Initialize data from a 2-D numpy matrix. If ``mat`` does not have ``order='C'`` (aka row-major) or is not contiguous, a temporary copy will be made. If ``mat`` does not have ``dtype=numpy.float32``, a temporary copy will be...
[ "Initialize", "data", "from", "a", "2", "-", "D", "numpy", "matrix", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L461-L496
[ "def", "_init_from_npy2d", "(", "self", ",", "mat", ",", "missing", ",", "nthread", ")", ":", "if", "len", "(", "mat", ".", "shape", ")", "!=", "2", ":", "raise", "ValueError", "(", "'Input numpy.ndarray must be 2 dimensional'", ")", "# flatten the array by rows...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix._init_from_dt
Initialize data from a datatable Frame.
python-package/xgboost/core.py
def _init_from_dt(self, data, nthread): """ Initialize data from a datatable Frame. """ ptrs = (ctypes.c_void_p * data.ncols)() if hasattr(data, "internal") and hasattr(data.internal, "column"): # datatable>0.8.0 for icol in range(data.ncols): ...
def _init_from_dt(self, data, nthread): """ Initialize data from a datatable Frame. """ ptrs = (ctypes.c_void_p * data.ncols)() if hasattr(data, "internal") and hasattr(data.internal, "column"): # datatable>0.8.0 for icol in range(data.ncols): ...
[ "Initialize", "data", "from", "a", "datatable", "Frame", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L498-L527
[ "def", "_init_from_dt", "(", "self", ",", "data", ",", "nthread", ")", ":", "ptrs", "=", "(", "ctypes", ".", "c_void_p", "*", "data", ".", "ncols", ")", "(", ")", "if", "hasattr", "(", "data", ",", "\"internal\"", ")", "and", "hasattr", "(", "data", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.set_float_info
Set float type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set
python-package/xgboost/core.py
def set_float_info(self, field, data): """Set float type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ if getattr(data, 'base', None) is not...
def set_float_info(self, field, data): """Set float type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ if getattr(data, 'base', None) is not...
[ "Set", "float", "type", "property", "into", "the", "DMatrix", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L576-L596
[ "def", "set_float_info", "(", "self", ",", "field", ",", "data", ")", ":", "if", "getattr", "(", "data", ",", "'base'", ",", "None", ")", "is", "not", "None", "and", "data", ".", "base", "is", "not", "None", "and", "isinstance", "(", "data", ",", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.set_float_info_npy2d
Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set
python-package/xgboost/core.py
def set_float_info_npy2d(self, field, data): """Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ ...
def set_float_info_npy2d(self, field, data): """Set float type property into the DMatrix for numpy 2d array input Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ ...
[ "Set", "float", "type", "property", "into", "the", "DMatrix", "for", "numpy", "2d", "array", "input" ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L598-L622
[ "def", "set_float_info_npy2d", "(", "self", ",", "field", ",", "data", ")", ":", "if", "getattr", "(", "data", ",", "'base'", ",", "None", ")", "is", "not", "None", "and", "data", ".", "base", "is", "not", "None", "and", "isinstance", "(", "data", ",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.set_uint_info
Set uint type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set
python-package/xgboost/core.py
def set_uint_info(self, field, data): """Set uint type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ if getattr(data, 'base', None) is not N...
def set_uint_info(self, field, data): """Set uint type property into the DMatrix. Parameters ---------- field: str The field name of the information data: numpy array The array of data to be set """ if getattr(data, 'base', None) is not N...
[ "Set", "uint", "type", "property", "into", "the", "DMatrix", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L624-L646
[ "def", "set_uint_info", "(", "self", ",", "field", ",", "data", ")", ":", "if", "getattr", "(", "data", ",", "'base'", ",", "None", ")", "is", "not", "None", "and", "data", ".", "base", "is", "not", "None", "and", "isinstance", "(", "data", ",", "n...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.save_binary
Save DMatrix to an XGBoost buffer. Saved binary can be later loaded by providing the path to :py:func:`xgboost.DMatrix` as input. Parameters ---------- fname : string Name of the output buffer file. silent : bool (optional; default: True) If set, the out...
python-package/xgboost/core.py
def save_binary(self, fname, silent=True): """Save DMatrix to an XGBoost buffer. Saved binary can be later loaded by providing the path to :py:func:`xgboost.DMatrix` as input. Parameters ---------- fname : string Name of the output buffer file. silent : bool...
def save_binary(self, fname, silent=True): """Save DMatrix to an XGBoost buffer. Saved binary can be later loaded by providing the path to :py:func:`xgboost.DMatrix` as input. Parameters ---------- fname : string Name of the output buffer file. silent : bool...
[ "Save", "DMatrix", "to", "an", "XGBoost", "buffer", ".", "Saved", "binary", "can", "be", "later", "loaded", "by", "providing", "the", "path", "to", ":", "py", ":", "func", ":", "xgboost", ".", "DMatrix", "as", "input", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L648-L661
[ "def", "save_binary", "(", "self", ",", "fname", ",", "silent", "=", "True", ")", ":", "_check_call", "(", "_LIB", ".", "XGDMatrixSaveBinary", "(", "self", ".", "handle", ",", "c_str", "(", "fname", ")", ",", "ctypes", ".", "c_int", "(", "silent", ")",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.set_group
Set group size of DMatrix (used for ranking). Parameters ---------- group : array like Group size of each group
python-package/xgboost/core.py
def set_group(self, group): """Set group size of DMatrix (used for ranking). Parameters ---------- group : array like Group size of each group """ _check_call(_LIB.XGDMatrixSetGroup(self.handle, c_array(ctypes.c_uint...
def set_group(self, group): """Set group size of DMatrix (used for ranking). Parameters ---------- group : array like Group size of each group """ _check_call(_LIB.XGDMatrixSetGroup(self.handle, c_array(ctypes.c_uint...
[ "Set", "group", "size", "of", "DMatrix", "(", "used", "for", "ranking", ")", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L735-L745
[ "def", "set_group", "(", "self", ",", "group", ")", ":", "_check_call", "(", "_LIB", ".", "XGDMatrixSetGroup", "(", "self", ".", "handle", ",", "c_array", "(", "ctypes", ".", "c_uint", ",", "group", ")", ",", "c_bst_ulong", "(", "len", "(", "group", ")...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.feature_names
Get feature names (column labels). Returns ------- feature_names : list or None
python-package/xgboost/core.py
def feature_names(self): """Get feature names (column labels). Returns ------- feature_names : list or None """ if self._feature_names is None: self._feature_names = ['f{0}'.format(i) for i in range(self.num_col())] return self._feature_names
def feature_names(self): """Get feature names (column labels). Returns ------- feature_names : list or None """ if self._feature_names is None: self._feature_names = ['f{0}'.format(i) for i in range(self.num_col())] return self._feature_names
[ "Get", "feature", "names", "(", "column", "labels", ")", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L821-L830
[ "def", "feature_names", "(", "self", ")", ":", "if", "self", ".", "_feature_names", "is", "None", ":", "self", ".", "_feature_names", "=", "[", "'f{0}'", ".", "format", "(", "i", ")", "for", "i", "in", "range", "(", "self", ".", "num_col", "(", ")", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.feature_names
Set feature names (column labels). Parameters ---------- feature_names : list or None Labels for features. None will reset existing feature names
python-package/xgboost/core.py
def feature_names(self, feature_names): """Set feature names (column labels). Parameters ---------- feature_names : list or None Labels for features. None will reset existing feature names """ if feature_names is not None: # validate feature name ...
def feature_names(self, feature_names): """Set feature names (column labels). Parameters ---------- feature_names : list or None Labels for features. None will reset existing feature names """ if feature_names is not None: # validate feature name ...
[ "Set", "feature", "names", "(", "column", "labels", ")", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L843-L874
[ "def", "feature_names", "(", "self", ",", "feature_names", ")", ":", "if", "feature_names", "is", "not", "None", ":", "# validate feature name", "try", ":", "if", "not", "isinstance", "(", "feature_names", ",", "str", ")", ":", "feature_names", "=", "[", "n"...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
DMatrix.feature_types
Set feature types (column types). This is for displaying the results and unrelated to the learning process. Parameters ---------- feature_types : list or None Labels for features. None will reset existing feature names
python-package/xgboost/core.py
def feature_types(self, feature_types): """Set feature types (column types). This is for displaying the results and unrelated to the learning process. Parameters ---------- feature_types : list or None Labels for features. None will reset existing feature na...
def feature_types(self, feature_types): """Set feature types (column types). This is for displaying the results and unrelated to the learning process. Parameters ---------- feature_types : list or None Labels for features. None will reset existing feature na...
[ "Set", "feature", "types", "(", "column", "types", ")", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L877-L913
[ "def", "feature_types", "(", "self", ",", "feature_types", ")", ":", "if", "feature_types", "is", "not", "None", ":", "if", "self", ".", "_feature_names", "is", "None", ":", "msg", "=", "'Unable to set feature types before setting names'", "raise", "ValueError", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.load_rabit_checkpoint
Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model.
python-package/xgboost/core.py
def load_rabit_checkpoint(self): """Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model. """ version = ctypes.c_int() _check_call(_LIB.XGBoosterLoadRabitCheckpoint( self.hand...
def load_rabit_checkpoint(self): """Initialize the model by load from rabit checkpoint. Returns ------- version: integer The version number of the model. """ version = ctypes.c_int() _check_call(_LIB.XGBoosterLoadRabitCheckpoint( self.hand...
[ "Initialize", "the", "model", "by", "load", "from", "rabit", "checkpoint", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1002-L1013
[ "def", "load_rabit_checkpoint", "(", "self", ")", ":", "version", "=", "ctypes", ".", "c_int", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterLoadRabitCheckpoint", "(", "self", ".", "handle", ",", "ctypes", ".", "byref", "(", "version", ")", ")", ")"...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.attr
Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist.
python-package/xgboost/core.py
def attr(self, key): """Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist. """ ...
def attr(self, key): """Get attribute string from the Booster. Parameters ---------- key : str The key to get attribute from. Returns ------- value : str The attribute value of the key, returns None if attribute do not exist. """ ...
[ "Get", "attribute", "string", "from", "the", "Booster", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1019-L1038
[ "def", "attr", "(", "self", ",", "key", ")", ":", "ret", "=", "ctypes", ".", "c_char_p", "(", ")", "success", "=", "ctypes", ".", "c_int", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterGetAttr", "(", "self", ".", "handle", ",", "c_str", "(", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.attributes
Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes.
python-package/xgboost/core.py
def attributes(self): """Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes. """ length = c_bst_ulong() sarr = ...
def attributes(self): """Get attributes stored in the Booster as a dictionary. Returns ------- result : dictionary of attribute_name: attribute_value pairs of strings. Returns an empty dict if there's no attributes. """ length = c_bst_ulong() sarr = ...
[ "Get", "attributes", "stored", "in", "the", "Booster", "as", "a", "dictionary", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1040-L1054
[ "def", "attributes", "(", "self", ")", ":", "length", "=", "c_bst_ulong", "(", ")", "sarr", "=", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char_p", ")", "(", ")", "_check_call", "(", "_LIB", ".", "XGBoosterGetAttrNames", "(", "self", ".", "handle"...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.set_attr
Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute.
python-package/xgboost/core.py
def set_attr(self, **kwargs): """Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute. """ for key, value in kwargs.items(): if value is not None: if n...
def set_attr(self, **kwargs): """Set the attribute of the Booster. Parameters ---------- **kwargs The attributes to set. Setting a value to None deletes an attribute. """ for key, value in kwargs.items(): if value is not None: if n...
[ "Set", "the", "attribute", "of", "the", "Booster", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1056-L1070
[ "def", "set_attr", "(", "self", ",", "*", "*", "kwargs", ")", ":", "for", "key", ",", "value", "in", "kwargs", ".", "items", "(", ")", ":", "if", "value", "is", "not", "None", ":", "if", "not", "isinstance", "(", "value", ",", "STRING_TYPES", ")", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.set_param
Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key
python-package/xgboost/core.py
def set_param(self, params, value=None): """Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key...
def set_param(self, params, value=None): """Set parameters into the Booster. Parameters ---------- params: dict/list/str list of key,value pairs, dict of key to value or simply str key value: optional value of the specified parameter, when params is str key...
[ "Set", "parameters", "into", "the", "Booster", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1072-L1087
[ "def", "set_param", "(", "self", ",", "params", ",", "value", "=", "None", ")", ":", "if", "isinstance", "(", "params", ",", "Mapping", ")", ":", "params", "=", "params", ".", "items", "(", ")", "elif", "isinstance", "(", "params", ",", "STRING_TYPES",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.eval
Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current iteration number. Returns ------- res...
python-package/xgboost/core.py
def eval(self, data, name='eval', iteration=0): """Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current ite...
def eval(self, data, name='eval', iteration=0): """Evaluate the model on mat. Parameters ---------- data : DMatrix The dmatrix storing the input. name : str, optional The name of the dataset. iteration : int, optional The current ite...
[ "Evaluate", "the", "model", "on", "mat", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1185-L1205
[ "def", "eval", "(", "self", ",", "data", ",", "name", "=", "'eval'", ",", "iteration", "=", "0", ")", ":", "self", ".", "_validate_features", "(", "data", ")", "return", "self", ".", "eval_set", "(", "[", "(", "data", ",", "name", ")", "]", ",", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.predict
Predict with data. .. note:: This function is not thread safe. For each booster object, predict can only be called from one thread. If you want to run prediction using multiple thread, call ``bst.copy()`` to make copies of model object and then call ``predict()``. .. not...
python-package/xgboost/core.py
def predict(self, data, output_margin=False, ntree_limit=0, pred_leaf=False, pred_contribs=False, approx_contribs=False, pred_interactions=False, validate_features=True): """ Predict with data. .. note:: This function is not thread safe. For each boost...
def predict(self, data, output_margin=False, ntree_limit=0, pred_leaf=False, pred_contribs=False, approx_contribs=False, pred_interactions=False, validate_features=True): """ Predict with data. .. note:: This function is not thread safe. For each boost...
[ "Predict", "with", "data", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1207-L1314
[ "def", "predict", "(", "self", ",", "data", ",", "output_margin", "=", "False", ",", "ntree_limit", "=", "0", ",", "pred_leaf", "=", "False", ",", "pred_contribs", "=", "False", ",", "approx_contribs", "=", "False", ",", "pred_interactions", "=", "False", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.save_model
Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To preserve all attributes, pickle the Booster object. ...
python-package/xgboost/core.py
def save_model(self, fname): """ Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To pre...
def save_model(self, fname): """ Save the model to a file. The model is saved in an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be saved. To pre...
[ "Save", "the", "model", "to", "a", "file", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1316-L1333
[ "def", "save_model", "(", "self", ",", "fname", ")", ":", "if", "isinstance", "(", "fname", ",", "STRING_TYPES", ")", ":", "# assume file name", "_check_call", "(", "_LIB", ".", "XGBoosterSaveModel", "(", "self", ".", "handle", ",", "c_str", "(", "fname", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.load_model
Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be loaded. To preserve all attributes, pickle the Booster ob...
python-package/xgboost/core.py
def load_model(self, fname): """ Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be loaded. ...
def load_model(self, fname): """ Load the model from a file. The model is loaded from an XGBoost internal binary format which is universal among the various XGBoost interfaces. Auxiliary attributes of the Python Booster object (such as feature_names) will not be loaded. ...
[ "Load", "the", "model", "from", "a", "file", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1350-L1371
[ "def", "load_model", "(", "self", ",", "fname", ")", ":", "if", "isinstance", "(", "fname", ",", "STRING_TYPES", ")", ":", "# assume file name, cannot use os.path.exist to check, file can be from URL.", "_check_call", "(", "_LIB", ".", "XGBoosterLoadModel", "(", "self",...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.dump_model
Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls whether the split statistics are output. ...
python-package/xgboost/core.py
def dump_model(self, fout, fmap='', with_stats=False, dump_format="text"): """ Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. ...
def dump_model(self, fout, fmap='', with_stats=False, dump_format="text"): """ Dump model into a text or JSON file. Parameters ---------- fout : string Output file name. fmap : string, optional Name of the file containing feature map names. ...
[ "Dump", "model", "into", "a", "text", "or", "JSON", "file", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1373-L1406
[ "def", "dump_model", "(", "self", ",", "fout", ",", "fmap", "=", "''", ",", "with_stats", "=", "False", ",", "dump_format", "=", "\"text\"", ")", ":", "if", "isinstance", "(", "fout", ",", "STRING_TYPES", ")", ":", "fout", "=", "open", "(", "fout", "...
253fdd8a42d5ec6b819788199584d27bf9ea6253
train
Booster.get_dump
Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls whether the split statistics are output. dump_format : string, optional ...
python-package/xgboost/core.py
def get_dump(self, fmap='', with_stats=False, dump_format="text"): """ Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls w...
def get_dump(self, fmap='', with_stats=False, dump_format="text"): """ Returns the model dump as a list of strings. Parameters ---------- fmap : string, optional Name of the file containing feature map names. with_stats : bool, optional Controls w...
[ "Returns", "the", "model", "dump", "as", "a", "list", "of", "strings", "." ]
dmlc/xgboost
python
https://github.com/dmlc/xgboost/blob/253fdd8a42d5ec6b819788199584d27bf9ea6253/python-package/xgboost/core.py#L1408-L1453
[ "def", "get_dump", "(", "self", ",", "fmap", "=", "''", ",", "with_stats", "=", "False", ",", "dump_format", "=", "\"text\"", ")", ":", "length", "=", "c_bst_ulong", "(", ")", "sarr", "=", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_char_p", ")", ...
253fdd8a42d5ec6b819788199584d27bf9ea6253