How to use the verticapy.utilities.tablesample function in verticapy

To help you get started, we’ve selected a few verticapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vertica / Vertica-ML-Python / verticapy / utilities.py View on Github external
model.X = info.split(",")[2:len(info.split(","))]
		model.X = [item.replace("'", '').replace('\\', '') for item in model.X]
		model.param = to_tablesample(query = "SELECT category_name, category_level::varchar, category_level_index FROM (SELECT GET_MODEL_ATTRIBUTE(USING PARAMETERS model_name = '{}', attr_name = 'integer_categories')) x UNION ALL SELECT GET_MODEL_ATTRIBUTE(USING PARAMETERS model_name = '{}', attr_name = 'varchar_categories')".format(name.replace("'", "''"), name.replace("'", "''")), cursor = cursor)
		model.param.table_info = False
	else:
		model.X = info.split(",")[2:len(info.split(",")) - 1]
		model.X = [item.replace("'", '').replace('\\', '') for item in model.X]
		model.n_cluster = int(info.split(",")[-1])
		model.cluster_centers = to_tablesample(query = "SELECT GET_MODEL_ATTRIBUTE(USING PARAMETERS model_name = '{}', attr_name = 'centers')".format(name.replace("'", "''")), cursor = cursor)
		model.cluster_centers.table_info = False
		query = "SELECT GET_MODEL_ATTRIBUTE(USING PARAMETERS model_name = '{}', attr_name = 'metrics')".format(name.replace("'", "''"))
		cursor.execute(query)
		result = cursor.fetchone()[0]
		values = {"index": ["Between-Cluster Sum of Squares", "Total Sum of Squares", "Total Within-Cluster Sum of Squares", "Between-Cluster SS / Total SS", "converged"]}
		values["value"] = [float(result.split("Between-Cluster Sum of Squares: ")[1].split("\n")[0]), float(result.split("Total Sum of Squares: ")[1].split("\n")[0]), float(result.split("Total Within-Cluster Sum of Squares: ")[1].split("\n")[0]), float(result.split("Between-Cluster Sum of Squares: ")[1].split("\n")[0]) / float(result.split("Total Sum of Squares: ")[1].split("\n")[0]), result.split("Converged: ")[1].split("\n")[0] == "True"] 
		model.metrics = tablesample(values, table_info = False)
	if (model.type == "classifier"):
		cursor.execute("SELECT DISTINCT {} FROM {} WHERE {} IS NOT NULL ORDER BY 1".format(model.y, model.input_relation, model.y))
		classes = cursor.fetchall()
		model.classes = [item[0] for item in classes]
	return (model)
#---#
github vertica / Vertica-ML-Python / verticapy / utilities.py View on Github external
elapsed_time = time.time() - start_time
	if (time_on):
		print_time(elapsed_time)
	result = cursor.fetchall()
	columns = [column[0] for column in cursor.description]
	data_columns = [[item] for item in columns]
	data = [item for item in result]
	for row in data:
		for idx, val in enumerate(row):
			data_columns[idx] += [val]
	values = {}
	for column in data_columns:
		values[column[0]] = column[1:len(column)]
	if (conn):
		conn.close()
	return tablesample(values = values, name = name)
#---#