def model(titanic_vd): create_verticapy_schema() model_class = KNeighborsClassifier("knn_model_test", ) model_class.drop() model_class.fit("public.titanic", ["age", "fare"], "survived") yield model_class model_class.drop()
def test_model_from_vDF(self, titanic_vd): model_test = KNeighborsClassifier("knn_from_vDF", ) model_test.drop() model_test.fit(titanic_vd, ["age"], "survived") assert model_test.score( cutoff=0.9, method="accuracy") == pytest.approx(0.5890710382513661) model_test.drop()
def test_contour(self, titanic_vd): model_test = KNeighborsClassifier("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()) == 34 model_test.drop()
def model(base, titanic_vd): try: create_verticapy_schema(base.cursor) except: pass model_class = KNeighborsClassifier("knn_model_test", cursor=base.cursor) model_class.drop() model_class.fit("public.titanic", [ "age", "fare", ], "survived") yield model_class model_class.drop()
def test_drop(self): model_test = KNeighborsClassifier("model_test_drop", ) model_test.drop() model_test.fit("public.titanic", ["age"], "survived") current_cursor().execute( "SELECT model_name FROM verticapy.models WHERE model_name IN ('model_test_drop', '\"model_test_drop\"')" ) assert current_cursor().fetchone()[0] in ( "model_test_drop", '"model_test_drop"', ) model_test.drop() current_cursor().execute( "SELECT model_name FROM verticapy.models WHERE model_name IN ('model_test_drop', '\"model_test_drop\"')" ) assert current_cursor().fetchone() is None
def test_drop(self, base): model_test = KNeighborsClassifier("model_test_drop", cursor=base.cursor) model_test.drop() model_test.fit("public.titanic", [ "age", ], "survived") base.cursor.execute( "SELECT model_name FROM verticapy.models WHERE model_name IN ('model_test_drop', '\"model_test_drop\"')" ) assert base.cursor.fetchone()[0] in ('model_test_drop', '"model_test_drop"') model_test.drop() base.cursor.execute( "SELECT model_name FROM verticapy.models WHERE model_name IN ('model_test_drop', '\"model_test_drop\"')" ) assert base.cursor.fetchone() is None
def test_drop(self, base, world_vd): base.cursor.execute("DROP TABLE IF EXISTS public.drop_data") base.cursor.execute( 'CREATE TABLE IF NOT EXISTS public.drop_data(Id identity(2000) primary key, transportation VARCHAR, gender VARCHAR, "owned cars" INT, cost VARCHAR, income CHAR(4)) ORDER BY id SEGMENTED BY HASH(id) ALL NODES KSAFE;' ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Bus', 'Male', 0, 'Cheap', 'Low')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Bus', 'Male', 1, 'Cheap', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Train', 'Female', 1, 'Cheap', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Bus', 'Female', 0, 'Cheap', 'Low')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Bus', 'Male', 1, 'Cheap', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Train', 'Male', 0, 'Standard', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Train', 'Female', 1, 'Standard', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Car', 'Female', 1, 'Expensive', 'Hig')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Car', 'Male', 2, 'Expensive', 'Med')" ) base.cursor.execute( "INSERT INTO drop_data(transportation, gender, \"owned cars\", cost, income) VALUES ('Car', 'Female', 2, 'Expensive', 'Hig')" ) base.cursor.execute("COMMIT") # table base.cursor.execute("DROP TABLE IF EXISTS public.verticapy_table_test") base.cursor.execute("CREATE TABLE verticapy_table_test AS SELECT 1;") drop("verticapy_table_test", base.cursor) base.cursor.execute( "SELECT table_name FROM columns WHERE table_name = 'verticapy_table_test' GROUP BY 1;" ) result = base.cursor.fetchall() assert result == [] # view base.cursor.execute("DROP VIEW IF EXISTS public.verticapy_view_test") base.cursor.execute("CREATE VIEW verticapy_view_test AS SELECT 1;") drop("verticapy_view_test", base.cursor) base.cursor.execute( "SELECT table_name FROM view_columns WHERE table_name = 'verticapy_view_test' GROUP BY 1;" ) result = base.cursor.fetchall() assert result == [] # text index base.cursor.execute( "CREATE TEXT INDEX drop_index ON drop_data (id, transportation);") drop("drop_index", base.cursor) with pytest.raises(vertica_python.errors.MissingRelation): base.cursor.execute("SELECT * FROM drop_index;") # model base.cursor.execute("DROP MODEL IF EXISTS public.verticapy_model_test") base.cursor.execute( "SELECT NAIVE_BAYES('public.verticapy_model_test', 'public.drop_data', 'transportation', 'gender, cost');" ) drop("verticapy_model_test", base.cursor) base.cursor.execute( "SELECT model_name FROM models WHERE model_name = 'verticapy_model_test' GROUP BY 1;" ) result = base.cursor.fetchall() assert result == [] # verticapy model with warnings.catch_warnings(record=True) as w: drop("verticapy", base.cursor, method="schema") create_verticapy_schema(base.cursor) model = KNeighborsClassifier("verticapy_model_test", base.cursor) model.fit("public.drop_data", [ "gender", "cost", ], "transportation") drop("verticapy_model_test", base.cursor) base.cursor.execute( "SELECT model_name FROM verticapy.models WHERE model_name = 'verticapy_model_test' GROUP BY 1;" ) result = base.cursor.fetchall() assert result == [] drop("verticapy", base.cursor, method="schema") # geo index world_copy = world_vd.copy() world_copy["id"] = "ROW_NUMBER() OVER (ORDER BY pop_est)" result = create_index(world_copy, "id", "geometry", "world_polygons", True) drop( "world_polygons", base.cursor, ) with pytest.raises(vertica_python.errors.QueryError): describe_index( "world_polygons", base.cursor, True, ) drop(cursor=base.cursor, )