In [1]:
import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
from IPython.display import display, HTML
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

In [2]:
data =pd.read_csv('Linear.csv',sep=',')

In [3]:
plt.plot(data[data.Class==1].X, data[data.Class==1].Y, 'ro')
plt.plot(data[data.Class==0].X, data[data.Class==0].Y, 'bo')
(mX,mY) = (np.mean(data.X),np.mean(data.Y))
plt.plot(mX,mY,'go')
plt.axis([min(data.Y)-1, max(data.X)+1, min(data.Y)-1, max(data.Y)+1])
plt.show()

The three levels is :

  • X
  • Y
  • Z :distance from the mean point

In [4]:
lst =[]
for i in range(len(data.X)):
    lst.append(np.linalg.norm(np.array((data.X[i],data.Y[i]))-np.array((mX,mY))))

In [5]:
data['Z'] = pd.Series(np.array(lst), index=data.index)

In [6]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(data[data.Class==1].X, data[data.Class==1].X, data[data.Class==1].Z, c='r', marker='o')
ax.scatter(data[data.Class==0].X, data[data.Class==0].X, data[data.Class==0].Z, c='b', marker='o')

xx, yy = np.meshgrid(range(6), range(6))
z1 = np.reshape(np.repeat(1.65,36),(6,6))

ax.plot_surface(xx,yy,z1, color='blue',                rstride=3, 
                cstride=3, 
                alpha=0.3,            # transparency of the surface 
                cmap=cm.coolwarm)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()


/home/aqeel/.local/lib/python2.7/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):