-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update runffx tool for Python 3 (#32)
* Bump version number for PyPI release, and include Py3.6 as supported. * Update push_to_pypi to use twine. * Update runffx tool for Python 3 * Added a Scikit-learn API, bumped FFX version number and Python/Sklearn numbers. * Squeeze an unused dimension in y. Move a comment in api. Add a commented line for pushing to test-PyPI. * Bump version number again and remember to rm old versions when uploading to PyPI. * Corrected the count of GP nodes (complexity) and used it in existing test, also added the code from the README as a test. * Bump version number for PyPI
- Loading branch information
Showing
8 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
from sklearn.base import BaseEstimator, RegressorMixin | ||
from . import core | ||
|
||
"""api.py defines user interfaces to FFX. run() runs the complete method. | ||
FFXRegressor is a Scikit-learn style regressor.""" | ||
|
||
def run(train_X, train_y, test_X, test_y, varnames=None, verbose=False): | ||
return core.MultiFFXModelFactory().build(train_X, train_y, test_X, test_y, varnames, verbose) | ||
|
||
class FFXRegressor(BaseEstimator, RegressorMixin): | ||
"""This class provides a Scikit-learn style estimator.""" | ||
def __init__(self): | ||
pass | ||
def fit(self, X, y): | ||
# if X is a Pandas DataFrame, we don't have to pass in varnames. | ||
# otherwise we make up placeholders. | ||
if hasattr(X, 'columns'): | ||
varnames = None | ||
else: | ||
varnames = ["X%d" % i for i in range(len(X))] | ||
self._models = run(X, y, X, y, varnames=varnames) | ||
self._model = self._models[-1] | ||
def predict(self, X): | ||
return self._model.simulate(X) | ||
def complexity(self): | ||
return self._model.complexity() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
python setup.py sdist bdist_egg register upload | ||
rm dist/* | ||
# they don't recommend using "setup.py register upload" anymore | ||
python setup.py sdist bdist_egg bdist_wheel # just build | ||
#twine upload --repository-url https://test.pypi.org/legacy/ dist/* # testpypi | ||
twine upload dist/* # pip install twine if needed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# this is the tiny example in the README, and now it | ||
# also prints out numBases and complexity for each model | ||
|
||
import numpy as np | ||
import ffx | ||
|
||
train_X = np.array( [ (1.5,2,3), (4,5,6) ] ).T | ||
train_y = np.array( [1,2,3]) | ||
|
||
test_X = np.array( [ (5.241,1.23, 3.125), (1.1,0.124,0.391) ] ).T | ||
test_y = np.array( [3.03,0.9113,1.823]) | ||
|
||
models = ffx.run(train_X, train_y, test_X, test_y, ["a", "b"]) | ||
print("numBases: GP-complexity : model") | ||
for model in models: | ||
yhat = model.simulate(test_X) | ||
print(model.numBases(), ":", model.complexity(), ": ", model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
|
||
import numpy as np | ||
import ffx | ||
|
||
# This creates a dataset of 2 predictors | ||
X = np.random.random((20, 2)) | ||
y = 0.1 * X[:, 0] + 0.5 * X[:, 1] | ||
|
||
train_X, test_X = X[:10], X[10:] | ||
train_y, test_y = y[:10], y[10:] | ||
|
||
FFX = ffx.FFXRegressor() | ||
FFX.fit(train_X, train_y) | ||
print("Prediction:", FFX.predict(test_X)) | ||
print("Score:", FFX.score(test_X, test_y)) | ||
print("Complexity:", FFX.complexity()) | ||
print("Model:", FFX._model) |