diff options
author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-30 12:41:53 +0200 |
---|---|---|
committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-30 12:41:53 +0200 |
commit | ad9193d35e5ae2f6847492f1867963fc1672ee3e (patch) | |
tree | be3b3a54bc42696e73f3c3092a9f52db8355c07f /backend/microservice/regression.py | |
parent | 6af8655c2d1a24c0c3ba851bb28d72f9d06c83b0 (diff) | |
parent | 476393d1530b261b8a145db2533262979558e064 (diff) |
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into dev
Diffstat (limited to 'backend/microservice/regression.py')
-rw-r--r-- | backend/microservice/regression.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/backend/microservice/regression.py b/backend/microservice/regression.py new file mode 100644 index 00000000..f039292c --- /dev/null +++ b/backend/microservice/regression.py @@ -0,0 +1,53 @@ +import numpy as np +from tensorflow.keras.datasets import boston_housing +from sklearn.preprocessing import StandardScaler +from tensorflow.keras.models import load_model + +x_new = np.random.rand(X_train.shape[1]) +x_new = x_new.reshape(1,-1) +# x_new.shape +y_pred = model.predict(x_new) +if y_pred < 0.5: + print('0') +else: + print('1') + +(X_train, y_train), (X_test, y_test) = boston_housing.load_data() + +X_train.shape +X_test.shape +X_train[0] +y_test + +scaler = StandardScaler() +scaler.fit(X_train) +X_train = scaler.transform(X_train) +X_test = scaler.transform(X_test) + +X_train[0] +X_test + +model = Sequential() +model.add(Dense(input_dim=X_train.shape[1], units=100, activation='relu')) +# model.add(Dense(input_dim=X_train.shape[1], units=50, activation='relu')) +model.add(Dense(units=1)) +model.summary() + +model.compile(optimizer='adam', loss='mse', metrics=['mae']) +history = model.fit(X_train, y_train, batch_size=32, epochs=20, validation_split=0.2) + +plt.plot(history.epoch, history.history['loss']) +plt.plot(history.epoch, history.history['val_loss']) + +plt.plot(history.epoch, history.history['mae']) +plt.plot(history.epoch, history.history['val_mae']) + +model.evaluate(X_test, y_test) +model.save('models/boston.h5') +old_model = load_model('models/boston.h5') + +x_new = np.random.rand(X_train.shape[1]) +x_new = x_new.reshape(1, -1) +x_new.shape +# Za nove podatke koristi se predict tako da se dobije predvidjena vrednost za y +old_model.predict(x_new)
\ No newline at end of file |