0

Has anyone defined a spline function (i.e. defineFuction) in PMML?

There is quite a few parameters that need to be defined, with a fairly lengthy math. For example, for a predictor with a 3-knot restrictive cubic spline, I have seven parameters (including two coefficients, three knots, one reference point and one predictor name). The math includes a bit of exponential, max statements, etc.

Here is an example of my Javascript code to calculate the value from a 3-knot RCS.

   function spline3(exp_value, exp_mean, exp_coef, exp_coef1, knot1, knot2, knot3) {
   var step1 = exp_coef*(exp_value-exp_mean);
   var step2 = Math.pow((knot3 - knot1),(2/3));
   var step3 = Math.pow(Math.max((exp_value - knot1)/step2,0), 3);
   var step4 = ((knot2 - knot1) * Math.pow(Math.max((exp_value - knot3)/step2,0), 3));
   var step5 = (knot3 - knot1) * Math.pow(Math.max((exp_value - knot2)/ step2 ,0), 3);
   var step6 = (knot3 - knot2);
   var output = (step3 + step4 - step5/step6) * exp_coef1 + step1;

   return output  ;
}
  • Where do the values of function arguments (`exp_value`, `exp_mean`, ..., `knot3`) come from? I'm not an expert of 3-knot RCS, so I is it correct to assume that only `exp_value` is related to the current prediction, whereas all others are constants that were determined during model training? If so, then it would be possible to generate a simplified version of this function for every single model. – user1808924 Dec 17 '15 at 17:35
  • Yes, exactly. Only `exp_value` is the variable input for the RCS function. All other parameters are defined during model development. So, all the parameters are defined within PMML and `exp_value` would not be defined. What I have defined as `exp_code` are usually defined as `coefficient` in PMML. I am wondering if anyone has seen the full version of PMML that describe the generic RCS function. – Doug Manuel Dec 17 '15 at 18:04
  • If you know the values of constants `knot1`, `knot2` and `knot3`, then you can pre-compute the values of `step2` and `step6` variables. Then, you need to define a reusable function for the expression `Math.pow(Math.max((exp_value - knotX)/step2,0), 3)`. After that, it's just a matter of expressing the `output` variable using those new constructs. – user1808924 Dec 17 '15 at 20:53
  • Basically, you would need a small utility that would automate the generation of this PMML snippet. It all depends on what's in your toolbox. If you're familiar with Java, then it could be implemented using the JPMML-Model library rather easily. – user1808924 Dec 17 '15 at 20:56
  • Spline functions are pretty common, so I was hoping that someone has already created the snippet (definition). If fact, I can't find too many snippets or definitions for many functions that we commonly use in our field of health care and survival models. Not sure if I am just not looking in the right places. – Doug Manuel Dec 17 '15 at 21:45

0 Answers0