Exemple #1
0
 def test_to_sql(self, model, titanic_vd):
     model_test = DecisionTreeClassifier("rfc_sql_test")
     model_test.drop()
     model_test.fit(titanic_vd, ["age", "fare", "sex"], "survived")
     current_cursor().execute(
         "SELECT PREDICT_RF_CLASSIFIER(* USING PARAMETERS model_name = 'rfc_sql_test', match_by_pos=True)::int, {}::int FROM (SELECT 30.0 AS age, 45.0 AS fare, 'male' AS sex) x"
         .format(model_test.to_sql()))
     prediction = current_cursor().fetchone()
     assert prediction[0] == prediction[1]
     model_test.drop()
 def test_contour(self, base, titanic_vd):
     model_test = DecisionTreeClassifier("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()) == 34
     model_test.drop()
    def test_model_from_vDF(self, base, dtc_data_vd):
        base.cursor.execute("DROP MODEL IF EXISTS tc_from_vDF")
        model_test = DecisionTreeClassifier("tc_from_vDF", cursor=base.cursor)
        model_test.fit(dtc_data_vd,
                       ["Gender", '"owned cars"', "cost", "income"],
                       "TransPortation")

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

        model_test.drop()
 def test_to_sql(self, model, titanic_vd):
     model_test = DecisionTreeClassifier("rfc_sql_test", cursor=model.cursor)
     model_test.drop()
     model_test.fit(titanic_vd, ["age", "fare", "sex"], "survived")
     model.cursor.execute(
         "SELECT PREDICT_RF_CLASSIFIER(* USING PARAMETERS model_name = 'rfc_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], 1e-2)
     model_test.drop()
 def test_to_python(self, model, titanic_vd):
     model_test = DecisionTreeClassifier("rfc_python_test", cursor=model.cursor)
     model_test.drop()
     model_test.fit(titanic_vd, ["age", "fare", "sex"], "embarked")
     model_test.cursor.execute(
         "SELECT PREDICT_RF_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_RF_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]
    def test_drop(self, base):
        base.cursor.execute("DROP MODEL IF EXISTS decision_tc_model_test_drop")
        model_test = DecisionTreeClassifier("decision_tc_model_test_drop",
                                            cursor=base.cursor)
        model_test.fit(
            "public.dtc_data",
            ["Gender", '"owned cars"', "cost", "income"],
            "TransPortation",
        )

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

        model_test.drop()
        base.cursor.execute(
            "SELECT model_name FROM models WHERE model_name = 'decision_tc_model_test_drop'"
        )
        assert base.cursor.fetchone() is None