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()]

29th Mar 2021, 5:30 AM
Athira Mathew
Athira Mathew - avatar
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))
31st Mar 2021, 12:25 PM
Xuyen Tran
+ 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))
26th Jun 2021, 1:19 PM
Shanmuga Priya
Shanmuga Priya - avatar
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))
8th Jun 2021, 6:01 AM
Pusthakala Divya
Pusthakala Divya - avatar
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))
2nd Dec 2021, 8:19 AM
Nichervan Essa Mahammad
Nichervan Essa Mahammad - avatar
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!
15th Dec 2021, 4:54 PM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar
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))
17th Dec 2021, 10:05 AM
Ismoilov Abdug'ofur
Ismoilov Abdug'ofur - avatar
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))
26th Dec 2021, 11:08 AM
Nabila Muftia Ma'ruf Kartono
Nabila Muftia Ma'ruf Kartono - avatar
- 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)))
12th Nov 2022, 11:07 PM
Виталий Меншиков
Виталий Меншиков - avatar