forked from oneconvergence/dkube-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
37 lines (33 loc) · 1.03 KB
/
predict.py
File metadata and controls
37 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from tensorflow import keras
from dkube.sdk import DkubeFeatureSet
import pandas as pd
import json, os
model_dir = "/model"
test_fs_dir= "/test_fs"
metadata = {
"outputs": [
{
"storage": "inline",
"type": "table",
"format": "csv",
"header": ["cv_accuracy", "cv_brier_score"],
"source": "0.78, 0.88",
}
]
}
with open("/output/metrics.json", "w") as f:
json.dump(metadata, f)
def predict():
os.system ("ls -l " + test_fs_dir)
test_df = DkubeFeatureSet.read_features(test_fs_dir)
print (test_df.columns)
x_test= test_df.drop(["PassengerId"], 1).values
model = keras.models.load_model(os.path.join(model_dir, "1"))
y_pred = model.predict(x_test)
y_pred[y_pred <= 0.5] = 0
y_pred[y_pred > 0.5] = 1
output = pd.DataFrame({'PassengerId': test_df.PassengerId, 'Survived': y_pred.flatten().tolist()})
output.to_csv("/output/prediction.csv", index=False)
print("predictions generated.")
if __name__ == "__main__":
predict()