def test_deploy_python_model_reg(gen_reg_model_and_data): """ Ensure `ds_util.ml.pyspark.deploy_python_model` generates the desired prediction values """ df, model, X, y, truth_pred = gen_reg_model_and_data pred = deploy_python_model(df, model, id_cols=['id'], predict_method="predict") assert np.abs(pred.groupBy().sum().collect()[0]['sum(pred_1)'] - float(truth_pred.sum())) <= 0.00001
def test_deploy_python_model_class(gen_class_model_and_data): """ Ensure `ds_util.ml.pyspark.deploy_python_model` generates the desired prediction values """ df, model, X, y, truth_pred = gen_class_model_and_data pred_names = list(load_iris().target_names) pred = deploy_python_model(df, model, id_cols=['id'], pred_names=pred_names, predict_method="predict_proba") assert np.abs(pred.groupBy().sum().collect()[0]['sum(setosa)'] - float(truth_pred[:, 0].sum())) <= 0.00001
def test_deploy_python_model_missing_id_exception(gen_class_model_and_data): df, model, X, y, truth_pred = gen_class_model_and_data with pytest.raises(Exception): deploy_python_model(df, model, id_cols=['not_an_id'])
def test_deploy_python_model_wrong_predict_method_exception( gen_class_model_and_data): df, model, X, y, truth_pred = gen_class_model_and_data with pytest.raises(Exception): deploy_python_model(df, model, predict_method='not_a_predict_method')
def test_deploy_python_model_input_col_exception(gen_class_model_and_data): df, model, X, y, truth_pred = gen_class_model_and_data with pytest.raises(Exception): deploy_python_model(df, model, input_cols=['not_a_column'])