Esempio n. 1
0
 def test_to_json_multiclass(self, titanic_vd):
     titanic = titanic_vd.copy()
     titanic.fillna()
     path = "verticapy_test_xgbr.json"
     X = ["survived", "age", "fare"]
     y = "pclass"
     model = XGBoostClassifier(
         "verticapy_xgb_multiclass_classifier_test", max_ntree=10, max_depth=5
     )
     model.drop()
     model.fit(titanic, X, y)
     X_test = titanic[X].to_numpy()
     y_test_vertica = model.to_python(return_proba=True)(X_test).argsort()
     if os.path.exists(path):
         os.remove(path)
     model.to_json(path)
     model_python = xgb.XGBClassifier()
     model_python.load_model(path)
     y_test_python = model_python.predict_proba(X_test).argsort()
     result = (y_test_vertica - y_test_python) ** 2
     result = result.sum() / len(result)
     assert result == 0.0
     y_test_vertica = model.to_python()(X_test)
     y_test_python = model_python.predict(X_test)
     result = (y_test_vertica - y_test_python) ** 2
     result = result.sum() / len(result)
     assert result == 0.0
     model.drop()
     os.remove(path)
Esempio n. 2
0
 def test_contour(self, titanic_vd):
     model_test = XGBoostClassifier("model_contour",)
     model_test.drop()
     model_test.fit(
         titanic_vd, ["age", "fare"], "survived",
     )
     result = model_test.contour()
     assert len(result.get_default_bbox_extra_artists()) in (38, 40, 43)
     model_test.drop()
Esempio n. 3
0
 def test_to_sql(self, model, titanic_vd):
     model_test = XGBoostClassifier("xgb_sql_test", cursor=model.cursor)
     model_test.drop()
     model_test.fit(titanic_vd, ["age", "fare", "sex"], "survived")
     model.cursor.execute(
         "SELECT PREDICT_XGB_CLASSIFIER(* USING PARAMETERS model_name = 'xgb_sql_test', match_by_pos=True, class=1, type='probability')::float, {}::float FROM (SELECT 30.0 AS age, 45.0 AS fare, 'male' AS sex) x"
         .format(model_test.to_sql()))
     prediction = model.cursor.fetchone()
     assert prediction[0] == pytest.approx(prediction[1])
     model_test.drop()
Esempio n. 4
0
    def test_model_from_vDF(self, base, xgbc_data_vd):
        base.cursor.execute("DROP MODEL IF EXISTS xgbc_from_vDF")
        model_test = XGBoostClassifier("xgbc_from_vDF", cursor=base.cursor)
        model_test.fit(
            xgbc_data_vd,
            ["Gender", '"owned cars"', "cost", "income"],
            "TransPortation",
        )

        base.cursor.execute(
            "SELECT model_name FROM models WHERE model_name = 'xgbc_from_vDF'")
        assert base.cursor.fetchone()[0] == "xgbc_from_vDF"

        model_test.drop()
Esempio n. 5
0
 def test_contour(self, base, titanic_vd):
     model_test = XGBoostClassifier("model_contour", cursor=base.cursor)
     model_test.drop()
     model_test.fit(
         titanic_vd,
         [
             "age",
             "fare",
         ],
         "survived",
     )
     result = model_test.contour()
     assert len(result.get_default_bbox_extra_artists()) == 38
     model_test.drop()
Esempio n. 6
0
 def test_to_python(self, model, titanic_vd):
     model_test = XGBoostClassifier("rfc_python_test", cursor=model.cursor)
     model_test.drop()
     model_test.fit(titanic_vd, ["age", "fare", "sex"], "embarked")
     model_test.cursor.execute(
         "SELECT PREDICT_XGB_CLASSIFIER(30.0, 45.0, 'male' USING PARAMETERS model_name = 'rfc_python_test', match_by_pos=True)"
     )
     prediction = model_test.cursor.fetchone()[0]
     assert prediction == model_test.to_python(return_str=False)(
         [[30.0, 45.0, 'male']])[0]
     model_test.cursor.execute(
         "SELECT PREDICT_XGB_CLASSIFIER(30.0, 145.0, 'female' USING PARAMETERS model_name = 'rfc_python_test', match_by_pos=True)"
     )
     prediction = model_test.cursor.fetchone()[0]
     assert prediction == model_test.to_python(return_str=False)(
         [[30.0, 145.0, 'female']])[0]
Esempio n. 7
0
    def test_drop(self):
        current_cursor().execute("DROP MODEL IF EXISTS xgbc_model_test_drop")
        model_test = XGBoostClassifier("xgbc_model_test_drop",)
        model_test.fit(
            "public.xgbc_data",
            ["Gender", '"owned cars"', "cost", "income"],
            "TransPortation",
        )

        current_cursor().execute(
            "SELECT model_name FROM models WHERE model_name = 'xgbc_model_test_drop'"
        )
        assert current_cursor().fetchone()[0] == "xgbc_model_test_drop"

        model_test.drop()
        current_cursor().execute(
            "SELECT model_name FROM models WHERE model_name = 'xgbc_model_test_drop'"
        )
        assert current_cursor().fetchone() is None