I am working on binary classification of imbalanced dataset.The dataset contains 777 minority classes and 2223 majority classes.I have built a one class SVM model with only minority labelled records.BUt when I am trying to predict on the built model,I am getting predicted values as all -1 and hence accuracy as 0.I have scaled my features. Here's my implementation
ml_file_df = pd.read_csv('/data/jayashree/3000_ML_features.csv')
minority_df = ml_file_df[ml_file_df['RESULT'] == 0]
array = minority_df.values
features = array[:, 0:60630]
labels = array[:, 60630]
scaler = MinMaxScaler()
scaled_features = scaler.fit_transform(features)
features_train, features_test, labels_train, labels_test = train_test_split(
scaled_features, labels, test_size=0.3, random_state=10)
gamma_values = [0.001, 0.005, 0.01, 0.05, 0.1, 0.5]
nu_values = [0.1, 0.3, 0.5, 0.7]
for j in nu_values:
for i in gamma_values:
clf = svm.OneClassSVM(nu=j, kernel='rbf', gamma=i)
clf.fit(features_train, labels_train)
pred = clf.predict(features_test)
print(i, classification_report(labels_test, pred))
For all the cases I am getting predictions like this
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 1 -1 -1 -1 -1 1]
Where am I going wrong?
I have resolved the error.One class svm will predict 1 or -1.I used minority class as 1 and majority class as -1.This solved my issue.