# Error using pyMVA exxample

**URL:** <https://root-forum.cern.ch/t/error-using-pymva-exxample/40226>\
**Category:** TMVA\
**Created:** [July 3, 2020, 12:26pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226 "2020-07-03T12:26:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michele\_Selvaggi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele_selvaggi/32/22575_2.png) [@Michele\_Selvaggi](https://root-forum.cern.ch/u/Michele_Selvaggi)\
**Post date:** [July 3, 2020, 12:26pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/1 "2020-07-03T12:26:42Z")

</div>

Hello,

the RandomForest PyMVA method in this example is not found:

source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.20.06/x86\_64-centos7-gcc48-opt/bin/thisroot.sh  
root /afs/cern.ch/user/s/selvaggi/public/4Gerri/TMVAClassification.C

Thanks for your help  
Michele

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [July 3, 2020, 1:17pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/2 "2020-07-03T13:17:36Z")

</div>

Hi Michele,

It looks like the tutorial in the AFS folder comes from another ROOT version. If you try

```
root $ROOTSYS/tutorials/tmva/TMVAClassification.C

```

it should work.

Cheers,  
Jakob

---

<div class="post-metadata">

**Author:** ![Michele\_Selvaggi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele_selvaggi/32/22575_2.png) [@Michele\_Selvaggi](https://root-forum.cern.ch/u/Michele_Selvaggi)\
**Post date:** [July 3, 2020, 1:57pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/3 "2020-07-03T13:57:23Z")

</div>

Hi,

thanks for your reply.  
I must be doing something wrong, but including:

#include “TMVA/MethodPyRandomForest.h”

and calling:

if (Use[“RandomForest”]) // Allow Using random forest  
factory-\>BookMethod( dataloader, TMVA::Types::kPyRandomForest, “PyRandomForest”, “!V:NEstimators=100:Criterion=gini:MaxFeatures=auto:MaxDepth=6:MinSamplesLeaf=1:MinWeightFractionLeaf=0:Bootstrap=kTRUE” );

on the example you pointed gives the same error:

/afs/cern.ch/user/s/selvaggi/public/TMVAClassification.C

Michele

---

<div class="post-metadata">

**Author:** ![jblomer](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/439d5e/32.png) [@jblomer](https://root-forum.cern.ch/u/jblomer)\
**Post date:** [July 3, 2020, 3:43pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/4 "2020-07-03T15:43:11Z")

</div>

Hm, perhaps @moneta can help?

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [July 6, 2020, 12:36pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/5 "2020-07-06T12:36:01Z")

</div>

Hi,

If you have built wROOT with support for PyMVA, you need also to call at the beginning

```auto
TMVA::PyMethodBase::PyInitialize();

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![Michele\_Selvaggi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele_selvaggi/32/22575_2.png) [@Michele\_Selvaggi](https://root-forum.cern.ch/u/Michele_Selvaggi)\
**Post date:** [July 6, 2020, 1:09pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/6 "2020-07-06T13:09:10Z")

</div>

Hi,

thanks, I get another error now:

source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.20.06/x86\_64-centos7-gcc48-opt/bin/thisroot.sh  
root /afs/cern.ch/user/s/selvaggi/public/Classification.C

> > ImportError: No module named sklearn.ensemble  
> > : Failed to run python code

not sure if I should install and link something myself, but was assuming this was already done, since:

> root-config --features

shows:

cxx11 asimage builtin\_afterimage builtin\_clang builtin\_davix builtin\_ftgl builtin\_gl2ps builtin\_glew builtin\_llvm builtin\_lz4 builtin\_lzma builtin\_pcre builtin\_tbb builtin\_unuran builtin\_vdt builtin\_veccore builtin\_xrootd builtin\_xxhash builtin\_zlib clad dataframe davix exceptions fftw3 fitsio fortran gdml http imt mathmore mlp minuit2 mysql opengl pgsql pyroot roofit runtime\_cxxmodules shadowpw shared soversion sqlite ssl tmva tmva-cpu tmva-pymva spectrum unuran vmc vdt veccore x11 xml xrootd

Thanks  
Michele

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [July 6, 2020, 1:24pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/7 "2020-07-06T13:24:18Z")

</div>

Hi Michele,

You need also to have sklearn installed in your python environment.  
So if you do:

```auto
python
>>> import sklearn

```

it should work. If not, you need to install it (e.g. by doing `pip install sklearn`)

Lorenzo

---

<div class="post-metadata">

**Author:** ![Michele\_Selvaggi](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/michele_selvaggi/32/22575_2.png) [@Michele\_Selvaggi](https://root-forum.cern.ch/u/Michele_Selvaggi)\
**Post date:** [July 6, 2020, 1:55pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/8 "2020-07-06T13:55:59Z")

</div>

> [@moneta](#):
>
> `TMVA::PyMethodBase::PyInitialize();`

Thanks Lorenzo,

in case other people might need it, posting here a recipe that works for me on lxplus (despite inconsistency in architecture):

source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.20.06/x86\_64-centos7-gcc48-opt/bin/thisroot.sh  
source /cvmfs/sft.cern.ch/lcg/releases/LCG\_88/scikitlearn/0.17.1/x86\_64-slc6-gcc49-opt/scikitlearn-env.sh

It would be great to have access to RMVA bindings as well in the future!

Thanks  
Michele

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [July 6, 2020, 2:07pm UTC](https://root-forum.cern.ch/t/error-using-pymva-exxample/40226/9 "2020-07-06T14:07:41Z")

</div>

@omazapa might know more if the R packages needed for RMVA are available in cvmfs
