def run_pyearth(X, y, **kwargs): '''Run with pyearth. Return prediction value, training time, and number of forward pass iterations.''' model = Earth(**kwargs) t0 = time.time() model.fit(X, y) t1 = time.time() y_pred = model.predict(X) forward_iterations = len(model.forward_trace()) - 1 return y_pred, t1 - t0, forward_iterations
def test_untrained(): model = Earth(**default_params) assert_raises(NotFittedError, model.predict, X) assert_raises(NotFittedError, model.transform, X) assert_raises(NotFittedError, model.predict_deriv, X) assert_raises(NotFittedError, model.score, X) # the following should be changed to raise NotFittedError assert_equal(model.forward_trace(), None) assert_equal(model.pruning_trace(), None) assert_equal(model.summary(), "Untrained Earth Model")
def test_patsy_compatibility(): import pandas import patsy X_df = pandas.DataFrame(X) y_df = pandas.DataFrame(y) colnames = ['xx' + str(i) for i in range(X.shape[1])] X_df.columns = colnames X_df['y'] = y y_df, X_df = patsy.dmatrices( 'y ~ xx0 + xx1 + xx2 + xx3 + xx4 + xx5 + xx6 + xx7 + xx8 + xx9 - 1', data=X_df) model = Earth(**default_params).fit(X_df, y_df) assert_list_equal(colnames, model.forward_trace()._getstate()['xlabels'])
def test_patsy_compatibility(): import pandas import patsy X_df = pandas.DataFrame(X) y_df = pandas.DataFrame(y) colnames = ['xx' + str(i) for i in range(X.shape[1])] X_df.columns = colnames X_df['y'] = y y_df, X_df = patsy.dmatrices( 'y ~ xx0 + xx1 + xx2 + xx3 + xx4 + xx5 + xx6 + xx7 + xx8 + xx9 - 1', data=X_df) model = Earth(**default_params).fit(X_df, y_df) assert_list_equal( colnames, model.forward_trace()._getstate()['xlabels'])
def test_untrained(): # NotFittedError moved from utils.validation to exceptions # some time after 0.17.1 try: from sklearn.exceptions import NotFittedError except ImportError: from sklearn.utils.validation import NotFittedError # Make sure calling methods that require a fitted Earth object # raises the appropriate exception when using a not yet fitted # Earth object model = Earth(**default_params) assert_raises(NotFittedError, model.predict, X) assert_raises(NotFittedError, model.transform, X) assert_raises(NotFittedError, model.predict_deriv, X) assert_raises(NotFittedError, model.score, X) # the following should be changed to raise NotFittedError assert_equal(model.forward_trace(), None) assert_equal(model.pruning_trace(), None) assert_equal(model.summary(), "Untrained Earth Model")