Learn R Programming

biogram (version 1.0)

calc_ig_single: Calculate IG for single feature

Description

Computes information gain of feature and target vector.

Usage

calc_ig_single(feature, target_b, len_target, pos_target, ES)

Arguments

feature
feature vector.
target_b
target in bits (as per as.bit).
len_target
length of target vector.
pos_target
number of positive cases in target vector.
ES
numeric value of target entropy.

Value

  • a single numeric value - information gain in nats.

Details

Input looks strange, but the function was designed to be as fast as possible subroutine of calc_ig and generally should not be directly called by user.

Examples

Run this code
tar <- sample(0L:1, 100, replace = TRUE)
feat <- sample(0L:1, 100, replace = TRUE)
prop <- c(100 - sum(tar), sum(tar))/100
entr <- - sum(prop*log(prop))
library(bit) #used to code vector as bit
calc_ig_single(feat, as.bit(tar), 100, sum(tar), entr)

Run the code above in your browser using DataLab