diff --git a/assignment_1/deliverable/linear_regression.pickle b/assignment_1/deliverable/linear_regression.pickle new file mode 100644 index 0000000..ec34b34 Binary files /dev/null and b/assignment_1/deliverable/linear_regression.pickle differ diff --git a/assignment_1/deliverable/nonlinear_model/keras_metadata.pb b/assignment_1/deliverable/nonlinear_model/keras_metadata.pb new file mode 100644 index 0000000..2e13065 --- /dev/null +++ b/assignment_1/deliverable/nonlinear_model/keras_metadata.pb @@ -0,0 +1,12 @@ + +Froot"_tf_keras_sequential*F{"name": "sequential", "trainable": true, "expects_training_arg": true, "dtype": "float32", "batch_input_shape": null, "must_restore_from_config": false, "class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 2]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "dense_input"}}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 30, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_3", "trainable": true, "dtype": "float32", "units": 10, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_4", "trainable": true, "dtype": "float32", "units": 5, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_5", "trainable": true, "dtype": "float32", "units": 3, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_6", "trainable": true, "dtype": "float32", "units": 2, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}, {"class_name": "Dense", "config": {"name": "dense_7", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}]}, "shared_object_id": 25, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 2}}, "shared_object_id": 26}, "build_input_shape": {"class_name": "TensorShape", "items": [null, 2]}, "is_graph_network": true, "save_spec": {"class_name": "TypeSpec", "type_spec": "tf.TensorSpec", "serialized": [{"class_name": "TensorShape", "items": [15, 2]}, "float32", "dense_input"]}, "keras_version": "2.5.0", "backend": "tensorflow", "model_config": {"class_name": "Sequential", "config": {"name": "sequential", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": {"class_name": "__tuple__", "items": [null, 2]}, "dtype": "float32", "sparse": false, "ragged": false, "name": "dense_input"}, "shared_object_id": 0}, {"class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 30, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 2}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 3}, {"class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 4}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 5}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 6}, {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 7}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 8}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 9}, {"class_name": "Dense", "config": {"name": "dense_3", "trainable": true, "dtype": "float32", "units": 10, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 10}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 11}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 12}, {"class_name": "Dense", "config": {"name": "dense_4", "trainable": true, "dtype": "float32", "units": 5, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 13}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 14}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 15}, {"class_name": "Dense", "config": {"name": "dense_5", "trainable": true, "dtype": "float32", "units": 3, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 16}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 17}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 18}, {"class_name": "Dense", "config": {"name": "dense_6", "trainable": true, "dtype": "float32", "units": 2, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 19}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 20}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 21}, {"class_name": "Dense", "config": {"name": "dense_7", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 22}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 23}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 24}]}}, "training_config": {"loss": "mse", "metrics": [[{"class_name": "MeanMetricWrapper", "config": {"name": "mse", "dtype": "float32", "fn": "mean_squared_error"}, "shared_object_id": 27}]], "weighted_metrics": null, "loss_weights": null, "optimizer_config": {"class_name": "RMSprop", "config": {"name": "RMSprop", "learning_rate": 0.0010000000474974513, "decay": 0.0, "rho": 0.8999999761581421, "momentum": 0.0, "epsilon": 1e-07, "centered": false}}}}2 +root.layer_with_weights-0"_tf_keras_layer*{"name": "dense", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense", "trainable": true, "dtype": "float32", "units": 30, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 1}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 2}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 3, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 2}}, "shared_object_id": 26}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 2]}}2 +root.layer_with_weights-1"_tf_keras_layer*{"name": "dense_1", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_1", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 4}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 5}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 6, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 30}}, "shared_object_id": 28}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 30]}}2 +root.layer_with_weights-2"_tf_keras_layer*{"name": "dense_2", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 20, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 7}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 8}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 9, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 20}}, "shared_object_id": 29}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 20]}}2 +root.layer_with_weights-3"_tf_keras_layer*{"name": "dense_3", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_3", "trainable": true, "dtype": "float32", "units": 10, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 10}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 11}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 12, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 20}}, "shared_object_id": 30}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 20]}}2 +root.layer_with_weights-4"_tf_keras_layer*{"name": "dense_4", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_4", "trainable": true, "dtype": "float32", "units": 5, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 13}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 14}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 15, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 10}}, "shared_object_id": 31}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 10]}}2 +root.layer_with_weights-5"_tf_keras_layer*{"name": "dense_5", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_5", "trainable": true, "dtype": "float32", "units": 3, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 16}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 17}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 18, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 5}}, "shared_object_id": 32}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 5]}}2 +root.layer_with_weights-6"_tf_keras_layer*{"name": "dense_6", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_6", "trainable": true, "dtype": "float32", "units": 2, "activation": "relu", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 19}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 20}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 21, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 3}}, "shared_object_id": 33}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 3]}}2 +root.layer_with_weights-7"_tf_keras_layer*{"name": "dense_7", "trainable": true, "expects_training_arg": false, "dtype": "float32", "batch_input_shape": null, "stateful": false, "must_restore_from_config": false, "class_name": "Dense", "config": {"name": "dense_7", "trainable": true, "dtype": "float32", "units": 1, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}, "shared_object_id": 22}, "bias_initializer": {"class_name": "Zeros", "config": {}, "shared_object_id": 23}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}, "shared_object_id": 24, "input_spec": {"class_name": "InputSpec", "config": {"dtype": null, "shape": null, "ndim": null, "max_ndim": null, "min_ndim": 2, "axes": {"-1": 2}}, "shared_object_id": 34}, "build_input_shape": {"class_name": "TensorShape", "items": [15, 2]}}2 +qroot.keras_api.metrics.0"_tf_keras_metric*{"class_name": "Mean", "name": "loss", "dtype": "float32", "config": {"name": "loss", "dtype": "float32"}, "shared_object_id": 35}2 +rroot.keras_api.metrics.1"_tf_keras_metric*{"class_name": "MeanMetricWrapper", "name": "mse", "dtype": "float32", "config": {"name": "mse", "dtype": "float32", "fn": "mean_squared_error"}, "shared_object_id": 27}2 \ No newline at end of file diff --git a/assignment_1/deliverable/nonlinear_model/saved_model.pb b/assignment_1/deliverable/nonlinear_model/saved_model.pb new file mode 100644 index 0000000..22064e7 Binary files /dev/null and b/assignment_1/deliverable/nonlinear_model/saved_model.pb differ diff --git a/assignment_1/deliverable/nonlinear_model/variables/variables.data-00000-of-00001 b/assignment_1/deliverable/nonlinear_model/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..5432cfe Binary files /dev/null and b/assignment_1/deliverable/nonlinear_model/variables/variables.data-00000-of-00001 differ diff --git a/assignment_1/deliverable/nonlinear_model/variables/variables.index b/assignment_1/deliverable/nonlinear_model/variables/variables.index new file mode 100644 index 0000000..20b3447 Binary files /dev/null and b/assignment_1/deliverable/nonlinear_model/variables/variables.index differ diff --git a/assignment_1/deliverable/nonlinear_model_normalizers.pickle b/assignment_1/deliverable/nonlinear_model_normalizers.pickle new file mode 100644 index 0000000..4e9916f Binary files /dev/null and b/assignment_1/deliverable/nonlinear_model_normalizers.pickle differ diff --git a/assignment_1/deliverable/run_model.py b/assignment_1/deliverable/run_model.py old mode 100644 new mode 100755 index 9b2d6ef..d4808f3 --- a/assignment_1/deliverable/run_model.py +++ b/assignment_1/deliverable/run_model.py @@ -1,6 +1,10 @@ +#!/usr/bin/env python3 + import joblib import numpy as np - +from keras import models +import sys +from keras.models import Model def load_data(filename): """ @@ -57,13 +61,51 @@ if __name__ == '__main__': # EDITABLE SECTION OF THE SCRIPT: if you need to edit the script, do it here ############################################################################ - # Load the trained model - baseline_model_path = './baseline_model.pickle' - baseline_model = load_model(baseline_model_path) + ms = {"baseline", "linear", "nonlinear"} - # Predict on the given samples - y_pred = baseline_model.predict(x) + if len(sys.argv) != 2: + print("%s {model_name}" % sys.argv[0]) + sys.exit(1) + if sys.argv[1] not in ms: + print("model name must be one of " + str(ms)) + sys.exit(2) + + y_pred = None + if sys.argv[1] == "baseline": + # Load the trained model + baseline_model_path = './baseline_model.pickle' + baseline_model = load_model(baseline_model_path) + + # Predict on the given samples + y_pred = baseline_model.predict(x) + else: + X = np.zeros([x.shape[0], 5]) + X[:, 0] = 1 + X[:, 1:3] = x + X[:, 3] = x[:, 0] * x[:, 1] + X[:, 4] = np.sin(x[:, 0]) + + if sys.argv[1] == "linear": + # Load the linear model + linear_model_path = './linear_regression.pickle' + linear_model = load_model(linear_model_path) + + # Predict on the given samples + y_pred = linear_model.predict(X) + else: + # Load saved Keras model + nonlinear_model = models.load_model('./nonlinear_model') + # Load saved normalizing factors for Xs + normalizers = load_model('./nonlinear_model_normalizers.pickle') + # Normalize Xs with normalizing factors + X = X[:, 1:3] + X -= normalizers["mean"] + X /= normalizers["std"] + + # Run model on normalized data + y_pred = nonlinear_model.predict(X) + y_pred = y_pred[:, 0] ############################################################################ # STOP EDITABLE SECTION: do not modify anything below this point. diff --git a/assignment_1/src/t1.py b/assignment_1/src/build_models.py similarity index 73% rename from assignment_1/src/t1.py rename to assignment_1/src/build_models.py index f980fb3..f2971de 100644 --- a/assignment_1/src/t1.py +++ b/assignment_1/src/build_models.py @@ -2,14 +2,18 @@ import numpy as np from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from tensorflow.keras import Input, Model -from tensorflow.keras.models import Sequential +from tensorflow.keras.models import Sequential, save_model from tensorflow.keras.layers import Dense from tensorflow.keras import losses from tensorflow import keras import tensorflow as tf from sklearn.metrics import mean_squared_error +from utils import save_sklearn_model, save_keras_model +import os -data = np.load("../data/data.npz") +d = os.path.dirname(__file__) + +data = np.load(d + "/../data/data.npz") xs = data["x"] # 2000x2 y = data["y"] # 2000x1 points = 2000 @@ -43,6 +47,8 @@ print("# Linear regression:") # Print the resulting parameters print("f(x) = %g + %g * x_1 + %g * x_2 + %g * x_1 * x_2 + %g * sin(x_1)" % tuple(reg.coef_)) +save_sklearn_model(reg, d + "/../deliverable/linear_regression.pickle") + # Test using MSQ on test set score = reg.score(X_test, y_test) print("MSQ error on test set is: %g" % (score)) @@ -53,48 +59,45 @@ print("\n# Feed-forward NN:") A = X_val -X_train = X_train[:, 1:] -X_val = X_val[:, 1:] +X_train = X_train[:, 1:3] +X_val = X_val[:, 1:3] # X_train = X_train[:, 1:3] # X_val = X_val[:, 1:3] mean = np.mean(X_train, axis=0) std = np.std(X_train, axis=0) -#y_mean = np.mean(y_train, axis=0) -#y_std = np.std(y_train, axis=0) - -y_mean = 0 -y_std = 1 X_train -= mean X_train /= std -y_train -= y_mean -y_train /= y_std X_val -= mean X_val /= std -y_val -= y_mean -y_val /= y_std network = Sequential() -network.add(Dense(35, activation='relu')) +network.add(Dense(30, activation='relu')) +network.add(Dense(20, activation='relu')) +network.add(Dense(20, activation='relu')) network.add(Dense(10, activation='relu')) +network.add(Dense(5, activation='relu')) network.add(Dense(3, activation='relu')) +network.add(Dense(2, activation='relu')) network.add(Dense(1, activation='linear')) network.compile(optimizer='rmsprop', loss='mse', metrics=['mse']) -epochs = 10000 -callback = tf.keras.callbacks.EarlyStopping(monitor='loss', patience=1000) -network.fit(X_train, y_train, epochs=epochs, verbose=1, batch_size=100, validation_data=(X_val, y_val), callbacks=[callback]) +epochs = 100000 +callback = tf.keras.callbacks.EarlyStopping(monitor='loss', patience=40) +network.fit(X_train, y_train, epochs=epochs, verbose=1, batch_size=15, + validation_data=(X_val, y_val), callbacks=[callback]) + +network.save(d + "/../deliverable/nonlinear_model") +save_sklearn_model({"mean": mean, "std": std}, d + "/../deliverable/nonlinear_model_normalizers.pickle") msq = mean_squared_error(network.predict(X_val), y_val) print(msq) -X_test = X_test[:, 1:] +X_test = X_test[:, 1:3] X_test -= mean X_test /= std -y_test -= y_mean -y_test /= y_std msq = mean_squared_error(network.predict(X_test), y_test) print(msq)