title: What type of orthogonal polynomials does R use?
body: <p>I was trying to match the orthogonal polynomials in the following code in R:</p>
  
  <pre><code>X &lt;- cbind(1, poly(x = x, degree = 9))
  </code></pre>
  
  <p>but in python. </p>
  
  <p>To do this I implemented my own method for giving orthogonal polynomials:</p>
  
  <pre><code>def get_hermite_poly(x,degree):
      #scipy.special.hermite()
      N, = x.shape
      ##
      X = np.zeros( (N,degree+1) )
      for n in range(N):
          for deg in range(degree+1):
              X[n,deg] = hermite( n=deg, z=float(x[deg]) )
      return X
  </code></pre>
  
  <p>though it does not seem to match it. Does someone know type of orthogonal polynomial it uses? I tried search in the documentation but didn't say.</p>
  
  <hr>
  
  <p>To give some context I am trying to implement the following R code in python (<a href="https://stats.stackexchange.com/questions/313265/issue-with-convergence-with-sgd-with-function-approximation-using-polynomial-lin/315185#comment602020_315185">https://stats.stackexchange.com/questions/313265/issue-with-convergence-with-sgd-with-function-approximation-using-polynomial-lin/315185#comment602020_315185</a>):</p>
  
  <pre><code>set.seed(1234)
  
  N &lt;- 10
  x &lt;- seq(from = 0, to = 1, length = N)
  mu &lt;- sin(2 * pi * x * 4)
  y &lt;- mu
  plot(x,y)
  
  X &lt;- cbind(1, poly(x = x, degree = 9))
  # X &lt;- sapply(0:9, function(i) x^i)
  w &lt;- rnorm(10)
  
  learning_rate &lt;- function(t) .1 / t^(.6)
  
  n_samp &lt;- 2
  for(t in 1:100000) {
    mu_hat &lt;- X %*% w
    idx &lt;- sample(1:N, n_samp)
    X_batch &lt;- X[idx,]
    y_batch &lt;- y[idx]
    score_vec &lt;- t(X_batch) %*% (y_batch - X_batch %*% w)
  
    change &lt;- score_vec * learning_rate(t)
    w &lt;- w + change
  }
  
  plot(mu_hat, ylim = c(-1, 1))
  lines(mu)
  fit_exact &lt;- predict(lm(y ~ X - 1))
  lines(fit_exact, col = 'red')
  abs(w - coef(lm(y ~ X - 1)))
  </code></pre>
  
  <p>because it seems to be the only one that works with gradient descent with linear regression with polynomial features. </p>
  
  <p>I feel that any orthogonal polynomial (or at least orthonormal) should work and give a hessian with condition number 1 but I can't seem to make it work in python. Related question: <a href="https://stackoverflow.com/questions/47624798/how-does-one-use-hermite-polynomials-with-stochastic-gradient-descent-sgd">How does one use Hermite polynomials with Stochastic Gradient Descent (SGD)?</a></p>