MCPcopy
hub / github.com/linkedin/greykite / valid_elements_for_evaluation

Function valid_elements_for_evaluation

greykite/common/evaluation.py:74–160  ·  view source on GitHub ↗

Keeps finite elements from reference_array, and corresponding elements in *arrays. Parameters ---------- reference_arrays : `list` [`numpy.array`, `pandas.Series` or `list` [`int`, `float`]] The reference arrays where the indices of NA/infs are populated. If length is lo

(
        reference_arrays: List[Union[np.array, pd.Series, List[Union[int, float]]]],
        arrays: List[Optional[Union[int, float, np.array, pd.Series, List[Union[int, float]]]]],
        reference_array_names: str,
        drop_leading_only: bool,
        keep_inf: bool)

Source from the content-addressed store, hash-verified

72
73
74def valid_elements_for_evaluation(
75 reference_arrays: List[Union[np.array, pd.Series, List[Union[int, float]]]],
76 arrays: List[Optional[Union[int, float, np.array, pd.Series, List[Union[int, float]]]]],
77 reference_array_names: str,
78 drop_leading_only: bool,
79 keep_inf: bool):
80 """Keeps finite elements from reference_array, and corresponding elements in *arrays.
81
82 Parameters
83 ----------
84 reference_arrays : `list` [`numpy.array`, `pandas.Series` or `list` [`int`, `float`]]
85 The reference arrays where the indices of NA/infs are populated.
86 If length is longer than 1, a logical and will be used to choose valid elements.
87 arrays : `list` [`int`, `float`, `numpy.array`, `pandas.Series` or `list` [`int`, `float`]]
88 The arrays with the indices of NA/infs in ``reference_array`` to be dropped.
89 reference_array_names : `str`
90 The reference array name to be printed in the warning.
91 drop_leading_only : `bool`
92 True means dropping the leading NA/infs only
93 (drop the leading indices whose values are not valid in any reference array).
94 False means dropping all NA/infs regardless of where they are.
95 keep_inf : `bool`
96 True means dropping NA only.
97 False means dropping both NA and INF.
98 Returns
99 -------
100 arrays_valid_elements : `list` [`numpy.array`]
101 List of numpy arrays with valid indices [*reference_arrays, *arrays]
102 """
103 if not all_equal_length(*reference_arrays, *arrays):
104 raise Exception("length of arrays do not match")
105
106 if len(reference_arrays) == 0:
107 return reference_arrays + arrays
108
109 reference_arrays = [np.array(reference_array) for reference_array in reference_arrays]
110 array_length = reference_arrays[0].shape[0]
111
112 # Defines a function to perform the opposite of `numpy.isnan`.
113 def is_not_nan(x):
114 """Gets the True/False for elements that are not/are NANs.
115
116 Parameters
117 ----------
118 x : array-like
119 The input array.
120
121 Returns
122 -------
123 is_not_nan : `numpy.array`
124 True/False array indicating whethere the elements are not NAN/ are NAN.
125 """
126 return ~np.isnan(x)
127
128 validation_func = is_not_nan if keep_inf else np.isfinite
129 # Finds the indices of finite elements in reference array
130 keep = [validation_func(reference_array) for reference_array in reference_arrays]
131 if drop_leading_only:

Callers 9

score_func_finiteFunction · 0.85
r2_null_model_scoreFunction · 0.85
calc_pred_errFunction · 0.85
fraction_within_bandsFunction · 0.85
prediction_band_widthFunction · 0.85
mean_interval_scoreFunction · 0.85
calc_pred_coverageFunction · 0.85

Calls 1

all_equal_lengthFunction · 0.85

Tested by 1