Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: support one-class svm pridict probability #67

Closed
yjhjstz opened this issue Jul 14, 2016 · 11 comments
Closed

feature request: support one-class svm pridict probability #67

yjhjstz opened this issue Jul 14, 2016 · 11 comments

Comments

@yjhjstz
Copy link

yjhjstz commented Jul 14, 2016

I need to probability of one-class svm.

please consider, thanks.

@yjhjstz yjhjstz changed the title feture request: support one-class svm pridict probability feature request: support one-class svm pridict probability Jul 14, 2016
@cjlin1
Copy link
Owner

cjlin1 commented Jul 14, 2016

We don't have that yet.. You can use decision values to get
prob outputs but it's unclear yet if the result is good..
Jianghua.yjh writes:

I need to probability of one-class svm, thanks.

please consider.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the
thread.*

@yjhjstz
Copy link
Author

yjhjstz commented Jul 14, 2016

decision values are always the same, I need to know every predict data probability result .

@abhikr360
Copy link

Hi,
I also need probabilities in one class SVM for my project. Previous request request was made 2 years ago but the feature wasn't implemented.

Please consider, Thanks

@lbraga
Copy link

lbraga commented Jan 5, 2019

Hi,
with one-class you can use 'svm_predict_values' function and get 'x' decision value. It's not probability, but maybe it could be useful.

See

libsvm/svm.cpp

Line 2577 in 3648ef3

double svm_predict(const svm_model *model, const svm_node *x)

@ghost
Copy link

ghost commented Jun 14, 2019

Any new methods?

@mattsliv
Copy link

mattsliv commented Feb 11, 2020

You can use Platt Scalling to create a probability distribution from the outputs of your one-class SVM.

Essentially, it fits a logistic regression model with cross-validation on your one-class SVM predictions to get the probability values you would normally get with the predict_proba(X) function.

Let oc_svm be your one-class SVM and X be the data you fitted oc_svm on. To get the probability estimates you are looking for, you can do something like this.

# Imports
from sklearn.linear_model import LogisticRegressionCV as LRCV
from sklearn.model_selection import train_test_split

def platt_scale(oc_svm, X, train_size, cv_size):
	# Get SVM predictions
	y_pred = oc_svm_.predict(X)
		
	# Split the data and SVM labels
	X_train, _, y_train, _ = train_test_split(X, y_pred, train_size=train_size)

	# Train using logistic regression with cross-validation 
	lr = LRCV(cv=cv_size)
	lr.fit(X_train, y_train)

	return lr.predict_proba(X)

@Al-Murphy
Copy link

@mattsliv, sorry to dig this thread up but did you implement that approach you have written above? I tried to take a similar approach in R but it would appear the cross-validated logistic regression model applied to the results of the one-class svm separates the data perfectly so I get probabilities extremely close to 0 or 1. I have a stackoverflow post showing a nice visual of my issue.

@mattsliv
Copy link

mattsliv commented May 20, 2020

@Al-Murphy If the probabilities values are very close to 0 or 1, it could mean that the variance of error of your classification is very low. With reference to the image in your StackOverflow post, this might be the case since your actual data is easily separable. Maybe try it on data that has some higher error variance?

I would like to note though, the project I was using this for changed and is not needed so I have not been using this on various amounts of data.

@mattsliv, sorry to dig this thread up but did you implement that approach you have written above? I tried to take a similar approach in R but it would appear the cross-validated logistic regression model applied to the results of the one-class svm separates the data perfectly so I get probabilities extremely close to 0 or 1. I have a stackoverflow post showing a nice visual of my issue.

@aminadibi
Copy link

Sad to see this useful feature is still not implemented 7 years after the initial request.

@cjlin1
Copy link
Owner

cjlin1 commented May 25, 2023

One-class svm prob outputs were introduced in version 3.3 in August 2022. Sorry for the delay.

@cjlin1 cjlin1 closed this as completed May 25, 2023
@aminadibi
Copy link

Fantastic! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants