Model.to_sql

In [ ]:
Model.to_sql(X: list = [])

Returns the SQL code needed to deploy the model without using Vertica built-in functions. This function only works for regression, binary classification and preprocessing. For binary classification, this function returns the probability of class 1.

Parameters

Name Type Optional Description
X
list
input predictors name.

Returns

str : SQL code

Example

In [16]:
from verticapy.learn.ensemble import XGBoostClassifier
model = XGBoostClassifier("xgb_titanic", max_ntree = 2, max_depth = 2)
model.drop()
model.fit("public.titanic", 
          ["age", "fare", "pclass",],
          "survived")

# Returns the string needed to deploy the model's probability in Standard SQL
print(model.to_sql())
CASE WHEN "age" IS NULL OR "fare" IS NULL OR "pclass" IS NULL THEN NULL ELSE 1 - 1 / (1 + EXP(-0.43652089804547567 + 0.1 * ((CASE WHEN "fare" < 48.030862 THEN -0.325084 ELSE 1.2022 END) + (CASE WHEN "pclass" < 2.062500 THEN 0.556098 ELSE -0.615402 END)))) END
In [17]:
from verticapy.learn.ensemble import XGBoostClassifier
model = XGBoostRegressor("xgb_titanic", max_ntree = 2, max_depth = 2)
model.drop()
model.fit("public.titanic", 
          ["age", "fare", "pclass",],
          "survived")

# Returns the string needed to deploy the model's prediction in Standard SQL
print(model.to_sql())
CASE WHEN "age" IS NULL OR "fare" IS NULL OR "pclass" IS NULL THEN NULL ELSE 0.392570281124498 + ((CASE WHEN "fare" < 48.030862 THEN -0.077519 ELSE 0.286675 END) + (CASE WHEN "pclass" < 2.062500 THEN 0.133376 ELSE -0.145705 END)) * 0.1 END
In [20]:
from verticapy.learn.cluster import KMeans
model = KMeans("kmeans_iris", n_cluster = 2)
model.drop()
model.fit("public.iris",)

# Returns the string needed to deploy the model's estimated centers in Standard SQL
print(model.to_sql())
CASE WHEN "SepalLengthCm" IS NULL OR "SepalWidthCm" IS NULL OR "PetalLengthCm" IS NULL OR "PetalWidthCm" IS NULL THEN NULL WHEN SQRT(POWER("SepalLengthCm" - 5.00566037735849, 2) + POWER("SepalWidthCm" - 3.36037735849057, 2) + POWER("PetalLengthCm" - 1.5622641509434, 2) + POWER("PetalWidthCm" - 0.288679245283019, 2)) <= SQRT(POWER("SepalLengthCm" - 6.30103092783505, 2) + POWER("SepalWidthCm" - 2.88659793814433, 2) + POWER("PetalLengthCm" - 4.95876288659794, 2) + POWER("PetalWidthCm" - 1.69587628865979, 2)) THEN 1 ELSE 0 END
In [21]:
from verticapy.learn.preprocessing import Normalizer
model = Normalizer("norm_titanic",)
model.drop()
model.fit("public.titanic",)

# Returns the string needed to deploy the model's transformation in Standard SQL
print(model.to_sql())
("pclass" - 2.28444084278768) / 0.842485636190292 AS "pclass", ("survived" - 0.364667747163695) / 0.481532018641288 AS "survived", ("age" - 30.1524573721163) / 14.4353046299159 AS "age", ("sibsp" - 0.504051863857374) / 1.04111727241629 AS "sibsp", ("parch" - 0.378444084278768) / 0.868604707790392 AS "parch", ("fare" - 33.9637936739659) / 52.6460729831293 AS "fare", ("body" - 164.14406779661) / 96.5760207557808 AS "body"