Issue
Here's a sample from my dataset
-0.76,-0.66,-1
0.07,0.59,1
0.73,0.6,-1
0.58,-0.46,-1
-0.71,0.9,-1
-0.82,-0.13,-1
0.2,0.43,1
-0.72,-0.93,-1
0.8,-0.79,-1
-0.35,-0.52,-1
0.53,0.72,1
-0.7,0.96,-1
3 columns in each
I need to visualize this as such that by placing a marker on a 2D plot for each pair of feature values i.e. for each row in the data. On the plot the x-axis should be the value of the first feature, the y-axis the value of the second feature and the marker should be, for example, a + marker when the target value is +1 and a o when the target is −1
Solution
Based on what you told, I've had some ideas for you to plot the desired output from your dataframe. So I tried to reproduce your problem with this code:
import pandas as pd
# I made this solution using matplotlib to make the scatterplot
from matplotlib import pyplot as plt
data = [
(-0.76, -0.66, -1),
( 0.07, 0.59, 1),
( 0.73, 0.60, -1),
( 0.58, -0.46, -1),
(-0.71, 0.90, -1),
(-0.82, -0.13, -1),
( 0.20, 0.43, 1),
(-0.72, -0.93, -1),
( 0.80, -0.79, -1),
(-0.35, -0.52, -1),
( 0.53, 0.72, 1),
(-0.70, 0.96, -1),
]
df = pd.DataFrame(data, columns = ["X", "Y", "Sign"])
x = df['X'] # Values for x-axis
y = df['Y'] # Values for y-axis
signs = df['Sign'] # Values for changing the marker in the plots
for i in range(len(x)):
plt.scatter(
x[i], y[i], # X, Y coordinates
s = 100, # Size of the markers
linewidth = 3, # Line width
marker = "+" if signs[i] > 0 else "_", # Control wether the marker is a '+' or a '-'
color = "green" if signs[i] > 0 else "red" # Control the color based on minus or plus sign
)
The output produced is:
Answered By - NickS1
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.