Chapter 4 AI
Chapter 4 AI
Page 1:
**Programming Languages for AI:**
- **Python**: Widely used for its simplicity and extensive libraries.
- **R**: Excellent for statistics and data analysis.
- **Java**: Known for its portability and performance in large-scale systems.
- **C++**: Offers high performance, useful in game development and real-time
systems.
- **Julia**: Designed for high-performance numerical analysis and computational
science.
Page 2:
**Example Code to Create a Machine Learning Model (Image Classification):**
```python
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
model = models.Sequential([
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Flatten(),
layers.Dense(64, activation='relu'),
layers.Dense(10)
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
Page 3:
**Example Code for Image Detection Output:**
```python
import numpy as np
# Example Usage
example_image = test_images[0]
result = detect_image(model, example_image)
if result == 1:
print("Image detected.")
else:
print("Image not detected.")
```
**Output when Image is Detected:**
```text
Image detected.
```
**Output when Image is Not Detected:**
```text
Image not detected.
```