pedophysics.utils package¶
Submodules¶
pedophysics.utils.similar_arrays module¶
- pedophysics.utils.similar_arrays.arrays_are_similar(array1, array2, tol=1e-05)[source]¶
Check if two numpy arrays are similar with a given tolerance.
Parameters
array1 (numpy.ndarray): The first array to compare. array2 (numpy.ndarray): The second array to compare. tol (float): The tolerance for the comparison. Default is 1e-5.
- Returns:
Returns True if the arrays are considered similar, otherwise False.
- Return type:
bool
Example
>>> a = np.array([1.0, 2.0, np.nan, 4.0]) >>> b = np.array([0.999, 2.001, np.nan, 4.0])
>>> similar = arrays_are_similar(a, b)
pedophysics.utils.stats module¶
- pedophysics.utils.stats.R2_score(actual, predicted)[source]¶
Calculate the coefficient of determination (R^2) of a prediction.
The R^2 score function computes the coefficient of determination, often used to evaluate the performance of a regression model. The best possible score is 1.0. This function is designed to handle arrays with NaN values by ignoring such entries.
- Parameters:
actual (array-like of shape (n_samples,)) – Ground truth (correct) target values.
predicted (array-like of shape (n_samples,)) – Estimated targets as returned by a classifier.
- Returns:
R^2 of the prediction.
- Return type:
float
Notes
This function works with arrays that include NaN values, ignoring such entries during the computation. Therefore, ‘actual’ and ‘predicted’ arrays can have missing values, but they must be of the same shape.
Example
>>> actual = np.array([3, -0.5, 2, 7, 4.2]) >>> predicted = np.array([2.5, 0.0, 2.1, 7.8, 5.3]) >>> R2_score(actual, predicted) 0.9228556485355649