Last active
March 16, 2021 10:34
-
-
Save oscar-defelice/2c9b88f8b1fed902d3452504f12f63de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.layers import Dense, Dropout | |
| num_features = X_train.shape[1] | |
| config = { | |
| 'data': data, | |
| 'train_test_ratio': 0.2, | |
| 'model_config': { | |
| 'model_name': 'house_pricing_model', | |
| 'layers': { | |
| 'first_layer': 12, | |
| 'second_layer': 5, | |
| 'output_layer': 1 | |
| }, | |
| 'activations': ['relu', 'relu', None], # Regression problem: no activation in the last layer. | |
| 'loss_function': 'mse', | |
| 'optimiser': 'adam', | |
| 'metrics': ['mae'] | |
| } | |
| } | |
| def get_model(config): | |
| params = config['model_config'] | |
| model_name, layers, activations = params['model_name'], params['layers'], params['activations'] | |
| loss, opt, metrics = params['loss_function'], params['optimiser'], params['metrics'] | |
| model = Sequential(name = model_name) | |
| for l, (name, n_units) in enumerate(layers.items()): | |
| if l==0: | |
| model.add(Dense(units=n_units, input_dim=num_features, activation = activations[l], name = name)) | |
| else: | |
| model.add(Dense(units=n_units, activation = activations[l], name = name)) | |
| model.compile(loss=loss, optimizer=opt, metrics=metrics) | |
| model.summary() | |
| return model | |
| model = get_model(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment