From db0e1700c888fd96eed43b8ffcafd4efa456a2b1 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Fri, 27 Nov 2020 22:14:14 +0000 Subject: [PATCH 1/2] Install bayesian-optimization from pip archive & add tests --- Dockerfile | 2 +- tests/test_bayes_opt.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/test_bayes_opt.py diff --git a/Dockerfile b/Dockerfile index 2e8c5d3b..a930bd6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -196,7 +196,7 @@ RUN pip install mpld3 && \ pip install missingno && \ pip install pandas-profiling && \ pip install s2sphere && \ - pip install git+https://github.com/fmfn/BayesianOptimization.git && \ + pip install bayesian-optimization && \ pip install matplotlib-venn && \ pip install pyldavis && \ pip install mlxtend && \ diff --git a/tests/test_bayes_opt.py b/tests/test_bayes_opt.py new file mode 100644 index 00000000..99af8aea --- /dev/null +++ b/tests/test_bayes_opt.py @@ -0,0 +1,32 @@ +import unittest + +from bayes_opt import BayesianOptimization + + +class TestBayesOpt(unittest.TestCase): + def test_optimize(self): + # Bounded region of parameter space + pbounds = {'x': (2, 4), 'y': (-3, 3)} + + optimizer = BayesianOptimization( + f=black_box_function, + pbounds=pbounds, + random_state=1, + ) + + optimizer.maximize( + init_points=2, + n_iter=1, + ) + + self.assertAlmostEqual(-7, optimizer.max['target'], places=0) # compares using 0 decimal + + +def black_box_function(x, y): + """Function with unknown internals we wish to maximize. + + This is just serving as an example, for all intents and + purposes think of the internals of this function, i.e.: the process + which generates its output values, as unknown. + """ + return -x ** 2 - (y - 1) ** 2 + 1 \ No newline at end of file From 4c68822ea4d931db052337621fa588522e4dd696 Mon Sep 17 00:00:00 2001 From: Vincent Roseberry Date: Fri, 27 Nov 2020 22:18:39 +0000 Subject: [PATCH 2/2] install openslide & category-encoders from pip archive --- Dockerfile | 6 ++---- tests/test_category_encoders.py | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index a930bd6c..a92ca383 100644 --- a/Dockerfile +++ b/Dockerfile @@ -283,8 +283,7 @@ RUN pip install --upgrade cython && \ pip install fasttext && \ apt-get install -y libhunspell-dev && pip install hunspell && \ pip install annoy && \ - # Need to use CountEncoder from category_encoders before it's officially released - pip install git+https://github.com/scikit-learn-contrib/categorical-encoding.git && \ + pip install category_encoders && \ # google-cloud-automl 2.0.0 introduced incompatible API changes, need to pin to 1.0.1 pip install google-cloud-automl==1.0.1 && \ # Newer version crashes (latest = 1.14.0) when running tensorflow. @@ -347,8 +346,7 @@ RUN pip install bcolz && \ pip install --upgrade Pillow && \ # Install openslide and its python binding apt-get install -y openslide-tools && \ - # b/152402322 install latest from pip once is in: https://github.com/openslide/openslide-python/pull/76 - pip install git+git://github.com/rosbo/openslide-python.git@fix-setup && \ + pip install openslide-python && \ pip install ptyprocess && \ pip install Pygments && \ pip install pyparsing && \ diff --git a/tests/test_category_encoders.py b/tests/test_category_encoders.py index 54d6024e..4aced160 100644 --- a/tests/test_category_encoders.py +++ b/tests/test_category_encoders.py @@ -1,12 +1,12 @@ import unittest +from category_encoders import CountEncoder +import pandas as pd + + ## Need to make sure we have CountEncoder available from the category_encoders library class TestCategoryEncoders(unittest.TestCase): def test_count_encoder(self): - - from category_encoders import CountEncoder - import pandas as pd - encoder = CountEncoder(cols="data") data = pd.DataFrame([1, 2, 3, 1, 4, 5, 3, 1], columns=["data"])