</>
Skip to content
Data Science lessons (16/42)

Data Science — Machine Learning

Neural network basics

import tensorflow as tf
from tensorflow import keras

# Build model
model = keras.Sequential([
    keras.layers.Dense(64, activation='relu', input_shape=(10,)),
    keras.layers.Dense(32, activation='relu'),
    keras.layers.Dense(1, activation='sigmoid')
])

# Compile
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

Training

# Train
history = model.fit(X_train, y_train, epochs=10, validation_split=0.2)

# Evaluate
loss, accuracy = model.evaluate(X_test, y_test)

CNN for images

model = keras.Sequential([
    keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
    keras.layers.MaxPooling2D((2, 2)),
    keras.layers.Conv2D(64, (3, 3), activation='relu'),
    keras.layers.Flatten(),
    keras.layers.Dense(64, activation='relu'),
    keras.layers.Dense(10, activation='softmax')
])

RNN for sequences

model = keras.Sequential([
    keras.layers.LSTM(64, return_sequences=True, input_shape=(100, 10)),
    keras.layers.LSTM(32),
    keras.layers.Dense(1)
])

Mini Practice

  1. Build a simple neural network
  2. Train on a dataset
  3. Build a CNN
  4. Create an RNN

Up Next

Continue with Computer Vision - Image analysis.

Related Topics

Frequently Asked Questions about Machine Learning

What is Machine Learning in Data Science?

Machine Learning is a fundamental concept in Data Science. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Machine Learning?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Machine Learning.

Why is Machine Learning important in Data Science?

Machine Learning is essential for Data Science development. Understanding this concept will help you write better code and solve real-world problems more effectively.