mongo?
This commit is contained in:
parent
1425365d68
commit
61f3ba7549
@ -7,50 +7,69 @@ import numpy as np
|
|||||||
import sys
|
import sys
|
||||||
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
from sklearn.preprocessing import StandardScaler, LabelEncoder
|
||||||
from tensorflow.keras.optimizers import Adam
|
from tensorflow.keras.optimizers import Adam
|
||||||
from sacred.observers import FileStorageObserver
|
from sacred.observers import FileStorageObserver, MongoObserver
|
||||||
from sacred import Experiment
|
from sacred import Experiment
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import pymongo
|
import pymongo
|
||||||
|
|
||||||
|
ex = Experiment("434788-mongo", interactive=False, save_git_info=False)
|
||||||
|
ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@172.17.0.1:27017', db_name='sacred'))
|
||||||
|
|
||||||
wine=pd.read_csv('train.csv')
|
@ex.config
|
||||||
|
def my_config():
|
||||||
|
batch_param = int(sys.argv[1])
|
||||||
|
epoch_param = int(sys.argv[2])
|
||||||
|
|
||||||
y = wine['quality']
|
@ex.capture
|
||||||
x = wine.drop('quality', axis=1)
|
def prepare_model(epoch_param, batch_param, _run):
|
||||||
|
_run.info["prepare_model_ts"] = str(datetime.now())
|
||||||
|
|
||||||
citricacid = x['fixed acidity'] * x['citric acid']
|
wine=pd.read_csv('train.csv')
|
||||||
citric_acidity = pd.DataFrame(citricacid, columns=['citric_accidity'])
|
|
||||||
|
|
||||||
density_acidity = x['fixed acidity'] * x['density']
|
y = wine['quality']
|
||||||
density_acidity = pd.DataFrame(density_acidity, columns=['density_acidity'])
|
x = wine.drop('quality', axis=1)
|
||||||
|
|
||||||
|
citricacid = x['fixed acidity'] * x['citric acid']
|
||||||
|
citric_acidity = pd.DataFrame(citricacid, columns=['citric_accidity'])
|
||||||
|
|
||||||
|
density_acidity = x['fixed acidity'] * x['density']
|
||||||
|
density_acidity = pd.DataFrame(density_acidity, columns=['density_acidity'])
|
||||||
|
|
||||||
|
|
||||||
x = wine.join(citric_acidity).join(density_acidity)
|
x = wine.join(citric_acidity).join(density_acidity)
|
||||||
|
|
||||||
bins = (2, 5, 8)
|
bins = (2, 5, 8)
|
||||||
gnames = ['bad', 'nice']
|
gnames = ['bad', 'nice']
|
||||||
y = pd.cut(y, bins = bins, labels = gnames)
|
y = pd.cut(y, bins = bins, labels = gnames)
|
||||||
|
|
||||||
enc = LabelEncoder()
|
enc = LabelEncoder()
|
||||||
yenc = enc.fit_transform(y)
|
yenc = enc.fit_transform(y)
|
||||||
|
|
||||||
scale = StandardScaler()
|
scale = StandardScaler()
|
||||||
scaled_x = scale.fit_transform(x)
|
scaled_x = scale.fit_transform(x)
|
||||||
|
|
||||||
NeuralModel = Sequential([
|
NeuralModel = Sequential([
|
||||||
Dense(128, activation='relu', input_shape=(14,)),
|
Dense(128, activation='relu', input_shape=(14,)),
|
||||||
Dense(32, activation='relu'),
|
Dense(32, activation='relu'),
|
||||||
Dense(64, activation='relu'),
|
Dense(64, activation='relu'),
|
||||||
Dense(64, activation='relu'),
|
Dense(64, activation='relu'),
|
||||||
Dense(64, activation='relu'),
|
Dense(64, activation='relu'),
|
||||||
Dense(1, activation='sigmoid')
|
Dense(1, activation='sigmoid')
|
||||||
])
|
])
|
||||||
|
|
||||||
rms = Adam(lr=0.0003)
|
rms = Adam(lr=0.0003)
|
||||||
|
|
||||||
NeuralModel.compile(optimizer=rms, loss='binary_crossentropy', metrics=['accuracy'])
|
NeuralModel.compile(optimizer=rms, loss='binary_crossentropy', metrics=['accuracy'])
|
||||||
|
|
||||||
NeuralModel.fit(scaled_x, yenc, batch_size=int(sys.argv[1]), epochs = int(sys.argv[2])) #verbose = 1
|
NeuralModel.fit(scaled_x, yenc, batch_size= batch_param, epochs = epoch_param) #verbose = 1
|
||||||
|
|
||||||
NeuralModel.save('wine_model.h5')
|
NeuralModel.save('wine_model.h5')
|
||||||
|
|
||||||
|
@ex.main
|
||||||
|
def my_main(train_size_param, test_size_param):
|
||||||
|
print(prepare_model())
|
||||||
|
|
||||||
|
|
||||||
|
r = ex.run()
|
||||||
|
ex.add_artifact("saved_model/saved_model.pb")
|
Loading…
Reference in New Issue
Block a user