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.

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[0][0]
__________________________________________________________________________________________________
embedded_station_reshape (Resha (None, 20)           0           embedded_stations[0][0]
__________________________________________________________________________________________________
month_day_input (InputLayer)    (None, 1)            0
__________________________________________________________________________________________________
station_and_day (Concatenate)   (None, 21)           0           embedded_station_reshape[0][0]
month_day_input[0][0]
__________________________________________________________________________________________________
hidden (Dense)                  (None, 40)           880         station_and_day[0][0]
__________________________________________________________________________________________________
prediction (Dense)              (None, 3)            123         hidden[0][0]
==================================================================================================
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.

For this post, I also switched to Cartopy from Basemap.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.458132266998291, "perplexity": 7447.211602284103}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-39/segments/1568514574058.75/warc/CC-MAIN-20190920175834-20190920201834-00064.warc.gz"}