使用 Python 内置的 defaultdict
,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)
就是这样!
''' | |
Non-parametric computation of entropy and mutual-information | |
Adapted by G Varoquaux for code created by R Brette, itself | |
from several papers (see in the code). | |
This code is maintained at https://github.com/mutualinfo/mutual_info | |
Please download the latest code there, to have improvements and | |
bug fixes. |
def splitData(df, trainPerc=0.6, cvPerc=0.2, testPerc=0.2): | |
""" | |
return: training, cv, test | |
(as pandas dataframes) | |
params: | |
df: pandas dataframe | |
trainPerc: float | percentage of data for trainin set (default=0.6 | |
cvPerc: float | percentage of data for cross validation set (default=0.2) | |
testPerc: float | percentage of data for test set (default=0.2) | |
(trainPerc + cvPerc + testPerc must equal 1.0) |
使用 Python 内置的 defaultdict
,我们可以很容易的定义一个树形数据结构:
def tree(): return defaultdict(tree)
就是这样!