Sacred
This commit is contained in:
parent
6ccc678bd8
commit
36702fb4a8
@ -20,20 +20,27 @@ pipeline {
|
|||||||
}
|
}
|
||||||
stage('Prepare stats') {
|
stage('Prepare stats') {
|
||||||
agent {
|
agent {
|
||||||
docker {
|
// no idea why it doesn't work
|
||||||
image 'mmoryl/ium:latest'
|
// docker {
|
||||||
|
// image 'mmoryl/ium:latest'
|
||||||
|
// reuseNode true
|
||||||
|
// }
|
||||||
|
dockerfile {
|
||||||
|
filename 'Lab4.dockerfile'
|
||||||
reuseNode true
|
reuseNode true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
copyArtifacts projectName: 'z487183-create-dataset'
|
copyArtifacts projectName: 'z487183-create-dataset'
|
||||||
sh './prepare-stats.sh'
|
sh './prepare-stats.sh'
|
||||||
archiveArtifacts 'stats.txt'
|
sh 'mkdir sacred-files'
|
||||||
sh 'python3 property_model.py'
|
sh 'python3 property_model.py'
|
||||||
sh 'python3 predict_values.py'
|
sh 'python3 predict_values.py'
|
||||||
archiveArtifacts 'test_predictions.csv'
|
// archiveArtifacts 'test_predictions.csv'
|
||||||
archiveArtifacts 'train_predictions.csv'
|
// archiveArtifacts 'train_predictions.csv'
|
||||||
archiveArtifacts 'dev_predictions.csv'
|
// archiveArtifacts 'dev_predictions.csv'
|
||||||
|
// archiveArtifacts 'stats.txt'
|
||||||
|
archiveArtifacts 'my_runs/**'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@ RUN pip install scikit-learn
|
|||||||
RUN pip install kaggle
|
RUN pip install kaggle
|
||||||
RUN pip install keras
|
RUN pip install keras
|
||||||
RUN pip install tensorflow
|
RUN pip install tensorflow
|
||||||
|
RUN apt-get install -y git
|
||||||
|
RUN pip install sacred
|
||||||
|
RUN pip install pymongo
|
||||||
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
@ -1,33 +1,74 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from keras.models import Sequential
|
from keras.models import Sequential
|
||||||
from keras.layers import Dense
|
from keras.layers import Dense
|
||||||
|
from sacred import Experiment
|
||||||
|
import json
|
||||||
|
from sacred.observers import MongoObserver
|
||||||
|
from sacred.observers import FileStorageObserver
|
||||||
|
|
||||||
# prepare dataset
|
ex = Experiment("z487183", interactive=True)
|
||||||
features = ['Rooms', 'Distance', 'Bedroom2', 'Bathroom']
|
ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1:27017', db_name='sacred'))
|
||||||
target = 'PriceAboveMedian'
|
ex.observers.append(FileStorageObserver('my_runs'))
|
||||||
|
|
||||||
X_train = pd.read_csv('X_train.csv').values
|
@ex.config
|
||||||
y_train = pd.read_csv('Y_train.csv').values
|
def my_config():
|
||||||
|
optimizer = 'sgd'
|
||||||
|
loss_function = 'binary_crossentropy'
|
||||||
|
|
||||||
X_dev = pd.read_csv('X_val.csv').values
|
@ex.automain
|
||||||
y_dev = pd.read_csv('Y_val.csv').values
|
def my_main(optimizer, loss_function, _run):
|
||||||
|
# prepare dataset
|
||||||
|
features = ['Rooms', 'Distance', 'Bedroom2', 'Bathroom']
|
||||||
|
|
||||||
X_test = pd.read_csv('X_test.csv').values
|
X_train_resource = ex.open_resource('X_train.csv')
|
||||||
y_test = pd.read_csv('Y_test.csv').values
|
y_train_resource = ex.open_resource('Y_train.csv')
|
||||||
|
|
||||||
# model definition
|
X_dev_resource = ex.open_resource('X_val.csv')
|
||||||
model = Sequential([
|
y_dev_resource = ex.open_resource('Y_val.csv')
|
||||||
Dense(32, activation='relu', input_shape=(len(features),)),
|
|
||||||
Dense(32, activation='relu'),
|
|
||||||
Dense(1, activation='sigmoid'),
|
|
||||||
])
|
|
||||||
|
|
||||||
#compile and train
|
X_test_resource = ex.open_resource('X_test.csv')
|
||||||
model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])
|
y_test_resource = ex.open_resource('Y_test.csv')
|
||||||
hist = model.fit(X_train, y_train,
|
|
||||||
batch_size=32, epochs=100,
|
|
||||||
validation_data=(X_dev, y_dev))
|
|
||||||
|
|
||||||
model.evaluate(X_test, y_test)[1]
|
X_train = pd.read_csv(X_train_resource).values
|
||||||
|
y_train = pd.read_csv(y_train_resource).values
|
||||||
|
|
||||||
model.save('model.h5')
|
X_dev = pd.read_csv(X_dev_resource).values
|
||||||
|
y_dev = pd.read_csv(y_dev_resource).values
|
||||||
|
|
||||||
|
X_test = pd.read_csv(X_test_resource).values
|
||||||
|
y_test = pd.read_csv(y_test_resource).values
|
||||||
|
|
||||||
|
# model definition
|
||||||
|
model = Sequential([
|
||||||
|
Dense(32, activation='relu', input_shape=(len(features),)),
|
||||||
|
Dense(32, activation='relu'),
|
||||||
|
Dense(1, activation='sigmoid'),
|
||||||
|
])
|
||||||
|
|
||||||
|
#compile and train
|
||||||
|
model.compile(optimizer=optimizer, loss=loss_function, metrics=['accuracy'])
|
||||||
|
hist = model.fit(X_train, y_train,
|
||||||
|
batch_size=32, epochs=100,
|
||||||
|
validation_data=(X_dev, y_dev))
|
||||||
|
model.save('model.h5')
|
||||||
|
|
||||||
|
loss, accuracy = model.evaluate(X_test, y_test)
|
||||||
|
_run.log_scalar("training.loss", loss)
|
||||||
|
_run.log_scalar("training.accuracy", accuracy)
|
||||||
|
|
||||||
|
with open("sacred-files/parameters.json", 'w') as file:
|
||||||
|
json.dump(my_config(), file)
|
||||||
|
|
||||||
|
with open('property_model.py', 'r') as current_file:
|
||||||
|
file_content = current_file.read()
|
||||||
|
with open('sacred-files/source_code.py', 'w') as new_file:
|
||||||
|
new_file.write(file_content)
|
||||||
|
|
||||||
|
with open("sacred-files/metrics.txt", 'w') as file:
|
||||||
|
file.write(f"loss: {loss}")
|
||||||
|
file.write(f"accuracy: {accuracy}")
|
||||||
|
|
||||||
|
ex.add_artifact("model.h5")
|
||||||
|
ex.add_artifact("sacred-files/parameters.json")
|
||||||
|
ex.add_artifact("sacred-files/source_code.py")
|
||||||
|
ex.add_artifact("sacred-files/metrics.txt")
|
||||||
|
Loading…
Reference in New Issue
Block a user