title: How can I replace svm.SVR 'rbf' kernel in sklearn using my own RBF function?
body: <p>I have developed the code below for starting a project for svm method:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  from sklearn import svm
  from sklearn.datasets import load_boston
  from sklearn.metrics import mean_absolute_error
  
  housing = load_boston()
  df = pd.DataFrame(np.c_[housing['data'], housing['target']],
                columns= np.append(housing['feature_names'], ['target']))
  
  features = df.columns.tolist()
  label = features[-1]
  features = features[:-1]
  
  x_train = df[features].iloc[:400]
  y_train = df[label].iloc[:400]
  
  x_test = df[features].iloc[400:]
  y_test = df[label].iloc[400:]
  
  svr = svm.SVR(kernel='rbf')
  svr.fit(x_train, y_train)
  y_pred = svr.predict(x_test)
  
  print(mean_absolute_error(y_pred, y_test))
  </code></pre>
  
  <p>Now I want to use my customized rbf kernel which is:</p>
  
  <pre><code>def my_rbf(feat, lbl):
  #feat = feat.values
      #lbl = lbl.values
      ans = np.array([])
      gamma = 0.000005
      for i in range(len(feat)):
          ans = np.append(ans, np.exp(-gamma * np.dot(feat[i]-lbl[i], feat[i]-lbl[i])))
  
      return ans
  </code></pre>
  
  <p>Then I changed <code>svm.SVR(kernel=my_rbf)</code> But I get plenty of errors while modifying it in any way. I also tried to use a simple function like <code>np.dot(feat-lbl,feat-lbl)</code> which worked fine in <code>SVR.fit</code> method but in <code>svr.predict</code> some error occurred which said that shape of input matrix has to be like [n_samples_test, n_samples_train]. </p>
  
  <p>I'm stymied to deal with the errors. Can anyone help me make this code work?</p>