Yapay Zeka Dersleri Ders 11: Sınıflandırma TensorFlow ve Keras Eğitimi – Bölüm 1-

Posted by

Yapay Zeka Dersleri Ders 11 ‘Sınıflandırma Tensorflow Keras -Part1-‘

In this tutorial, we will be exploring the topic of classification using Tensorflow and Keras. Classification is a fundamental task in machine learning where the aim is to learn a model that can map input data to a discrete class label.

For this tutorial, we will be using the popular deep learning framework Tensorflow along with its high-level API Keras. Tensorflow is an open-source software library for machine learning that was developed by Google and Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano.

Before we get started, make sure you have Tensorflow and Keras installed on your machine. You can install them using pip by running the following commands in your terminal:

pip install tensorflow
pip install keras

Now, let’s begin by creating a simple classification model using Tensorflow and Keras. We will be using the famous Iris dataset for this tutorial, which is a popular dataset for classification tasks.

First, let’s create a new HTML file and start by defining the necessary HTML tags:

<!DOCTYPE html>
<html>
<head>
    <title>Classification with Tensorflow and Keras</title>
</head>
<body>
    <h1>Classification with Tensorflow and Keras - Part 1</h1>
    <script>
        // Your classification model code will go here
    </script>
</body>
</html>

Next, let’s add the script tag where we will write our classification model code. In this example, we will create a simple neural network model with one hidden layer using Keras.

<script>
    // Import necessary libraries
    const tf = require('@tensorflow/tfjs');

    // Load the Iris dataset
    const iris = tf.data.csv('iris.csv');

    // Define the model architecture
    const model = tf.sequential();
    model.add(tf.layers.dense({inputShape: [4], units: 10, activation: 'relu'}));
    model.add(tf.layers.dense({units: 3, activation: 'softmax'}));

    // Compile the model
    model.compile({loss: 'categoricalCrossentropy', optimizer: 'adam', metrics: ['accuracy']});

    // Train the model
    const batchSize = 32;
    const epochs = 50;
    iris.shuffle(150).batch(batchSize).forEachAsync(data => {
        model.fit(data.xs, data.labels, {
            batchSize,
            epochs
        });
    });
</script>

In the code above, we first import the necessary libraries and load the Iris dataset using Tensorflow’s csv function. We then define the model architecture with one hidden layer and compile it with a suitable loss function and optimizer. Finally, we train the model on the dataset using batch training.

That’s it for Part 1 of our Classification with Tensorflow and Keras tutorial! In the next part, we will continue building on this simple model and explore more advanced techniques for classification tasks.

I hope you found this tutorial helpful and informative. Stay tuned for Part 2 where we will dive deeper into the world of classification with Tensorflow and Keras!