-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
60 lines (43 loc) · 1.51 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
Azad-Academy
Author: J. Rafid Siddiqui
jrs@azaditech.com
https://www.azaditech.com
'''
import sys
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np
import math
from itertools import permutations
import matplotlib
import sklearn
from sklearn.datasets import *
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import MinMaxScaler
from IPython.display import display
def plot_data(X,Y,canvas=None,xtitle=None,ytitle=None,colors=None,plt_title=None,color_map=plt.cm.RdBu):
if(colors is None):
colors = np.random.rand(max(Y)+1,3)
if(canvas is None):
fig, ax = plt.subplots(figsize=(11,8))
else:
ax = canvas
if(plt_title is not None):
ax.set_title(plt_title)
if(X.shape[1]>2):
ax.scatter3D(X[:,0],X[:,1],X[:,2],color=np.array(colors)[Y],alpha=0.6) #plotting the 3D points
ax.grid(False)
else:
ax.scatter(X[:,0],X[:,1],color=np.array(colors)[Y],alpha=0.6,cmap=color_map) #plotting the 2D points
if(xtitle is not None):
ax.set_xlabel(xtitle,fontweight='bold',fontsize=16)
if(xtitle is not None):
ax.set_ylabel(ytitle,fontweight='bold',fontsize=16)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
def sigmoid(z):
return 1/(1 + np.exp(-z))
def sigmoid_grad(z):
return sigmoid(z)*(1-sigmoid(z))