Skip to content

Commit

Permalink
refactor: build_model -> build rename
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperHG90 committed Jan 5, 2021
1 parent 31544b1 commit 2461bd1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ model = PivenMlpModel(
lr=0.0001,
)
# Normalize input data
model.build_model(preprocess=StandardScaler())
model.build(preprocess=StandardScaler())
# You can pass any arguments that you would also pass to a keras model
model.fit(x_train, y_train, model__epochs=200, model__validation_split=.2)
model.score()
```

You can score the model by calling the `score()` method:
Expand Down
2 changes: 1 addition & 1 deletion src/piven/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def load_model_from_disk(build_fn: Callable, path: str):
return load_piven_model(build_fn, path)

@abc.abstractmethod
def build_model(self, **build_params):
def build(self, **build_params):
pass

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/piven/models/mlp_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def piven_model(


class PivenMlpModel(PivenBaseModel):
def build_model(self, preprocess: Union[None, Pipeline, TransformerMixin] = None):
def build(self, preprocess: Union[None, Pipeline, TransformerMixin] = None):
# All build params are passed to init and should be checked here
check_model_params(**self.params)
model = PivenKerasRegressor(build_fn=piven_model, **self.params)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_mlp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def sklearn_preprocessing_pipeline():

class TestPivenMlpExperiment:
def test_experiment_build_model(self, experiment):
experiment.build_model()
experiment.build()

def test_experiment_fit_model_no_preprocess(self, mock_data, experiment):
x_train, x_valid, y_train, y_valid = mock_data
experiment.build_model()
experiment.build()
experiment.fit(
x_train,
y_train,
Expand All @@ -83,7 +83,7 @@ def test_experiment_fit_model_with_preprocess(
bias_init_high=3.0,
lr=0.0001,
)
experiment.build_model(preprocess=sklearn_preprocessing_pipeline)
experiment.build(preprocess=sklearn_preprocessing_pipeline)
experiment.fit(
x,
y,
Expand All @@ -94,7 +94,7 @@ def test_experiment_fit_model_with_preprocess(

def test_experiment_io(self, mock_data, experiment):
x_train, x_valid, y_train, y_valid = mock_data
experiment.build_model()
experiment.build()
experiment.fit(
x_train,
y_train,
Expand All @@ -108,7 +108,7 @@ def test_experiment_io(self, mock_data, experiment):

def test_experiment_scoring(self, mock_data, experiment):
x_train, x_valid, y_train, y_valid = mock_data
experiment.build_model()
experiment.build()
experiment.fit(x_train, y_train, model__epochs=3)
y_pred, y_pi_low, y_pi_high = experiment.predict(
x_valid, return_prediction_intervals=True
Expand All @@ -124,7 +124,7 @@ def test_experiment_scoring(self, mock_data, experiment):

def test_experiment_logging(self, mock_data, experiment):
x_train, x_valid, y_train, y_valid = mock_data
experiment.build_model()
experiment.build()
experiment.fit(x_train, y_train, model__epochs=3)
with tempfile.TemporaryDirectory() as tmpdir:
experiment.log(x_valid, y_valid, tmpdir, model=True, predictions=True)
Expand Down

0 comments on commit 2461bd1

Please sign in to comment.