机器学习随手笔记

Posted 龙鸣丿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器学习随手笔记相关的知识,希望对你有一定的参考价值。

信息价值IV计算案例:

# _*_ coding : utf-8 _*_
# @Time : 2022/5/8 19:57
from numpy import log
from pandas import DataFrame as df
import pandas as pd


def createDateset():
    dataSet=[
        [0,1,1],
        [0,0,0],
        [0,1,0],
        [1,0,1],
        [1,0,0],
        [1,1,1],
        [0,1,1],
        [1,1,1],
        [1,0,1],
        [1,0,1]
    ]
    return dataSet


def calcWOE(dataset,col,targe):
    subdata=df(dataset.groupby(col)[col].count())
    suby=df(dataset.groupby(col)[targe].sum())
    data=df(pd.merge(subdata,suby,how="left",left_index=True,right_index=True))
    b_total=data[targe].sum()
    total=data[col].sum()
    g_total=total-b_total
    data["bad"]=data.apply(lambda x:round(x[targe]/b_total,3),axis=1)
    data["good"]=data.apply(lambda x:round((x[col]-x[targe])/g_total,3),axis=1)
    data["WOE"]=data.apply(lambda x:log(x.bad/x.good),axis=1)
    return data.loc[:,["bad","good","WOE"]]



def calcIV(dataset):
    dataset["IV"] = dataset.apply(lambda x:(x.bad-x.good)*x.WOE,axis=1)
    IV=sum(dataset["IV"])
    return IV


if __name__=='__main__':
    data = createDateset()
    data = df(data,columns=["x1","x2","y"])
    data_WOE=calcWOE(data,"x1","y")
    print(data_WOE)
    data_IV=calcIV(data_WOE)
    print(data_IV)


以上是关于机器学习随手笔记的主要内容,如果未能解决你的问题,请参考以下文章

机器学习-随手笔记二(卷积神经网络TensorFlow和IV值计算)

EJB学习随手笔记

java随手笔记一

EJB学习随手笔记

随手笔记

机器学习(01)——机器学习简介