Machine Learning - Classification Plots¶
General¶
In this example, we aim to present several regression plots, including linear regression, tree-based algorithms, and various residual plots. It’s important to note that these plots are purely illustrative and are based on generated data. To make the data more realistically representative, we introduce some noise, resulting in an approximately linear relationship.
Let’s begin by importing verticapy.
import verticapy as vp
Let’s also import numpy to create a random dataset.
import numpy as np
Let’s generate a dataset using the following data.
N = 100 # Number of Records
k = 10 # step
# Normal Distributions
x = np.random.normal(5, 1, round(N / 2))
y = np.random.normal(3, 1, round(N / 2))
z = np.random.normal(3, 1, round(N / 2))
# Creating a vDataFrame with two clusters
data = vp.vDataFrame({
"x": np.concatenate([x, x + k]),
"y": np.concatenate([y, y + k]),
"z": np.concatenate([z, z + k]),
"c": [0 for i in range(round(N / 2))] + [1 for i in range(round(N / 2))]
})
Let’s proceed by creating both a logistic regression model and a linear SVC model using the complete dataset.
# Importing the Vertica ML module
import verticapy.machine_learning.vertica as vml
# Defining the Models
model_logit_1d = vml.LogisticRegression()
model_svc_1d = vml.LinearSVC()
model_svc_2d = vml.LinearSVC()
model_svc_3d = vml.LinearSVC()
# Fitting the models
model_logit_1d.fit(data, "x", "c")
model_svc_1d.fit(data, "x", "c")
model_svc_2d.fit(data, ["x", "y"], "c")
model_svc_3d.fit(data, ["x", "y", "z"], "c")
# Displaying the vDataFrame
display(data)
In the context of data visualization, we have the flexibility to harness multiple plotting libraries to craft a wide range of graphical representations. VerticaPy, as a versatile tool, provides support for several graphic libraries, such as Matplotlib, Highcharts, and Plotly. Each of these libraries offers unique features and capabilities, allowing us to choose the most suitable one for our specific data visualization needs.
Note
To select the desired plotting library, we simply need to use the set_option() function. VerticaPy offers the flexibility to smoothly transition between different plotting libraries. In instances where a particular graphic is not supported by the chosen library or is not supported within the VerticaPy framework, the tool will automatically generate a warning and then switch to an alternative library where the graphic can be created.
Please click on the tabs to view the various graphics generated by the different plotting libraries.
We can switch to using the plotly module.
vp.set_option("plotting_lib", "plotly")
model_svc_1d.plot()
Logit Plot
model_logit_1d.plot()
model_svc_2d.plot()