This is a loading state for the blog post page. Please be patient while the page is loading.
Current course progress at a steady 15% completion. Todays learning has primarily been about the construction of neural networks using Python with TensorFlow. The is getting more practical and less theoretical which I find very interesting, I like getting to utilize what I have learned.
As mentioned yesterday, a ML neural network consists of layers of neurons. Using TensorFlow’s Dense function, you can create a layer of the neural network using the following code.
layer_1 = Dense(units=10, activation=‘sigmoid’)
With this code, layer_1 would be a layer with 10 neurons that all use the sigmoid activation function, which as you would remember, is commonly used for classification tasks.
To calculate the output of the new layer_1, you would input an array with the input values like so
x = np.array([20, 30, 40])
a1 = layer_1(x)
Matrixes are a big part of writing machine learning applications. In python, matrixes are commonly written using numpy arrays where each row is inputted as an array. Say you want to use the following matrix in python:
You would do
m_1 = np.array([
[0.1, 0.2],
[-3.0, -4.0],
[-0.5, -0.6],
[7.0, 8.0]
])
This matrix would have the shape of 4 x 2, meaning it has 4 rows and 2 columns.
When working with TensorFlow, matrixes are usually called tensors and can be created like so:
tf.Tensor([[0.2 0.7 0.3]], shape=(1, 3), dtype=float32)
This will create a matrix or tensor with one row and three columns (also noted as 1 x 3) with the datatype of float32.
You can use both tf.Tensor and np.array for creating matrixes, and you can even convert tensorflow tensors to numpy using the following:
tensor.numpy()
You can create neural networks with TensorFlow by stringing together multiple layers (which we made earlier with the Dense function) by using the following Sequential function.
model = Sequential([layer_1, layer_2])
From then on, you can train the model. Say you have a dataset for whether or a person is qualified for getting cheap car insurance. You could have the person’s age as one input and the value of the person’s car as the other, then you would have an array of 1s (denoting that the person is qualified for cheap insurance) and 0s (not qualified).
You would train the model doing the following.
x = np.array([
[18.0, 30000.0],
[30.0, 40000.0],
[56.0, 15000.0]
])
y = np.array([0, 0, 1])
model.fit(x,y)