QNA > H > Come Addestrare Un Set Di Dati Iris In Un Algoritmo Cnn
Domanda

Come addestrare un set di dati Iris in un algoritmo CNN

Risposte
02/13/2022
Vano Ekmark

Firstly, CNNs work on the basic principle of exploitation of spatial representation of data. So, even though your code might “run”, you’d most probably get terrible results.

The Iris dataset has following features Sepal Length, Sepal Width, Petal Length, and Petal Width.

In the case of training CNN on numerical data (Iris), the network is going to memorize feature groups and associations between them which will result in nonlinearity. However, I do not think convolutions are going to be of much use here since features are not invariant. The paper [0] examines the application of CNNs to textual understanding.

Furthermore, the training process is fairly simple.

Read the dataset into an array and convert labels to one hot for ease.

  1. data = read_data(iris.csv)
  2. labels = data['labels'].values
  3. num_classes = len(labels)

Create the placeholders to feed the data into network.

  1. x = tf.placeholder(tf.float32, [None, 4])
  2. y = tf.placeholder(tf.float32, [None, num_classes])

Split the data into training and testing.

  1. x_train, y_train, x_test, y_test = split(data)

Create the network, add 1D-CNN layers since you are not dealing with images i.e. 2D matrix [W, H] so I guess 1D-CNN will work fine as you will be returning 1D tensor. Additionally, 1D convolution means applying convolutions along one direction, you might have to test this hypothesis. Add max-pooling.

  1. conv_1 = tf.nn.conv1d(x, filters, stride, padding)
  2. pool_1 = tf.layers.max_pooling1d(conv_1, pool_size, strides, padding)

Apply loss function, compute cost and then apply optimizer to minimize the cost.

  1. loss = tf.losses.mean_squared_error(labels, pred, labels)
  2. optimizer = tf.train.AdamOptimizer(learning_rate).minimize(loss)

The rest is fairly standard.

However, I donot think this will yield any result. You can try collecting images of those flowers and then training a CNN to classify. Furthermore, you could combine CNN with a ML based classifier or simply a neural net (MLP maybe) to do the task.

Share the results of both 1D and 2D convolutions.

[0] [1502.01710] Text Understanding from Scratch

Dare una risposta
Perché il mio occhio è rosso solo vicino all'iride? :: Qual è il miglior schema di ponderazione per l'algoritmo di classificazione knn?
Link utili