I am doing a binary classification that only returns "yes" or "no" for the image. As I only got an image of one class, so I wanna classify between "Target" and " Outlier".
For example, I am classifying the fireman.
I am using Scikit Learn svm.OneClassSVM()
. However, after training the model, I got "-1" every time, even for predicting the training data.
Here is my code:
X_train = []
for subdir, dirs, files in os.walk("training"):
for imagePath in files:
print ("path = ", imagePath)
img = Image.open(os.path.join(subdir, imagePath))
img = img.resize(sample_size, PIL.Image.ANTIALIAS)
img = np.array(img)
img = img[:,:,0]
img = img.reshape(1, img.shape[0]* img.shape[1])
X_train.append(img[0])
clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.1)
clf.fit(X_train)
And then I predict the result of "training data"
print clf.predict (X_train)
However, I still get all "-1". Can anyone tell me what's wrong?
you can set the threshold level by calculating the score sample. For example
clf = OneClassSVM()
y_scores = clf.score_samples(test)
You need to check by yourself which threshold is better. You can check that by running the model on some data of abnormal class and check below which threshold are you getting your answer. The lesser the score sample the more outlier is that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With