首页 > 其他分享 >Split to Achieve Gain

Split to Achieve Gain

时间:2023-10-30 21:12:32浏览次数:47  
标签:gini Gain sum 0.5 len split cases Achieve Split

Machine Learning - Split to Achieve Gain

Calculate Information Gain.

Task
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).

Input Format
Three lines of 1's and 0's separated by spaces

Output Format
Float (rounded to 5 decimal places)

Sample Input
1 0 1 0 1 0
1 1 1
0 0 0

Sample Output
0.5

 

Explanation
The initial set has 3 positive cases and 3 negative cases. Thus the gini impurity is 2*0.5*0.5=0.5.
The left set has 3 positive cases and 0 negative cases. Thus the gini impurity is 2*1*0=0.
The right set has 0 positive cases and 3 negative cases. Thus the gini impurity is 2*0*1=0.
The information gain is 0.5-0-0=0.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()]
gini=2*(sum(S)/len(S))*(1-sum(S)/len(S))
ha=2*(sum(A)/len(A))*(1-sum(A)/len(A)) hb=2*(sum(B)/len(B))*(1-sum(B)/len(B)) ig=gini-ha*(len(A)/len(S))-hb*(len(B)/len(S))
print(round(ig,5))

 

标签:gini,Gain,sum,0.5,len,split,cases,Achieve,Split
From: https://www.cnblogs.com/tinghae/p/17798845.html

相关文章

  • 题解 ABC326G【Unlock Achievement】
    题解ABC326G【UnlockAchievement】problem有\(n\)项属性,第\(j\)个属性的等级\(l_j\)初始为\(1\),每提升一级花费\(c_j\)的钱。又有\(m\)项成就,第\(i\)项成就要求对于所有\(1\leqj\leqn\),都要\(l_j\geqL_{i,j}\),如果满足所有要求,获得\(a_i\)的钱。求你最多......
  • Angular 中的 code splitting 和 lazy loading 技术
    Angular中的LazyLoading技术详解在Angular应用开发领域,实现LazyLoading是一个重要而复杂的任务,特别是在构建时需要动态加载代码的情况下。本文将详细介绍AngularLazyLoading的更多细节,包括核心概念、实际应用和解决方案。LazyLoading是一项在应用构建时进行的技术,通常是基于......
  • CodeForces 1887D Split
    洛谷传送门CF传送门\(a_l,a_{l+1},\ldotsa_r\)是好的当且仅当\(\existsk\in[l,r-1],\max\limits_{i=l}^ka_i<\min\limits_{i=k+1}^ra_i\),称此时的\(k\)为分割点。对\(r\)扫描线,单调栈维护极长的一些区间\([L_i,R_i]\)使得\(\min\limits_{j=......
  • Qt之分裂器(QSplitter)
    一、QSplitter概述QSplitter是Qt中的一个布局管理器,允许用户在应用程序窗口中创建可拖动的分隔器,以便调整多个子窗口或控件的大小。它是一种非常有用的布局管理器,用于创建可分隔的多个部分,通常用于分割、重新排列和管理用户界面中的多个区域。以下是有关QSplitter的详细介......
  • Codeforces Round 895 (Div. 3) B. The Corridor or There and Back Again
    你在一个向右延申的无限坐标轴上,且你初始在坐标\(1\)。有\(n\)个陷阱在坐标轴上,第\(i\)个陷阱坐标为\(d_i\),且会在你踩上这个陷阱的\(s_i\)秒过后发动。这时候你不能进入坐标\(d_i\)或者走出坐标\(d_i\)。你需要确定最远的\(k\),保证你能够走到坐标\(k\),并且顺......
  • CF1872B The Corridor or There and Back Again
    CF1872BTheCorridororThereandBackAgain观察第二组样例的解释,注意这句话:“第二个陷阱限制了你”。这启发我们计算经过每个陷阱之后最多还能向前走到哪里,然后取\(\min\)得到答案。现在的问题是如何求出每个陷阱限制的最远可到达点。由于要求折返,因此对于第\(i\)个......
  • CF1416E Split
    暴力dp是很拉跨的,我们会设\(dp_{i,j}\)表示前\(i\)个\(a_i\)分裂后,最后一个\(b\)为\(j\)时的最小答案,爆炸。但这里面有很多性质啊,直观地我们可以感受到,若已经确定了决策\(dp_{i-1,k}\),那么无论如何选择\(a_i\)的分裂方式,对答案带来的贡献都会在\(0\sim2\)之间,......
  • Unity完美像素Sprite:怎么让图片变得清晰(转载) Unity Pixel Perfect Sprite: How To Ach
    https://gamedevelopertips.com/unity-pixel-perfect-sprite/SoIwasmakingalittleprototypeformynewgamewhenIjustcameacrossalittleproblem.ThespritethatIwasloadingintoUnitywasjustlookingtoopixelatedandnotsharpatall.SoIspen......
  • Codeforces Round 706 (Div. 2) A. Split it!
    给一个长度为\(n\)的字符串\(s\)。给定一个正整数\(k\)。询问\(s\)能否等于\(a_1+a_2+\cdots+a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\cdots+R(a_{1})\)。其中\(a_i\)代表一个非空字符串,\(R(a_i)\)代表\(a_i\)的\(reverse\)。由于\(a_{k+1}\)......
  • System.NotSupportedException:“无法显式设置 SplitterPanel 的高度。改在 SplitCont
    System.NotSupportedException:“无法显式设置SplitterPanel的高度。改在SplitContainer上设置SplitterDistance。”这个错误信息是在使用SplitContainer控件时出现的。它表明您尝试显式设置SplitterPanel的高度,但这是不支持的操作,应该在SplitContainer上设置Splitte......