How to use the verticapy.vDataFrame 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 / learn / datasets.py View on Github external
cursor = read_auto_connect().cursor()
	else:
		check_cursor(cursor)
	try:
		vdf = vDataFrame(name, cursor, schema = schema)
	except:
		cursor.execute("CREATE TABLE {}.{}(\"number\" Integer, \"date\" Date, \"state\" Varchar(32));".format(str_column(schema), str_column(name)))
		try:
			path = os.path.dirname(verticapy.__file__) + "/learn/data/amazon.csv"
			query = "COPY {}.{}(\"number\", \"date\", \"state\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
			if ("vertica_python" in str(type(cursor))):
				with open(path, "r") as fs:
	   				cursor.copy(query.format('STDIN'), fs)
			else:
				cursor.execute(query.format("LOCAL '{}'".format(path)))
			vdf = vDataFrame(name, cursor, schema = schema)
		except:
			cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
			raise
	return (vdf)
#---#
github vertica / Vertica-ML-Python / verticapy / learn / datasets.py View on Github external
cursor = read_auto_connect().cursor()
	else:
		check_cursor(cursor)
	try:
		vdf = vDataFrame(name, cursor, schema = schema)
	except:
		cursor.execute("CREATE TABLE {}.{}(\"Name\" Varchar(32), \"Form\" Varchar(32), \"Price\" Float);".format(str_column(schema), str_column(name)))
		try:
			path = os.path.dirname(verticapy.__file__) + "/learn/data/market.csv"
			query = "COPY {}.{}(\"Form\", \"Name\", \"Price\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
			if ("vertica_python" in str(type(cursor))):
				with open(path, "r") as fs:
	   				cursor.copy(query.format('STDIN'), fs)
			else:
				cursor.execute(query.format("LOCAL '{}'".format(path)))
			vdf = vDataFrame(name, cursor, schema = schema)
		except:
			cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
			raise
	return (vdf)
#---#
github vertica / Vertica-ML-Python / verticapy / learn / cluster.py View on Github external
----------
	voronoi: bool, optional
		If set to true, a voronoi plot will be drawn. It is only available for
		KMeans using 2 predictors.
		"""
		if (voronoi):
			if (len(self.X) == 2):
				from verticapy.learn.plot import voronoi_plot
				query = "SELECT GET_MODEL_ATTRIBUTE(USING PARAMETERS model_name = '{}', attr_name = 'centers')".format(self.name)
				self.cursor.execute(query)
				clusters = self.cursor.fetchall()
				voronoi_plot(clusters = clusters, columns = self.X)
			else:
				raise ValueError("Voronoi Plots are only available in 2D")
		else:
			vdf = vDataFrame(self.input_relation, self.cursor)
			self.predict(vdf, "kmeans_cluster")
			if (len(self.X) <= 3):
				vdf.scatter(columns = self.X, catcol = "kmeans_cluster", max_cardinality = 100, max_nb_points = 10000)
			else:
				raise ValueError("Clustering Plots are only available in 2D or 3D")
	#---#
github vertica / Vertica-ML-Python / verticapy / learn / neighbors.py View on Github external
def to_vdf(self):
		"""
	---------------------------------------------------------------------------
	Creates a vDataFrame of the model.

	Returns
	-------
	vDataFrame
 		model vDataFrame
		"""
		return (vDataFrame(self.name, self.cursor))
github vertica / Vertica-ML-Python / verticapy / utilities.py View on Github external
if not(cursor):
		conn = read_auto_connect()
		cursor = conn.cursor()
	else:
		conn = False
		check_cursor(cursor)
	path = "verticapy_{}.csv".format(gen_name([name]))
	try:
		df.to_csv(path, index = False)
		read_csv(path, cursor, table_name = name, schema = schema, insert = insert)
		os.remove(path)
	except:
		os.remove(path)
		raise
	from verticapy import vDataFrame
	return vDataFrame(input_relation = name, schema = schema, cursor = cursor)
#---#
github vertica / Vertica-ML-Python / verticapy / learn / datasets.py View on Github external
cursor = read_auto_connect().cursor()
	else:
		check_cursor(cursor)
	try:
		vdf = vDataFrame(name, cursor, schema = schema)
	except:
		cursor.execute("CREATE TABLE {}.{}(\"pclass\" Integer, \"survived\" Integer, \"name\" Varchar(164), \"sex\" Varchar(20), \"age\" Numeric(6,3), \"sibsp\" Integer, \"parch\" Integer, \"ticket\" Varchar(36), \"fare\" Numeric(10,5), \"cabin\" Varchar(30), \"embarked\" Varchar(20), \"boat\" Varchar(100), \"body\" Integer, \"home.dest\" Varchar(100));".format(str_column(schema), str_column(name)))
		try:
			path = os.path.dirname(verticapy.__file__) + "/learn/data/titanic.csv"
			query = "COPY {}.{}(\"pclass\", \"survived\", \"name\", \"sex\", \"age\", \"sibsp\", \"parch\", \"ticket\", \"fare\", \"cabin\", \"embarked\", \"boat\", \"body\", \"home.dest\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
			if ("vertica_python" in str(type(cursor))):
				with open(path, "r") as fs:
	   				cursor.copy(query.format('STDIN'), fs)
			else:
				cursor.execute(query.format("LOCAL '{}'".format(path)))
			vdf = vDataFrame(name, cursor, schema = schema)
		except:
			cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
			raise
	return (vdf)
#---#
github vertica / Vertica-ML-Python / verticapy / utilities.py View on Github external
skip   = " SKIP 1" if (header) else ""
		query2 = "COPY {}({}) FROM {} DELIMITER '{}' NULL '{}' ENCLOSED BY '{}' ESCAPE AS '{}'{};".format(input_relation, ", ".join(['"' + column + '"' for column in header_names]), "{}", sep, na_rep, quotechar, escape, skip)
		if (genSQL):
			print(query1 + "\n" + query2)
		else:
			if (query1):
				cursor.execute(query1)
			if ("vertica_python" in str(type(cursor))):
				with open(path, "r") as fs:
					cursor.copy(query2.format('STDIN'), fs)
			else:
				cursor.execute(query2.format("LOCAL '{}'".format(path)))
			if (query1):
				print("The table {} has been successfully created.".format(input_relation))
			from verticapy import vDataFrame
			return vDataFrame(table_name, cursor, schema = schema)
#---#
github vertica / Vertica-ML-Python / verticapy / learn / svm.py View on Github external
Probability cutoff. If this number is not between 0 and 1, a column
		corresponding to the probability to be of class 1 will be generated.

	Returns
	-------
	vDataFrame
 		the vDataFrame of the new relation.
		"""
		check_types([
			("name", name, [str], False),
			("view", view, [bool], False),
			("cutoff", cutoff, [int, float], False)])
		relation = "TABLE" if not(view) else "VIEW"
		sql = "CREATE {} {} AS SELECT {}, {} AS {} FROM {}".format(relation, name, ", ".join(self.X), self.deploySQL(cutoff), self.y, self.test_relation)
		self.cursor.execute(sql)
		return vDataFrame(name, self.cursor)
	#---#
