def test_convert_input_dtype(from_dtype, to_dtype, input_type, num_rows, num_cols, order): if from_dtype == np.float16 and input_type != 'numpy': pytest.xfail("float16 not yet supported by numba/cuDF.from_gpu_matrix") if from_dtype in [np.uint8, np.uint16, np.uint32, np.uint64]: if input_type == 'cudf': pytest.xfail("unsigned int types not yet supported by \ cuDF") elif not has_cupy(): pytest.xfail("unsigned int types not yet supported by \ cuDF and cuPy is not installed.") input_data, real_data = get_input(input_type, num_rows, num_cols, from_dtype, out_dtype=to_dtype, order=order) if input_type == 'cupy' and input_data is None: pytest.skip('cupy not installed') converted_data = convert_dtype(input_data, to_dtype=to_dtype) if input_type == 'numpy': np.testing.assert_equal(converted_data, real_data) elif input_type == 'cudf': np.testing.assert_equal(converted_data.as_matrix(), real_data) elif input_type == 'pandas': np.testing.assert_equal(converted_data.to_numpy(), real_data) else: np.testing.assert_equal(converted_data.copy_to_host(), real_data)
def _treelite_fil_accuracy_score(y_true, y_pred): """Function to get correct accuracy for FIL (returns class index)""" # convert the input if necessary y_pred1 = (y_pred.copy_to_host() if cuda.devicearray.is_cuda_ndarray(y_pred) else y_pred) y_true1 = (y_true.copy_to_host() if cuda.devicearray.is_cuda_ndarray(y_true) else y_true) y_pred_binary = input_utils.convert_dtype(y_pred1 > 0.5, np.int32) return cuml.metrics.accuracy_score(y_true1, y_pred_binary)
def _treelite_fil_accuracy_score(y_true, y_pred): """Function to get correct accuracy for FIL (returns class index)""" y_pred_binary = input_utils.convert_dtype(y_pred > 0.5, np.int32) if isinstance(y_true, np.ndarray): return cuml.metrics.accuracy_score(y_true, y_pred_binary) elif cuda.devicearray.is_cuda_ndarray(y_true): y_true_np = y_true.copy_to_host() return cuml.metrics.accuracy_score(y_true_np, y_pred_binary) elif isinstance(y_true, cudf.Series): return cuml.metrics.accuracy_score(y_true, y_pred_binary) elif isinstance(y_true, pd.Series): return cuml.metrics.accuracy_score(y_true, y_pred_binary) else: raise TypeError("Received unsupported input type")