Skip to content
Permalink
14ad1aa2e8
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
56 lines (45 sloc) 2.18 KB
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import pandas as pd
def plot_data_3d(data):
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# data = data[np.logical_and(data[0] < 0, data[1] > 0)]
color_cond = {'b': np.logical_and(data[0] < 0, np.logical_and(data[1] > 0, data[2] < 0)),
'k': np.logical_and(data[0] < 0, np.logical_and(data[1] > 0, data[2] > 0)),
'g': np.logical_and(data[0] > 0, data[1] < 0),
'r': np.logical_and(data[0] < 0, data[1] < 0),
'c': np.logical_and(data[0] > 0, data[1] > 0),
}
for c in color_cond:
ax.scatter(data[0][color_cond[c]], data[1][color_cond[c]], data[2][color_cond[c]], c=c, s=1)
ax.set_xlabel('X0')
ax.set_ylabel('X1')
ax.set_zlabel('X2')
plt.show()
def write_out_file(name, disc_intervals, disc_points, class_labels):
with open(name, 'w') as out:
out.write('@relation DB\n\n')
counter = [1]
for i in range(len(disc_intervals)):
out.write(
'@attribute dim' + str(i) + ' {' + ','.join([str(j + counter[-1]) for j in disc_intervals[i]]) + '}\n')
counter.append(counter[-1] + len(disc_intervals[i]))
out.write('@attribute class {' + ','.join(['"' + str(i) + '"' for i in class_labels.unique()]) + '}\n\n')
out.write('@data\n')
for i in range(len(disc_points[0])):
for j in range(len(disc_points)):
out.write(str(disc_points[j][i] + counter[j]))
out.write(',')
out.write('"' + str(class_labels[i]) + '"\n')
def write_cut_file(name, disc_intervals):
with open(name, 'w') as out:
for i in range(len(disc_intervals)):
out.write('dimension ' + str(i) + ' (' + str(len(disc_intervals[i])) + ' bins)\n')
for bin in disc_intervals[i]:
out.write(str(disc_intervals[i][bin][1]) + '\n')
out.write('-------------------------------------\n')
if __name__ == '__main__':
data = pd.read_csv("synthetic_cases/synthetic_3d_gauss.csv", delimiter=";", header=None, na_values='?')
plot_data_3d(data)