def test_gamma_regressor(self): model = GammaRegressor() X = np.array([[1, 2], [2, 3], [3, 4], [4, 3]]) y = np.array([19, 26, 33, 30]) model.fit(X, y) test_x = np.array([[1, 0], [2, 8]]) model_onnx = convert_sklearn( model, "scikit-learn Gamma Regressor", [("input", FloatTensorType([None, X.shape[1]]))], target_opset=TARGET_OPSET) self.assertIsNotNone(model_onnx) dump_data_and_model(test_x.astype(np.float32), model, model_onnx, basename="SklearnGammaRegressor")
# # Note: # # - We filter out ``ClaimAmount == 0`` as the Gamma distribution has support # on :math:`(0, \infty)`, not :math:`[0, \infty)`. # - We use ``ClaimNb`` as `sample_weight` to account for policies that contain # more than one claim. mask_train = df_train["ClaimAmount"] > 0 mask_test = df_test["ClaimAmount"] > 0 glm_sev = GammaRegressor(alpha=10.0, max_iter=10000) glm_sev.fit( X_train[mask_train.values], df_train.loc[mask_train, "AvgClaimAmount"], sample_weight=df_train.loc[mask_train, "ClaimNb"], ) scores = score_estimator( glm_sev, X_train[mask_train.values], X_test[mask_test.values], df_train[mask_train], df_test[mask_test], target="AvgClaimAmount", weights="ClaimNb", ) print("Evaluation of GammaRegressor on target AvgClaimAmount") print(scores)