Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CPE EL3 ELECTIVE 3 (SOFTWARE DEVELOPMENT)

LABORATORY EXERCISES

LAB2 – Using TensorFlow for Linear Regression with Synthetic Data

I. OBJECTIVES

1. Familiarize and identify iterative loss reduction approaches in training a model.


2. Practice linear regression code in tf.keras.
3. Evaluate loss curves during model training.
4. Configure hyperparameters for training the model.

II. RESOURCES AND MATERIALS

 Internet connection
 Google account
 Google Colaboratory

III. CONCEPTS/THEORY/CONTENT

Reducing Loss

Loss in the context of model training refers to the difference or deviation between predicted values and
corresponding label or expected value. Minimizing loss is critical during model training, as it affects the
learning process as well as the reliability of a model in making inferences (testing predictions on unseen
data).

Fortunately, there are tools and algorithms that provide an iterative loss reduction for training models. It
follows a trial-and-error process as illustrated in Figure 1.

Figure 1. Iterative Approach to Reducing Loss (Google Developers, 2021)

Two of the many available algorithms are:

 mini-batch gradient descent


 stochastic gradient descent

CPE EL3 Elective 3 Page 1 of 2


Prepared, edited by: Jeremiah Dearborn F. Gangoso, CpE
These, along with the basic concept of squared loss function will be explored in this exercise.

TensorFlow

TensorFlow is an ML platform of Google that features a rich system ranging from high-level to low APIs
to to develop and train machine learning models. Its hierarchical nature, enables developers to take
advantage of available tools to readily deploy ML models, and at the same time offer support to researchers
and developers to create and explore new machine learning algorithms. The TensorFlow toolkit is illustrated
in Figure 2.

Figure 2. TensorFlow toolkit (Google Developers, 2021)

This exercise will make use of keras, a high-level API to train models.

IV. EXERCISES

1. Read and perform the exercise as outline in the following references:


a. Reducing loss - https://developers.google.com/machine-learning/crash-course/reducing-
loss/video-lecture
b. The TensorFlow Toolkit - https://developers.google.com/machine-learning/crash-
course/first-steps-with-tensorflow/toolkit
2. Do the exercise, “Simple Linear Regression with Synthetic Data” as presented in section 1b. Use
colaboratory for convenience.
3. Repeat the exercise, but this time, use another synthetic data, representing for example, “essay
number of words” and “average price”. You may think of any. Prepare 50 data rows (features and
labels).

Use a new colab notebook for this exercise. Aim for a loss of less than 1 if possible by adjusting
the hyperparameters as discussed in the reference learning material. You may use this colab
notebook for reference:

https://colab.research.google.com/drive/1pi_0ru-
JYvRYhExCj3gKY2NhQkWKZye5?usp=sharing

CPE EL3 Elective 3 Page 2 of 2


Prepared, edited by: Jeremiah Dearborn F. Gangoso, CpE

You might also like