1

This figure is to illustrate a hyperplane

enter image description here

Is there a toy dataset could be used to draw this kind of figure with Python?

in other words, is there a dataset which is not linearly separable in 2d and linearly separable in 3D?

2

You could generate such a dataset using Python. A simple approach would be to generate a set of (x, y) coordinates, partition the set, then assign a distinct value for the z coordinate for each partition. An example with 100 points divided into 5 linearly separable partitions:

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt
import numpy as np

N = 100 
K = 5                               # Partitions to split the N observations.
x = np.random.normal(0, 1, N)
y = np.random.normal(0, 1, N)
z = np.repeat(np.arange(K), N / K)  # One can simply shift the z-axis for 
                                    # partitions of the (x, y) coordinates
                                    # Given this simple transformation, each 
                                    # partition is linearly separable.

# 2d plot
fig = plt.gcf()
plt.scatter(x, y, c=z)
plt.show()
fig.savefig('demo2d.png')

# 3d plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c=z)
plt.show()
fig.savefig('demo3d.png')


# save toy dataset
D = np.vstack((x,y,z)).T 
np.savetxt('demo.csv', D, delimiter=',')

Plots of the data in 2 and 3 dimensions: enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.