0% found this document useful (0 votes)
23 views2 pages

Chapter 4 AI

Uploaded by

gsal4066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Chapter 4 AI

Uploaded by

gsal4066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ch4: programming languages

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.

**Common Modules and Libraries:**


- **TensorFlow**: An open-source framework developed by Google for machine learning
and deep learning applications.
- **PyTorch**: Developed by Facebook, it is popular for its dynamic computation
graph and ease of use in research.
- **Keras**: A high-level neural networks API, written in Python and capable of
running on top of TensorFlow, CNTK, or Theano.
- **scikit-learn**: A library for machine learning built on NumPy, SciPy, and
Matplotlib.
- **OpenCV**: An open-source computer vision and machine learning software library.
- **spaCy**: An open-source library for Natural Language Processing (NLP) in
Python.
- **NLTK**: The Natural Language Toolkit, a leading platform for building Python
programs to work with human language data.
- **Pandas**: A data manipulation and analysis library for Python.

Page 2:
**Example Code to Create a Machine Learning Model (Image Classification):**
```python
import tensorflow as tf
from tensorflow.keras import datasets, layers, models

(train_images, train_labels), (test_images, test_labels) =


datasets.cifar10.load_data()

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'])

model.fit(train_images, train_labels, epochs=10, validation_data=(test_images,


test_labels))
```
**Output:**
```text
Epoch 1/10
1563/1563 [==============================] - 15s 9ms/step - loss: 1.5294 -
accuracy: 0.4424 - val_loss: 1.3023 - val_accuracy: 0.5285
...
Epoch 10/10
1563/1563 [==============================] - 13s 8ms/step - loss: 0.5589 -
accuracy: 0.8105 - val_loss: 0.8753 - val_accuracy: 0.7047
```

Page 3:
**Example Code for Image Detection Output:**
```python
import numpy as np

# Detecting Image Function


def detect_image(model, image):
predictions = model.predict(np.expand_dims(image, axis=0))
return np.argmax(predictions)

# 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.
```

You might also like