`
junfeng_feng
  • 浏览: 18266 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Information Gain 计算 python实现

 
阅读更多



from math import log

def I(*args):
    total = sum(args) + 0.0
    result = 0.0
    for i in args:
        if i == 0:
            result += 0
        else:
            result += i / total * log( i / total, 2)
    return -result

#num表示分类的个数
def E(num, *args):
    if len(args) % num != 0:
        print "Error len(args)"
    result = 0.0
    total = sum(args)
    for x in xrange(len(args) / num):
        k = x * num
        total_up = 0.0 + sum(args[k:k + num])
        result += total_up / total * I(*args[k:k + num])
    return result

def Gain(i, e):
    return i - e

#取个别名
i = I
e = E
g = Gain

if __name__ == "__main__":
    #for example
    print i(9, 5)
    print e(2, 2, 3, 4, 0, 3, 2)




分享到:
评论

相关推荐

    Spark for Python Developers

    Spark for Python Developers aims to combine the elegance and fl...Third, gain insights from the collected data. Fourth, stream live data and process it in real time. Finally, visualize the information.

    Python: Penetration Testing for Developers

    Exploit the Remote File Inclusion to gain administrative access to systems with Python and other scripting languages Crack an organization's Internet perimeter and chain exploits to gain deeper access...

    Building Chatbots with Python(2019)

    This book begins with an introduction to chatbots where you will gain vital information on their architecture. You will then dive straight into natural language processing with the natural language ...

    Natural Language Processing with Python

    this book will help you gain practical skills in Natural Language Processing using the Python programming language and the Natural Language Toolkit (NLTK) open source library., If you're interested in...

    Learning Data Mining with Python - Second Edition

    You will gain hands on experience with complex data types including text, images, and graphs. You will also discover object detection using Deep Neural Networks, which is one of the big, difficult ...

    Mastering Natural Language Processing with Python [2016]

    Gain insights into the current and budding research topics of NLP This is a comprehensive step-by-step guide to help students and researchers create their own projects based on real-life applications ...

    Building Probabilistic Graphical Models with Python

    Gain an insight on algorithms that run inference Explore parameter estimation in Bayes nets with PyMC sampling Understand the complexity of running inference algorithms in Bayes networks Discover ...

    Learning.Data.Mining.with.Python.1784396052

    The next step in the information age is to gain insights from the deluge of data coming our way. Data mining provides a way of finding this insight, and Python is one of the most popular languages for...

    Beginning Python: From Novice to Professional 第二版

    Gain a fundamental understanding of Python’s syntax and features with the second edition of Beginning Python, an up–to–date introduction and practical reference. Covering a wide array of Python–...

    Python.Hacking.Essentials.1511797568

    Rather than simply using words for descriptions, graphics are very effective in transferring information. An abstract concept can materialize through the use of graphics in order to improve the ...

    Building Chatbots with Python: Using Natural Language Processing and Machine

    This book begins with an introduction to chatbots where you will gain vital information on their architecture. You will then dive straight into natural language processing with the natural language ...

    information_gain

    information_gain

    KrantikariQA:基于InformationGain的知识图系统问答

    CUDA_VISIBLE_DEVICES = 3 python corechain.py -model slotptr -device cuda -dataset lcquad -pointwise False 下载手套 wget 将其保存到资源文件夹中将其解压缩 使用Anaconda安装(仍然需要对其进行测试) ...

    Python3 ID3决策树判断申请贷款是否成功的实现代码

    # 计算数据集的信息熵(Information Gain)增益函数(机器学习实战中信息熵叫香农熵) def calcInfoEnt(dataSet):#本题中Label即好or坏瓜 #dataSet每一列是一个属性(列末是Label) numEntries = len(dataSet) #每一行是...

    Designing.Machine.Learning.Systems.with.Python.178588

    To get the most out of this book, you will need to know some linear algebra and some Python, and have a basic knowledge of machine learning concepts. What You Will Learn Gain an understanding of the...

    Flask.By.Example.1785286935

    Build three web applications from the ground up using the powerful Python micro framework, Flask. Dynamically display data to your viewers, based on their requests Store user and static data in SQL ...

Global site tag (gtag.js) - Google Analytics