Question: I am using `svm.SVR()` from scikit-learn to apply Logistic Regression on my training data to solve a similarity problem. Using GridSearchCV, I am finding the best hyper parameters using the scoring as "R2". The best hyperparameters are `C=1, cache_size=200, coef0=0.0, degree=3, epsilon=0.001, gamma=0.005, kernel='rbf', shrinking=True, tol=0.001`.

I fit the training data and training label as `model.fit(X_train, Y_train)`

Now I use test data in the same model as: `prediction = model.predict(X_test)`

The reason I am using SVM-Regression is to find similarity between two inputs. However, for some of the test data, the prediction contains value in negative (less than 0) and for all the same vs same comparison it returns the value as 1.09469178. I am expecting the value to be between 0 and 1. Is this normal or am I doing something wrong?

Answer: 
> 
> I am using svm.SVR() from scikit-learn to apply Logistic Regression on my training data to solve similarity problem.
> 
> 
> 

Wait a second, if you're using support-vector regression, then you're *not* using logistic regression. These two are very different algorithms. They aren't even applicable to the same type of problem. Support-vector regression is used when you are predicting a continuous target, whereas logistic regression (despite the name) is a classification algorithm.

> 
> However, for some of the test data, the prediction contains value in negative (less than 0) and for all the same vs same comparison it returns the value as 1.09469178.
> 
> 
> 

There's nothing unusual about this if you're using support-vector regression. A support-vector machine can (in theory) output any real number.

Logistic regression, on the other hand, is a [sigmoid function](https://en.wikipedia.org/wiki/Sigmoid_function). It will take as input any real number and output a result between 0 and 1. Maybe you meant to use scikit's [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) model rather than SVR?

> 
> The reason I am using SVM-Regression is to find similarity between two inputs.
> 
> 
> 

Could you expound on your use-case a bit more? Support-vector regression isn't really meant to be used to compute similarity.

I'm speculating that you have a training set of (X, y) pairs (where y is a label between 0 and 1). You are training a model to output $\hat{y}$, a prediction of y. To find the similarity of two inputs, $X\_i$ and $X\_j$, you pass them both through the model and measure the difference in the $\hat{y}\_i$ and $\hat{y}\_j$. Is that right?

If so, I think this is a really roundabout way of computing similarity, and is unlikely to yield better results than a more straightforward method. I'm not sure that you need a machine learning algorithm at all.

Have you looked into other similarity metrics that might be suitable for your problem? For similarity based on Euclidean distance, you can compute $\frac{1}{1 + d(X\_i, X\_j)}$ (where $d$ is the euclidean distance function). [Cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) might be a good choice if you care more about the similarity in direction of two input vectors.
This is normal: unless your training data covers the population very well, the test set is bound to contain instances which slightly deviate from the cases seen in the training data. With any regression method, this might cause predicted values to go slightly out of range. If the application requires normalized values, these deviations should be programmatically corrected post-process (i.e. anything negative changed to 0 and anything higher than 1 changed to 1).