Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Change how we export the fitted_pipeline in the execute_model method (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhang-gp committed Dec 20, 2019
1 parent 4db39f8 commit 7d07e32
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
13 changes: 8 additions & 5 deletions foreshadow/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,17 @@ def execute_model(fs, X_train, y_train, X_test, y_test):
logging.info("Final Results: ")
logging.info(score)

fs.to_json("foreshadow.json")
json_file_location = "foreshadow.json"
fs.to_json(json_file_location)

with open("foreshadow.p", "wb") as fopen:
pickle.dump(fs, fopen)
pickled_fitted_pipeline_location = "foreshadow_fitted_pipeline.p"
fs.pickle_fitted_pipeline(pickled_fitted_pipeline_location)

logging.info(
"Serialized foreshadow pipeline has been saved to foreshadow.p "
"and foreshadow.json. Refer to docs to read and process."
"Serialized foreshadow pipeline has been saved to {} "
"and {}. Refer to docs to read and process.".format(
json_file_location, pickled_fitted_pipeline_location
)
)


Expand Down
20 changes: 10 additions & 10 deletions foreshadow/tests/test_foreshadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def test_foreshadow_serialization_adults_classification():
print(score)


def test_foreshadow_pickling_and_unpickling_unfitted():
def test_foreshadow_pickling_and_unpickling_unfitted(tmpdir):
from foreshadow.foreshadow import Foreshadow
from foreshadow.estimators import AutoEstimator

Expand All @@ -960,10 +960,10 @@ def test_foreshadow_pickling_and_unpickling_unfitted():
estimator=estimator, problem_type=ProblemType.CLASSIFICATION
)
with pytest.raises(ValueError):
shadow.pickle_fitted_pipeline("fitted_pipeline.p")
shadow.pickle_fitted_pipeline(tmpdir.join("fitted_pipeline.p"))


def test_foreshadow_pickling_and_unpickling_non_tpot():
def test_foreshadow_pickling_and_unpickling_non_tpot(tmpdir):
from foreshadow.foreshadow import Foreshadow
import pandas as pd
import numpy as np
Expand All @@ -985,13 +985,13 @@ def test_foreshadow_pickling_and_unpickling_non_tpot():
shadow = Foreshadow(
estimator=LogisticRegression(), problem_type=ProblemType.CLASSIFICATION
)

pickled_file_location = tmpdir.join("fitted_pipeline.p")
shadow.fit(X_train, y_train)
shadow.pickle_fitted_pipeline("fitted_pipeline.p")
shadow.pickle_fitted_pipeline(pickled_file_location)

import pickle

with open("fitted_pipeline.p", "rb") as fopen:
with open(pickled_file_location, "rb") as fopen:
pipeline = pickle.load(fopen)

pipeline.fit(X_train, y_train)
Expand All @@ -1010,7 +1010,7 @@ def test_foreshadow_pickling_and_unpickling_non_tpot():


@slow
def test_foreshadow_pickling_and_unpickling_tpot():
def test_foreshadow_pickling_and_unpickling_tpot(tmpdir):
from foreshadow.foreshadow import Foreshadow
import pandas as pd
import numpy as np
Expand Down Expand Up @@ -1038,13 +1038,13 @@ def test_foreshadow_pickling_and_unpickling_tpot():
shadow = Foreshadow(
estimator=estimator, problem_type=ProblemType.CLASSIFICATION
)

pickled_file_location = tmpdir.join("fitted_pipeline.p")
shadow.fit(X_train, y_train)
shadow.pickle_fitted_pipeline("fitted_pipeline.p")
shadow.pickle_fitted_pipeline(pickled_file_location)

import pickle

with open("fitted_pipeline.p", "rb") as fopen:
with open(pickled_file_location, "rb") as fopen:
pipeline = pickle.load(fopen)

pipeline.fit(X_train, y_train)
Expand Down

0 comments on commit 7d07e32

Please sign in to comment.