-
Notifications
You must be signed in to change notification settings - Fork 1
/
distribution.py
147 lines (128 loc) · 4.09 KB
/
distribution.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import stats
from mpl_toolkits.mplot3d import Axes3D
##from sklearn.decomposition import PCA
r = "bank.csv"## Name of the file
d = ";"## delimiter
def hisplot1(dataset,name):
"It is used to create a histagram for a name column "
dataset[name].hist(alpha=0.6)
##plt.axhline(0,color='')
plt.show()
def lineplot(dataset,name):
"Used to do autoscaling and plot line for group of data "
dataset[name].plot()
plt.show()
def threed(dataset,name):
"Pass only 3 data columns to draw a 3d plot"
threedee = plt.figure().gca(projection='3d')
threedee.scatter(dataset[name[0]], dataset[name[1]], dataset[name[2]])
threedee.set_xlabel(name[0])
threedee.set_ylabel(name[1])
threedee.set_zlabel(name[2])
plt.show()
def outliers1(dataset,name):
"IT is used to calculate univariate dataset based on Z test in a name column of the dataset"
z= []
for i in dataset[name]:
z .append((i - dataset[name].mean()) / dataset[name].std(ddof=0))
out = []
for i in z:
print i
if(i > 3 or i < (-3)):
out.append(1)
else:
out.append(0)
return out
def pca(dataset):
count = 0
for i in dataset:
count = count+1
pca = PCA(n_componenets=count)
Z = pca.fit_transform(dataset)
def typedis(dataset,name,dis):
"Type any type of ditribution . Dis is used to take in the type of code distribution visit refer http://docs.scipy.org/doc/scipy-0.14.0/reference/stats.html#module-scipy.stats for more reference and throws KS Test Statistic either D,D+,D- test and p value as a result "
if (dataset[name].dtype == 'int64' or dataset[name].dtype == 'float64'):
dataset[name].dropna()
x = np.array(dataset[name])
z, p = stats.kstest(x, dis)
if (p < 0.055):
print 'It is Not as',dis,' distribution'
else:
print 'It is a',dis,'distribution'
return z, p
else:
return None
def distri(dataset,name):
"It is used to tell whether name of dataset is continous or a discrete distribution "
if(dataset[name].dtype == 'object'):
return 'discrete'
else:
len1 = len(dataset[name].unique()) /(dataset[name].count())
if(len1 > 0.05):
return 'continous'
else:
return 'discrete'
def norm(dataset,name):
"Normal test for normal distribution and throws KS Test Statistic either D,D+,D- test and p value as a result "
if(dataset[name].dtype == 'int64' or dataset[name].dtype == 'float64'):
dataset[name].dropna()
x = np.array(dataset[name])
z,p = stats.kstest(x,'norm')
if(p<0.055):
print 'It is Not a normal distribution'
else:
print 'It is a normal distribution'
return z,p
else:
return None
def welisberg(dataset,name):
"Weibull continous distribution and throws KS Test Statistic either D,D+,D- test and p value as a result"
if (dataset[name].dtype == 'int64' or dataset[name].dtype == 'float64'):
dataset[name].dropna()
x = np.array(dataset[name])
z, p = stats.kstest(x, 'dweibull')
if (p < 0.055):
print 'It is Not a Weibull distribution'
else:
print 'It is a weibull distribution'
return z, p
else:
return None
def exponential(dataset,name):
"Exponential continous distribution and throws KS Test Statistic either D,D+,D- test and p value as a result "
if (dataset[name].dtype == 'int64' or dataset[name].dtype == 'float64'):
dataset[name].dropna()
x = np.array(dataset[name])
z, p = stats.kstest(x, 'expon')
if (p < 0.055):
print 'It is Not a Exponential distribution'
else:
print 'It is a Exponential distribution'
return z, p
else:
return None
def logistic(dataset,name):
"Logistic continous distribution and and throws KS Test Statistic either D,D+,D- test and p value as a result "
if (dataset[name].dtype == 'int64' or dataset[name].dtype == 'float64'):
dataset[name].dropna()
x = np.array(dataset[name])
z, p = stats.kstest(x, 'logistic')
if (p < 0.055):
print 'It is Not a Exponential distribution'
else:
print 'It is a Exponential distribution'
return z, p
else:
return None
'''df = pd.read_csv(r,d)
print df
for i in df:
k = distri(df,i)
z,p = norm(df,i)
print i , ' is of ',k
a = outliers1(df,'age')
hisplot1(df,'weight')
##distribution(dar)'''