I have a dataset which I have loaded as a data frame in Python. It consists of 21392 rows (the data instances, each row is one sample) and 1972 columns (the features). The last column i.e. column 1972 has string type labels (14 different categories of target labels). I would like to use a CNN to classify the data in this case and predict the target labels using the available features. This is a somewhat unconventional approach though it seems possible. However, I am very confused on how the methodology should be as I could not find any sample code/ pseudo code guiding on using CNN for Classifying non-image data, either in Tensorflow or Keras. Any help in this regard will be highly appreciated. Cheers!
3 Answers
You can use CNN on any data, but it's recommended to use CNN only on data that have spatial features (It might still work on data that doesn't have spatial features, see DuttaA's comment below).
For example, in the image, the connection between pixels in some area gives you another feature (e.g. edge) instead of a feature from one pixel (e.g. color). So, as long as you can shaping your data, and your data have spatial features, you can use CNN.
For Text classification, there are connections between characters (that form words) so you can use CNN for text classification in character level.
For Speech recognition, there is also a connection between frequencies from one frame with some previous and next frames, so you can also use CNN for speech recognition.
If your data have spatial features, just reshape it to a 1D array (for example in text) or 2D array (for example in Audio). Tensorflow's function conv1d and conv2d are general function that can be used on any data. It look the data as an array of floating-point, not as image/audio/text.
But if your data doesn't have spatial features, for example, your features are price
, salary
, status_marriage
, etc. I think you don't need CNN, and using CNN won't help.
-
$\begingroup$ It still might work without spatial features considering CNN s NNs are just a special case of CNNs. $\endgroup$– user9947Commented Feb 8, 2019 at 10:49
-
$\begingroup$ hmm that's true, that's why I said "it's recommended to use CNN only on data that have spatial features", I think I'll add your comment to give more emphasis $\endgroup$ Commented Feb 8, 2019 at 22:05
-
$\begingroup$ @DuttaA I think "CNNs are just a special case of NNs" would be more correct. Unless you're thinking of 1x1 convolutions of a 1x1 input "image" of 1972 "channels".. $\endgroup$ Commented Feb 12, 2019 at 4:20
-
1$\begingroup$ @tsbertalan CNN literature specify filter size, stride, etc. If filter size=image size then it is a NN (by NN I mean a fully connected NN). Otherwise speaking rnn, CNN are all NN's. Here I meant a FCNN by NN. $\endgroup$– user9947Commented Feb 12, 2019 at 5:54
-
$\begingroup$ @DuttA Yeah, I guess if filter size=image size, and you use "valid" padding, the output will be 1x1xM, after which further convolutions will just be 1x1xN, then 1x1xO, etc as I said, where M, N, O, etc. are equivalent to the widths of successive layers in a normal MLP. I mentioned 1x1 convolutions since this is a common way that MLP-like results are achieved with CNNs pointwise (e.g. in fully-convolutional NNs). $\endgroup$ Commented Feb 18, 2019 at 23:02
The convolutional models are a method of choice when your problem is translation invariant (or covariant). In image classification, the image should be classified into class 'cow' if a cow is present in any part of the image. In text classification, different orders of phrases and sentences result in related meaning. In speech recognition, the same syllable is used at different places to build different words.
In your problem, you should check whether some subsequences of your 1791 columns give rise to the same meaning although they are located at different places within the sample. If the answer is positive, then convolutional layers are likely going to improve the performance.
DeepInsight method has been used for converting tabular data into corresponding images which are then processed by CNN. Here is the link https://alok-ai-lab.github.io/DeepInsight/