# Using Kriging POD model

**URL:** <https://openturns.discourse.group/t/using-kriging-pod-model/241>\
**Category:** Python usage\
**Created:** [September 24, 2022, 1:53am UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241 "2022-09-24T01:53:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnkhanh](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://openturns.discourse.group/u/cnkhanh)\
**Post date:** [September 24, 2022, 1:53am UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/1 "2022-09-24T01:53:48Z")

</div>

After run the Kriging POD model as in this example [https://openturns.github.io/otpod/master/examples/krigingPOD.html](https://openturns.github.io/otpod/master/examples/krigingPOD.html)

How to save the model?  
Can I use this model to estimate the output value for new inputs? For example, I want to predict output value for an input like this “[4.5, 4.2, 1.1, 2.6]”

---

<div class="post-metadata">

**Author:** ![dumas](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/dumas/32/12_2.png) [@dumas](https://openturns.discourse.group/u/dumas)\
**Post date:** [September 26, 2022, 3:31pm UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/2 "2022-09-26T15:31:17Z")

</div>

Hello,

Indeed, there is not method that gives you the metamodel coming from the Kriging model.  
The KrigingPOD uses the Kriging class of openTURNS and you can get the KrigingResult object. And then from it, it is simple to get the metamodel to predict values for some specific inputs.  
However, we have added an initial transformation (only accessible through a private attribute) so the metamodel is not defined into the original space. To do a prediction, you should run this command :

```python
POD.getKrigingResult().getMetaModel()(POD._transformation([4.5, 4.2, 1.1, 2.6]))

```

Regards,  
Antoine

---

<div class="post-metadata">

**Author:** ![cnkhanh](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://openturns.discourse.group/u/cnkhanh)\
**Post date:** [September 27, 2022, 1:36am UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/3 "2022-09-27T01:36:21Z")

</div>

It works.  
Thank you so much 🙂

And another problem,  
Can I save the trained model? Because It took a lot of time when I trained the model with my own data.

---

<div class="post-metadata">

**Author:** ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)\
**Post date:** [September 27, 2022, 1:41pm UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/4 "2022-09-27T13:41:45Z")

</div>

Hello, you can use the “Study” class to save/load all OpenTURNS objects. Here is an example:

[https://openturns.github.io/openturns/latest/auto\_numerical\_methods/general\_methods/plot\_study\_save\_load.html](https://openturns.github.io/openturns/latest/auto_numerical_methods/general_methods/plot_study_save_load.html)

---

<div class="post-metadata">

**Author:** ![cnkhanh](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://openturns.discourse.group/u/cnkhanh)\
**Post date:** [September 28, 2022, 5:18am UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/5 "2022-09-28T05:18:40Z")

</div>

I tried this example before,

I can save the KrigingResults but I could not save the POD,  
Because when predicting output for the new input, it also needs the POD to transform input data according to KrigingPOD (POD.\_transformation())

```predicting
POD.getKrigingResult().getMetaModel()(POD._transformation([4.5, 4.2, 1.1, 2.6]))

```

**When I tried to save the POD,**

```auto
study.add('POD', POD)

```

## the error as below:

TypeError Traceback (most recent call last)  
Input In [36], in \<cell line: 1\>()  
----\> 1 study.add(‘POD’, POD)

File ~\AppData\Roaming\Python\Python39\site-packages\openturns\common.py:660, in Study.add(self, \*args)  
640 def add(self, \*args):  
641 r"“”  
642 Add an object to the study.  
643  
(…)  
658 otherwise.  
659 “”"  
 → 660 return \_common.Study\_add(self, \*args)

TypeError: Wrong number or type of arguments for overloaded function ‘Study\_add’.  
Possible C/C++ prototypes are:  
OT::Study::add(OT::InterfaceObject const &)  
OT::Study::add(OT::String const &,OT::InterfaceObject const &,OT::Bool)  
OT::Study::add(OT::String const &,OT::InterfaceObject const &)  
OT::Study::add(OT::PersistentObject const &)  
OT::Study::add(OT::String const &,OT::PersistentObject const &,OT::Bool)  
OT::Study::add(OT::String const &,OT::PersistentObject const &)

---

<div class="post-metadata">

**Author:** ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)\
**Post date:** [September 28, 2022, 1:14pm UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/6 "2022-09-28T13:14:24Z")

</div>

Ah yes, indeed the POD is not an OpenTURNS object and thus cannot be saved via the Study mechanism. However, if what you need in practice is the KrigingResult and the \_transformation, you could save them separately, because both are OpenTURNS objects (the \_transformation is simply an OpenTURNS [Function](https://openturns.github.io/openturns/latest/user_manual/_generated/openturns.Function.html)). Something like this:

```python
study.add('kriging_result', POD.getKrigingResult())
study.add('transformation', POD._transformation)
# ...

### Load study from save file ###
# ...
kriging_result = ot.KrigingResult()
transformation = ot.Function()
study.fillObject('kriging_result', kriging_result)
study.fillObject('transformation', transformation)

```

---

<div class="post-metadata">

**Author:** ![cnkhanh](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cnkhanh](https://openturns.discourse.group/u/cnkhanh)\
**Post date:** [September 30, 2022, 4:48am UTC](https://openturns.discourse.group/t/using-kriging-pod-model/241/7 "2022-09-30T04:48:07Z")

</div>

It works.  
Thank you so much 🥰
