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()]
8 Réponses
+ 7
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))
+ 4
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))
- 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()]
print(((2 * (sum(S) / len(S)) * (1 - (sum(S) / len(S)))) - (len(A) / len(S)) * (
2 * (sum(A) / len(A)) * (1 - (sum(A) / len(A)))) - (len(B) / len(S)) * (
2 * (sum(B) / len(B)) * (1 - (sum(B) / len(B)))).__round__(5)))