-
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.
- Loading branch information
Showing
4 changed files
with
27 additions
and
7 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,27 +1,40 @@ | ||
from sklearn.base import BaseEstimator, RegressorMixin | ||
from sklearn.utils import check_array, check_X_y | ||
from sklearn.utils.validation import check_is_fitted | ||
from . import core | ||
|
||
"""api.py defines user interfaces to FFX. run() runs the complete method. | ||
FFXRegressor is a Scikit-learn style regressor.""" | ||
""" 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) | ||
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): | ||
X, y = check_X_y(X, y, y_numeric=True, multi_output=False) | ||
# if X is a Pandas DataFrame, we don't have to pass in varnames. | ||
# otherwise we make up placeholders. | ||
# 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] | ||
return self | ||
|
||
def predict(self, X): | ||
check_is_fitted(self, "_model") | ||
X = check_array(X, accept_sparse=False) | ||
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