github vertica / Vertica-ML-Python / verticapy / learn / datasets.py View on Github external
load_smart_meters : Ingests the smart meters dataset in the Vertica DB.
	(Time Series / Regression).
load_titanic      : Ingests the titanic dataset in the Vertica DB.
	(Classification).
load_winequality  : Ingests the winequality dataset in the Vertica DB.
	(Regression / Classification).
	"""
	check_types([
			("schema", schema, [str], False),
			("name", name, [str], False)])
	if not(cursor):
		cursor = read_auto_connect().cursor()
	else:
		check_cursor(cursor)
	try:
		vdf = vDataFrame(name, cursor, schema = schema)
	except:
		cursor.execute("CREATE TABLE {}.{}(\"SepalLengthCm\" Numeric(5,2), \"SepalWidthCm\" Numeric(5,2), \"PetalLengthCm\" Numeric(5,2), \"PetalWidthCm\" Numeric(5,2), \"Species\" Varchar(30));".format(str_column(schema), str_column(name)))
		try:
			path = os.path.dirname(verticapy.__file__) + "/learn/data/iris.csv"
			query = "COPY {}.{}(\"Id\" FILLER Integer, \"SepalLengthCm\", \"SepalWidthCm\", \"PetalLengthCm\", \"PetalWidthCm\", \"Species\") FROM {} DELIMITER ',' NULL '' ENCLOSED BY '\"' ESCAPE AS '\\' SKIP 1;".format(str_column(schema), str_column(name), "{}")
			if ("vertica_python" in str(type(cursor))):
				with open(path, "r") as fs:
	   				cursor.copy(query.format('STDIN'), fs)
			else:
				cursor.execute(query.format("LOCAL '{}'".format(path)))
			vdf = vDataFrame(name, cursor, schema = schema)
		except:
			cursor.execute("DROP TABLE {}.{}".format(str_column(schema), str_column(name)))
			raise
	return (vdf)
#---#
github vertica / Vertica-ML-Python / verticapy / utilities.py View on Github external
-------
vDataFrame
	The vDataFrame associated to the input relation.
	"""
	check_types([
		("relation", relation, [str], False), 
		("name", name, [str], False), 
		("dsn", dsn, [str], False), 
		("schema", schema, [str], False),
		("history", history, [list], False),
		("saving", saving, [list], False),
		("query_on", query_on, [bool], False),
		("time_on", time_on, [bool], False)])
	name = gen_name([name])
	from verticapy import vDataFrame
	vdf = vDataFrame("", empty = True)
	vdf._VERTICAPY_VARIABLES_["dsn"] = dsn
	if not(cursor) and not(dsn):
		cursor = read_auto_connect().cursor()
	elif not(cursor):
		from verticapy import vertica_cursor
		cursor = vertica_cursor(dsn)
	else:
		check_cursor(cursor)
	vdf._VERTICAPY_VARIABLES_["input_relation"] = name
	vdf._VERTICAPY_VARIABLES_["main_relation"] = relation
	vdf._VERTICAPY_VARIABLES_["schema"] = schema
	vdf._VERTICAPY_VARIABLES_["schema_writing"] = schema_writing
	vdf._VERTICAPY_VARIABLES_["cursor"] = cursor
	vdf._VERTICAPY_VARIABLES_["query_on"] = query_on
	vdf._VERTICAPY_VARIABLES_["time_on"] = time_on
	vdf._VERTICAPY_VARIABLES_["where"] = []