Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
conn = read_auto_connect()
cursor = conn.cursor()
else:
conn = False
check_cursor(cursor)
if not(type(n_cluster) == list):
L = range(n_cluster[0], n_cluster[1])
else:
L = n_cluster
L.sort()
schema, relation = schema_relation(input_relation)
schema = str_column(schema)
relation_alpha = ''.join(ch for ch in relation if ch.isalnum())
for i in L:
cursor.execute("DROP MODEL IF EXISTS {}.__vpython_kmeans_tmp_model_{}__".format(schema, relation_alpha))
model = KMeans("{}.__vpython_kmeans_tmp_model_{}__".format(schema, relation_alpha), cursor, i, init, max_iter, tol)
model.fit(input_relation, X)
score = model.metrics.values["value"][3]
if (score > elbow_score_stop):
return i
score_prev = score
if (conn):
conn.close()
print("\u26A0 The K was not found. The last K (= {}) is returned with an elbow score of {}".format(i, score))
return i
#---#
cursor = conn.cursor()
else:
conn = False
check_cursor(cursor)
schema, relation = schema_relation(input_relation)
schema = str_column(schema)
relation_alpha = ''.join(ch for ch in relation if ch.isalnum())
all_within_cluster_SS = []
if not(type(n_cluster) == list):
L = [i for i in range(n_cluster[0], n_cluster[1])]
else:
L = n_cluster
L.sort()
for i in L:
cursor.execute("DROP MODEL IF EXISTS {}.VERTICAPY_KMEANS_TMP_{}".format(schema, relation_alpha))
model = KMeans("{}.VERTICAPY_KMEANS_TMP_{}".format(schema, relation_alpha), cursor, i, init, max_iter, tol)
model.fit(input_relation, X)
all_within_cluster_SS += [float(model.metrics.values["value"][3])]
model.drop()
if (conn):
conn.close()
plt.figure(figsize = (10,8))
plt.rcParams['axes.facecolor'] = '#F4F4F4'
plt.grid()
plt.plot(L, all_within_cluster_SS, marker = "s", color = "#FE5016")
plt.title("Elbow Curve")
plt.xlabel('Number of Clusters')
plt.ylabel('Between-Cluster SS / Total SS')
plt.subplots_adjust(left = 0.2)
plt.show()
values = {"index": L, "Within-Cluster SS": all_within_cluster_SS}
return tablesample(values = values, table_info = False)
model = LogisticRegression(name, cursor, parameters_dict['regularization'], float(parameters_dict['epsilon']), float(parameters_dict['lambda']), int(parameters_dict['max_iterations']), parameters_dict['optimizer'], float(parameters_dict['alpha']))
elif (model_type == "linear_reg"):
from verticapy.learn.linear_model import ElasticNet
model = ElasticNet(name, cursor, parameters_dict['regularization'], float(parameters_dict['epsilon']), float(parameters_dict['lambda']), int(parameters_dict['max_iterations']), parameters_dict['optimizer'], float(parameters_dict['alpha']))
elif (model_type == "naive_bayes"):
from verticapy.learn.naive_bayes import MultinomialNB
model = MultinomialNB(name, cursor, float(parameters_dict['alpha']))
elif (model_type == "svm_regressor"):
from verticapy.learn.svm import LinearSVR
model = LinearSVR(name, cursor, float(parameters_dict['epsilon']), float(parameters_dict['C']), True, float(parameters_dict['intercept_scaling']), parameters_dict['intercept_mode'], float(parameters_dict['error_tolerance']), int(parameters_dict['max_iterations']))
elif (model_type == "svm_classifier"):
from verticapy.learn.svm import LinearSVC
model = LinearSVC(name, cursor, float(parameters_dict['epsilon']), float(parameters_dict['C']), True, float(parameters_dict['intercept_scaling']), parameters_dict['intercept_mode'], [float(item) for item in parameters_dict['class_weights'].split(",")], int(parameters_dict['max_iterations']))
elif (model_type == "kmeans"):
from verticapy.learn.cluster import KMeans
model = KMeans(name, cursor, -1, parameters_dict['init_method'], int(parameters_dict['max_iterations']), float(parameters_dict['epsilon']))
elif (model_type == "pca"):
from verticapy.learn.decomposition import PCA
model = PCA(name, cursor, 0, bool(parameters_dict['scale']))
elif (model_type == "svd"):
from verticapy.learn.decomposition import SVD
model = SVD(name, cursor)
elif (model_type == "one_hot_encoder_fit"):
from verticapy.learn.preprocessing import OneHotEncoder
model = OneHotEncoder(name, cursor)
model.input_relation = info.split(",")[1].replace("'", '').replace('\\', '')
model.test_relation = test_relation if (test_relation) else model.input_relation
if (model_type not in ("kmeans", "pca", "svd", "one_hot_encoder_fit")):
model.X = info.split(",")[3:len(info.split(","))]
model.X = [item.replace("'", '').replace('\\', '') for item in model.X]
model.y = info.split(",")[2].replace("'", '').replace('\\', '')
elif (model_type in ("pca")):