machine learning using python , information gain value | Sololearn: Learn to code for FREE!

0

# machine learning using python , information gain value

how to find the answer for this question Given a dataset and a split of the dataset, calculate the information gain using the gini impurity. The first line of the input is a list of the target values in the initial dataset. The second line is the target values of the left split and the third line is the target values of the right split. Round your result to 5 decimal places. You can use round(x, 5). S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()]

3/29/2021 5:30:46 AM

Athira Mathew

+6

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))

+1

S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))

0

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))

0

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))

0

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5)) It works!

0

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))

0

import math S = [int(x) for x in input().split()] A = [int(x) for x in input().split()] B = [int(x) for x in input().split()] def p(a): x=sum(a)/len(a) return x def log2(a): a=math.log2(a) return a def gini(a): h=2*p(a)*(1-p(a)) return h infogain=gini(S)-(len(A)/len(S))*gini(A)-(len(B)/len(S))*gini(B) print(round(infogain,5))