0

Can I build a cnn in keras with only one class (class - 0) so it can predict if the given date belongs to this class? Thanks in advance

Edite :Thanks for the answer and comments so far. My data is acceleration time series from a healthy structure but I don't have access to damaged state acceleration signals, so I have only data for class 0.

zahra
  • 1
  • 1
  • 2
  • I think it should have two classes (class-0 and class-1). Suppose you train a model with single class, and later provided a data that doesn't belong to class-0, then the model has to predict it doesn't belong to class-0 right? So I think two classes need to be there. Please let me know what is your use case. Thanks! – Vishnuvardhan Janapati Apr 05 '20 at 23:08
  • If you want two class (binary classification) model, then check it [here](https://stackoverflow.com/a/61039478/9936228) – Vishnuvardhan Janapati Apr 05 '20 at 23:10

1 Answers1

0

I believe what you're describing is an anomaly detection model. Other ML models exist for this purpose, such as the one class support vector machine (https://scikit-learn.org/stable/modules/generated/sklearn.svm.OneClassSVM.html) and isolation forest (https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html). It's possible to implement a neural network, but you will need to have a customized loss function - as in, binary cross-entropy doesn't make sense for this application. One example of such a loss function is described here: https://arxiv.org/pdf/1802.06360.pdf which is based on the one class SVM.

I have an implementation of a one class fully connected network here in Keras: https://github.com/danielenricocahall/One-Class-NeuralNetwork which utilizes a loss function based on the one described in that paper, if that helps.

Good luck!

danielcahall
  • 2,672
  • 8
  • 14