Skip to content

Commit ddbcc04

Browse files
authored
Fixing the bugs
1 parent 4fba45e commit ddbcc04

File tree

6 files changed

+32
-37
lines changed

6 files changed

+32
-37
lines changed

MANIFEST.in

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
21
include *.md
3-
include *.rst
2+
include docs/index.rst
43
include LICENSE
54
include requirements.txt
65
include spkit/__init__.py
6+
include spkit/data/EEG16SecData.pkl
77

88
recursive-include spkit *.py
99
recursive-include spkit *.txt
@@ -12,7 +12,5 @@ recursive-include examples *.ipynb
1212
recursive-include *.ipynb
1313
recursive-include *.pkl
1414

15-
16-
### Exclude
1715
recursive-exclude * __pycache__
1816
recursive-exclude *.yml

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Signal Processing toolkit
22

3-
43
[![Documentation Status](https://readthedocs.org/projects/spkit/badge/?version=latest)](https://spkit.readthedocs.io/en/latest/?badge=latest)
54
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
65
[![PyPI version fury.io](https://badge.fury.io/py/spkit.svg)](https://pypi.org/project/spkit/)
@@ -20,8 +19,6 @@
2019

2120
![PyPI - Downloads](https://img.shields.io/pypi/dm/spkit?style=social)
2221

23-
24-
2522
### Links: **[Github](https://github.com/Nikeshbajaj/spkit)** | **[PyPi - project](https://pypi.org/project/spkit/)**
2623
### Installation: *[pip install spkit](https://pypi.org/project/spkit/)*
2724

@@ -225,5 +222,5 @@ ______________________________________
225222
* http://nikeshbajaj.in
226223
227224
228-
### PhD Student: Queen Mary University of London & University of Genoa
225+
### PhD Student: Queen Mary University of London
229226
______________________________________

Version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.5
1+
0.0.6

spkit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Signal Processing tool kit"
22

3-
__version__ = '0.0.5'
3+
__version__ = '0.0.6'
44
__author__ = 'Nikesh Bajaj'
55
import sys, os
66

spkit/ml/Trees.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
# Super class for Classification and Regression
2222
class DecisionTree(object):
23-
"""Super class of RegressionTree and ClassificationTree.
23+
'''Super class of RegressionTree and ClassificationTree.
2424
25-
"""
25+
'''
2626
def __init__(self, min_samples_split=2, min_impurity=1e-7, max_depth=float("inf"), thresholdFromMean=False):
2727

2828
'''
@@ -104,8 +104,8 @@ def fit(self, X, y):
104104
print('---------------------------------------')
105105
self.trained = True
106106
def _build_tree(self, X, y, current_depth=0):
107-
""" Recursive method which builds out the decision tree and splits X and respective y
108-
on the feature of X which (based on impurity) best separates the data"""
107+
''' Recursive method which builds out the decision tree and splits X and respective y
108+
on the feature of X which (based on impurity) best separates the data'''
109109

110110
largest_impurity = 0
111111
best_criteria = None # Feature index and threshold
@@ -267,8 +267,8 @@ def _build_tree(self, X, y, current_depth=0):
267267

268268
return node
269269
def predict_value(self, x, tree=None,path=''):
270-
""" Do a recursive search down the tree and make a prediction of the data sample by the
271-
value of the leaf that we end up at """
270+
''' Do a recursive search down the tree and make a prediction of the data sample by the
271+
value of the leaf that we end up at '''
272272

273273
# check if sample has same number of features
274274
assert len(x)==self.nfeatures
@@ -301,7 +301,7 @@ def predict_value(self, x, tree=None,path=''):
301301
# Test subtree
302302
return self.predict_value(x, branch,path)
303303
def predict(self, X,treePath=False):
304-
""" Classify samples one by one and return the set of labels """
304+
'''Classify samples one by one and return the set of labels '''
305305

306306
if treePath:
307307
y_pred = np.array([list(self.predict_value(x)) for x in X])
@@ -338,7 +338,7 @@ def pruneTree(self,DT):
338338
DT['T'] = self.pruneTree(DT['T'])
339339
DT['F'] = self.pruneTree(DT['F'])
340340
return DT
341-
def plotTree(self,scale=True,show=True, showtitle =True, showDirection=True,DiffBranchColor=False,legend=True):
341+
def plotTree(self,scale=True,show=True, showtitle =True, showDirection=False,DiffBranchColor=True,legend=True):
342342
import copy
343343
self.DT = copy.deepcopy(self.tree)
344344
if not(self.DT['leaf']):
@@ -444,9 +444,10 @@ def plotTreePath(self,path,ax=None,fig=None):
444444

445445
class ClassificationTree(DecisionTree):
446446
def entropy(self,y):
447-
""" Calculate the entropy of array y
447+
'''
448+
Calculate the entropy of array y
448449
H(y) = - sum(p(y)*log2(p(y)))
449-
"""
450+
'''
450451
yi = y
451452
if len(y.shape)>1 and y.shape[1]>1:
452453
yi = np.argmax(y,axis=1)
@@ -457,11 +458,10 @@ def entropy(self,y):
457458
return Hy
458459

459460
def _infoGain(self, y, y1, y2):
460-
# Calculate information gain
461-
""" Calculate the information Gain with Entropy
462-
H(y) = - sum(p(y)*log2(p(y)))
463-
I_gain = H(y) - P(y1) * H(y1) - (1 - P(y1)) * H(y2)
464-
"""
461+
'''
462+
Calculate the information Gain with Entropy
463+
I_gain = H(y) - P(y1) * H(y1) - (1 - P(y1)) * H(y2)
464+
'''
465465
p = len(y1) / len(y)
466466
info_gain = self.entropy(y) - p * self.entropy(y1) - (1 - p) * self.entropy(y2)
467467
return info_gain
@@ -476,13 +476,13 @@ def fit(self, X, y,verbose=0,feature_names=None,randomBranch=False):
476476
'''
477477
Parameters:
478478
-----------
479-
X:: ndarray (number of sample, number of features)
480-
y:: list of 1D array
481-
verbose::0 - no progress or tree (silent)
482-
::1 - show progress in short
483-
::2 - show progress with details with branches
484-
::3 - show progress with branches True/False
485-
::4 - show progress in short with plot tree
479+
X :: ndarray (number of sample, number of features)
480+
y :: list of 1D array
481+
verbose ::0 - no progress or tree (silent)
482+
::1 - show progress in short
483+
::2 - show progress with details with branches
484+
::3 - show progress with branches True/False
485+
::4 - show progress in short with plot tree
486486
487487
feature_names:: (optinal) list, Provide for better look at tree while plotting or shwoing the progress,
488488
default to None, if not provided, features are named as f1,...fn
@@ -496,10 +496,10 @@ def fit(self, X, y,verbose=0,feature_names=None,randomBranch=False):
496496

497497
class RegressionTree(DecisionTree):
498498
def _varReduction(self, y, y1, y2):
499-
'''
500-
Calculate the variance reduction
501-
VarRed = Var(y) - P(y1) * Var(y1) - P(p2) * Var(y2)
502-
'''
499+
'''
500+
Calculate the variance reduction
501+
VarRed = Var(y) - P(y1) * Var(y1) - P(p2) * Var(y2)
502+
'''
503503
assert len(y.shape)==1 or y.shape[1]==1
504504

505505
p1 = len(y1) / len(y)

spkit/ml/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Signal Processing tool kit"
22

3-
__version__ = '0.0.5'
3+
__version__ = '0.0.6'
44
__author__ = 'Nikesh Bajaj'
55
import sys, os
66

0 commit comments

Comments
 (0)