🟣 ML + AI  ·  Lesson 64

TensorFlow and Keras Basics

TensorFlow और Keras Basics

What are TensorFlow and Keras Basics?

TensorFlow and Keras Basics means tensorFlow and Keras are used to build, train and evaluate deep learning models.

In real programs, this topic helps in building neural networks. Learn the idea first, then type the program yourself and compare the output.

💡 At a Glance
PointDetails
Course AreaMachine Learning + AI
Concepts used for prediction, classification, clustering and AI-based projects.
Main Usebuilding neural networks
Example Filetensorflow-keras-basics.py
Practice FocusRun, change values, and explain the output line by line.

Why should you learn this?

  • It is useful for building neural networks.
  • It connects with training deep learning models.
  • It improves your ability to read, write and debug Python programs.

Important Terms

These terms are used directly in this lesson. Understand them before memorising the code.

TermMeaning
tensortensor is an important term in this topic.
KerasHigh-level API used to build neural networks easily.
SequentialSequential is an important term in this topic.
Dense layerDense layer is an important term in this topic.
trainingProcess where a model learns from data.

Syntax / Basic Pattern

The simple pattern is: prepare data, apply the concept, then show the result.

Basic Pattern
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)),
    tf.keras.layers.Dense(1, activation="sigmoid")
])
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.summary()

Complete Example Program

Python – tensorflow-keras-basics.py
import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)),
    tf.keras.layers.Dense(1, activation="sigmoid")
])

model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.summary()

Expected Output

Model summary with layers and parameters will be displayed.

Program Explanation

  • import tensorflow as tf imports ready-made features from a module/library.
  • model = tf.keras.Sequential([ stores a value in model.
  • tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)), stores a value in tf.keras.layers.Dense(8, activation.
  • tf.keras.layers.Dense(1, activation="sigmoid") stores a value in tf.keras.layers.Dense(1, activation.
  • ]) performs the next step of the program logic.
  • model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"] stores a value in model.compile(optimizer.
  • model.summary() performs the next step of the program logic.

Where will you use it?

  • Building neural networks.
  • Training deep learning models.
  • Using keras layers.

Common Mistakes

  • Training and testing the model on the same data.
  • Using an algorithm without understanding the input features.
  • Reporting only accuracy without checking actual mistakes and limitations.

Practice Tasks

  1. Type the program in tensorflow-keras-basics.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to building neural networks.
  4. Write 5 lines explaining the logic in your own words.

Summary

TensorFlow and Keras Basics is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.

TensorFlow और Keras Basics क्या है?

TensorFlow और Keras Basics ka matlab hai: TensorFlow and Keras are used to build, train and evaluate deep learning models. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki building neural networks jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye building neural networks me kaam aata hai.
  • Ye training deep learning models se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
tensortensor is an important term in this topic.
KerasHigh-level API used to build neural networks easily.
SequentialSequential is an important term in this topic.
Dense layerDense layer is an important term in this topic.
trainingProcess where a model learns from data.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
import tensorflow as tf
model = tf.keras.Sequential([
    tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)),
    tf.keras.layers.Dense(1, activation="sigmoid")
])
model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.summary()

Complete Example Program

Python – tensorflow-keras-basics.py
import tensorflow as tf

model = tf.keras.Sequential([
    tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)),
    tf.keras.layers.Dense(1, activation="sigmoid")
])

model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"])
model.summary()

Expected Output

Model summary with layers and parameters will be displayed.

Program Explanation

  • import tensorflow as tf imports ready-made features from a module/library.
  • model = tf.keras.Sequential([ stores a value in model.
  • tf.keras.layers.Dense(8, activation="relu", input_shape=(2,)), stores a value in tf.keras.layers.Dense(8, activation.
  • tf.keras.layers.Dense(1, activation="sigmoid") stores a value in tf.keras.layers.Dense(1, activation.
  • ]) performs the next step of the program logic.
  • model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"] stores a value in model.compile(optimizer.
  • model.summary() performs the next step of the program logic.

Practical Uses

  • Building neural networks.
  • Training deep learning models.
  • Using keras layers.

Common Mistakes

  • Training and testing the model on the same data.
  • Using an algorithm without understanding the input features.
  • Reporting only accuracy without checking actual mistakes and limitations.

Practice Tasks

  1. Program ko tensorflow-keras-basics.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. building neural networks par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

TensorFlow and Keras Basics ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial