# How to make a CNN predict a continuous value?

I understand the dimensionality of convolutions, max pooling and dense as function of stride and kernel size. But I'm having trouble wrapping my head around how to use these layers to end up with my final prediction, which should be one continuous variable.

Here is what I'm working with:

• X training: n 2-channel 3D grids of size 46x46x46, shape: (n, 46, 46, 46, 2)

• Y training: n-element vector of continuous values, shape: (n,)

I would imagine there will be some resizing and some concatenation involved. But there's no point doing that if I don't actually understand what it's doing.

• I do not have enough reputation to add this as a comment so pardon me. My problem is the following: I have implemented a simple FNN feedforward network that is taking 90 inputs and is producing a continuous value as an output. Everything in the FNN looks like it works well, but my task is to do a similar type of network using CNN. From what I can think of is I will input my 90 features as 9x10 matrix and from here all becomes unclear. I do not know how to make the CONV and the POL layers and how many they should be? Also, a big question is for me how make the last layer so it can give me a con
– Sim
Commented Jun 26, 2018 at 4:21

A common way to do this is flatten your output after your last convolution layer, and pass it through a fully connected layer.

What you need to do:

1. Ensure that your output vector for training and test data is exactly what you need, continuous for each element of output vector.
2. Use what you said and familiar for the layers before the last layer.
3. For the last layer use a dense layer with n, number of outputs, outputs each having linear activation, y = x.

You need to use linear regressor instead of logistic regressor. The difference between the two is, the latter is used to "classify" things whereas the former provides a continuous output as you require. In order to get

..."one continuous variable"...

you need to use for example KerasRegressor if you are using Keras. Similar functions exist in other systems like scikit-learn, caffe etc.

Here is a great example (written in Keras), that describes how to predict house prices (a continuous value) using Keras machine learning library. Here is it for scikit-learn, and here is a tutorial on linear regression using caffe.

Check this StackOverflow post for in-depth analysis of the difference between linear and logistic regression.