One of my favorite hack projects was trying to create a climate classification by clustering learned embeddings of weather stations.
The original model was written in TensorFlow. Since then, I’ve started to experiment with Keras. Because the climate classifier is pretty simple neural network, I rewrote the model using Keras and saved many lines of code.
For the problem description and data preparation, see the original post.
Load the data
I’m using the same files that I created for the original post.
Define the network
I’ll use the same network as before.
__________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== station_id_input (InputLayer) (None, 1) 0 __________________________________________________________________________________________________ embedded_stations (Embedding) (None, 1, 20) 24360 station_id_input __________________________________________________________________________________________________ embedded_station_reshape (Resha (None, 20) 0 embedded_stations __________________________________________________________________________________________________ month_day_input (InputLayer) (None, 1) 0 __________________________________________________________________________________________________ station_and_day (Concatenate) (None, 21) 0 embedded_station_reshape month_day_input __________________________________________________________________________________________________ hidden (Dense) (None, 40) 880 station_and_day __________________________________________________________________________________________________ prediction (Dense) (None, 3) 123 hidden ================================================================================================== Total params: 25,363 Trainable params: 25,363 Non-trainable params: 0 __________________________________________________________________________________________________
Epoch 1/1 2417066/2417066 [==============================] - 178s 74us/step - loss: 4390.3217
There is less boilerplate in the Keras code compared to my TensorFlow implementation in the original post. I think it’s cool that most of the code is doing work describing the network.
Classify the embeddings
Finally, I run KMeans on the trained embeddings to assign a “climate”.
I get similar climates as before. Since there’s randomness in the neural network initializations and batches and in the KMeans, I wouldn’t expect to get exactly the same. For example, the latitude boundaries on the East coast have shifted compared to before.