My First AI Model

My First AI Model

If you will check the below table, then you will get to know that Y is dependent on X and the relationship is. y = 2x - 1

You can also draw the relationship. Below I draw the relationship? in a graph.?


Now I will use TensorFlow to predict the value of y by training the model using the above data set. I will use the Keras library over TensorFlow.

Neural Network Layer?

model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])        

units=1 represents the total number of neurons going to be used to predict the model, and input_shape=[1] represents the number of inputs. Here we are going to?input the value of X, and the model will predict the value of Y.

Compile the model.?

model.compile(optimizer='sgd', loss='mean_squared_error')        

What is a loss function??

The loss function calculates the difference between the predicted values and the actual value.?

The mean squared error (MSE) loss function, also known as L2 loss or quadratic loss, is a function that measures the average of the squared differences between predicted and actual values.?

Optimizer

In machine learning, an optimizer is an algorithm that adjusts a model's parameters to reduce a loss function and improve its performance.

Stochastic gradient descent (SGD) is an optimization algorithm that's used to train models in machine learning and artificial intelligence.

Train the model.?

model.fit(xs, ys, epochs=500)        

The fit function will make the guess 500 times, and the loss function and optimizer will work on making the guess correct.?

Use the model?

print(model.predict(np.array([10.0])))        

Output

[[18.98005]]        

Let’s discuss other keras library components used in the above code.?

Sequential

The Sequential class in Keras is a fundamental building block for creating neural networks, particularly those with a linear stack of layers. It offers a straightforward and intuitive way to define the architecture of your model.?

Key Concepts:

Linear Stack of Layers: In a Sequential model, layers are arranged in a linear sequence. The output of one layer becomes the input to the next layer.

Simplicity: The Sequential API is designed for simplicity, making it ideal for beginners and quick prototyping.

Flexibility: While it's well-suited for simple architectures, it can still be used for more complex models with the help of advanced techniques like functional API or model subclassing.

The Dense layer is one of the most fundamental layers in neural networks, and it's extensively used in Keras to construct deep learning models. It's often referred to as a fully connected layer because every neuron in the layer is connected to every neuron in the preceding layer.

Complete code in Google Colab.?

https://colab.research.google.com/drive/1tmSKyjh7l8mmt3Mft408WUrcNZtiJds6?usp=sharing

要查看或添加评论,请登录

Rajendra Verma的更多文章

  • Evolution of Neural Network

    Evolution of Neural Network

    This is a very intersecting topic, just like an Netflix webseries. Now a days everyone is talking about AI, but no one…

  • What is Deep Learning?

    What is Deep Learning?

    A subset of machine learning: Deep learning is a branch of machine learning that focuses on using artificial neural…

  • Very Good CLI vs Flutter CLI: A Clear Distinction

    Very Good CLI vs Flutter CLI: A Clear Distinction

    We all know about Flutter cli, that it is known to develop the project and that it works to update and upgrade the…

  • Flutter Internationalization

    Flutter Internationalization

    When you create a mobile app and it hits the international market, you have to internationalize the app which is an…

  • Mixin in dart

    Mixin in dart

    Flutter is becoming the most popular language now for mobile development. When developers write code, they encounter…

  • Types of provider in Flutter

    Types of provider in Flutter

    I was working on one of my Flutter projects, and suddenly I thought that it is a good idea to explain the difference…

  • Flutter

    Flutter

    A couple of days ago, I was thinking of learning to flutter because of market requirements. But I find it too easy and…

  • My Experiment with the Matter Protocol

    My Experiment with the Matter Protocol

    Exploring the Future of IoT: An In-Depth Look at the Matter Protocol As a software engineer specializing in IoT…

  • How to filter array of a positive integer and negative integer in kotlin

    How to filter array of a positive integer and negative integer in kotlin

    Interviews are asking a general question nowadays from Kotlin developers so that I like to give its answer fun main(){…

  • Print numbers with using recursion and without using recursion and loop in java.

    Print numbers with using recursion and without using recursion and loop in java.

    I was taking the interview and the thought comes, let's put a question to the interviewee that you have to print…