title: How to save a logit model in R and import it in Python?
body: <p>I need to train a glm model in R 3.6 and import it in Python 3.7 to make predictions.</p>
  
  <p>As a proof of concept I borrowed this code from <a href="https://stats.stackexchange.com/questions/46523/how-to-simulate-artificial-data-for-logistic-regression/46525">https://stats.stackexchange.com/questions/46523/how-to-simulate-artificial-data-for-logistic-regression/46525</a></p>
  
  <pre><code>set.seed(666)
  x1 = rnorm(1000)           # some continuous variables 
  x2 = rnorm(1000)
  z = 1 + 2*x1 + 3*x2        # linear combination with a bias
  pr = 1/(1+exp(-z))         # pass through an inv-logit function
  y = rbinom(1000,1,pr)      # bernoulli response variable
  #now feed it to glm:
  df = data.frame(y=as.factor(y), x1=x1, x2=x2)
  my_model = glm(y~x1+x2, data=df, family=binomial(link = 'logit'))
  </code></pre>
  
  <p>I can save the R model in PMML format, but there is no Python library to import it:</p>
  
  <pre><code>library(r2pmml)
  r2pmml(my_model, "my_model.pmml")
  </code></pre>
  
  <p>so this is not a solution.</p>
  
  <p>I read that I can export the R model in <code>pickle</code> format, but when I try to do this using the <code>reticulate</code> library:</p>
  
  <pre><code>package.install(reticulate)
  library(reticulate)
  use_python("/opt/anaconda3/bin/python")
  py_save_object(my_model, "my_model")
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
  <pre><code>Error in py_call_impl(callable, dots$args, dots$keywords) :
        Evaluation error: Evaluation error: Unable to convert R object to Python type..
  </code></pre>
  </blockquote>
  
  <p>Any idea how I can get around this problem?</p>