def test_generate_test(self): from ramp.modeling import generate_test model_def = self.make_model_def_basic() x, y, fitted_model = fit_model(model_def, self.data) x, y_true = generate_test(model_def, self.data[:3], fitted_model) y_preds = fitted_model.model_def.estimator.predict(x) self.assertEqual(len(x), 3) self.assertEqual(len(y_true), 3) self.assertEqual(len(y_preds), 3)
def test_predict(self): model_def = self.make_model_def_basic() x, y, fitted_model = fit_model(model_def, self.data) x, y_true = modeling.generate_test(model_def, self.data[:3], fitted_model) y_preds = fitted_model.fitted_estimator.predict(x) self.assertEqual(len(x), 3) self.assertEqual(len(y_true), 3) self.assertEqual(len(y_preds), 3) y_preds2 = modeling.predict_with_model(model_def, self.data[:3], fitted_model) assert_almost_equal(y_preds, y_preds2.values)
def test_predictions_nest(self): inner_estimator = DummyEstimator() inner_model = ModelDefinition(features=[F("a")], estimator=inner_estimator, target=F("b")) features = [F("c"), Predictions(inner_model)] target = F("b") estimator = DummyEstimator() model_def = ModelDefinition(features=features, estimator=estimator, target=target) train_index = self.data.index[:5] x, y, fitted_model = fit_model(model_def, self.data, train_index=train_index) self.assertEqual(fitted_model.fitted_features[1].trained_data.fitted_estimator.fitx.shape, (5, 1)) self.assertEqual(x.shape, (len(train_index), 2)) x, y_true = modeling.generate_test(model_def, self.data[:3], fitted_model) assert_almost_equal(x[x.columns[1]].values, np.zeros(3))
def _train(self, train_data): x, y, fitted_model = fit_model(self.model_def, train_data) return fitted_model
def test_fit_model(self): model_def = self.make_model_def_basic() x, y, fitted_model = fit_model(model_def, self.data) fe = fitted_model.fitted_estimator self.assertEqual(fe.fitx.shape, x.shape) self.assertEqual(fe.fity.shape, y.shape)
def test_generate_test(self): model_def = self.make_model_def_basic() x, y, fitted_model = fit_model(model_def, self.data) test_index = self.data.index[:5] x_test, y_test = generate_test(model_def, self.data.loc[test_index], fitted_model) assert_almost_equal(x_test.index, test_index)