In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
For more information on big data's analysis and modeling, please follow the official account "bigdatamodeling".
Python realizes KS curve. For related usage, please refer to the previous blog-R language to realize KS curve.
The code is as follows:
# PlotKS # # def PlotKS (preds, labels, n, asc): # preds is score: asc=1 # preds is prob: asc=0 pred = preds # predicted value bad = labels # take 1 as bad, 0 as good ksds = DataFrame ({'bad': bad) 'pred': pred}) ksds [' good'] = 1-ksds.bad if asc = = 1: ksds1 = ksds.sort_values (by= ['pred',' bad'], ascending= [True, True]) elif asc = = 0: ksds1 = ksds.sort_values (by= ['pred',' bad'], ascending= [False] True]) ksds1.index = range (len (ksds1.pred)) ksds1 ['cumsum_good1'] = 1.0*ksds1.good.cumsum () / sum (ksds1.good) ksds1 [' cumsum_bad1'] = 1.0*ksds1.bad.cumsum () / sum (ksds1.bad) if asc = = 1: ksds2 = ksds.sort_values (by= ['pred',' bad'], ascending= [True] False]) elif asc = = 0: ksds2 = ksds.sort_values (by= ['pred',' bad'], ascending= [False] False]) ksds2.index = range (len (ksds2.pred)) ksds2 ['cumsum_good2'] = 1.0*ksds2.good.cumsum () / sum (ksds2.good) ksds2 [' cumsum_bad2'] = 1.0*ksds2.bad.cumsum () / sum (ksds2.bad) # ksds1 ksds2-> average ksds = ksds1 [['cumsum_good1'] 'cumsum_bad1']] ksds [' cumsum_good2'] = ksds2 ['cumsum_good2'] ksds [' cumsum_bad2'] = ksds2 ['cumsum_bad2'] ksds [' cumsum_good'] = (ksds ['cumsum_good1'] + ksds [' cumsum_good2']) / 2 ksds ['cumsum_bad'] = (ksds [' cumsum_bad1'] + ksds ['cumsum_bad2']) / 2 # ks ksds [' ks'] = ksds ['cumsum_bad']-ksds [' cumsum_good'] ksds ['tile0'] = range (1 Len (ksds.ks) + 1) ksds ['tile'] = 1.0*ksds [' tile0'] / len (ksds ['tile0']) qe = list (np.arange (0,1) 1.0) qe.append (1) qe = qe [1:] ks_index = Series (ksds.index) ks_index = ks_index.quantile (Q = qe) ks_index = np.ceil (ks_index) .astype (int) ks_index = list (ks_index) ksds = ksds. Locks _ index] ksds = ksds [['tile',' cumsum_good', 'cumsum_bad'] 'ks']] ksds0 = np.array ([[0,0,0,0]]) ksds = np.concatenate ([ksds0, ksds], axis=0) ksds = DataFrame (ksds, columns= [' tile', 'cumsum_good',' cumsum_bad', 'ks']) ks_value = ksds.ks.max () ks_pop = ksds.tile [ksds.ks.idxmax ()] print (' ks_value is'+ str (np.round (ks_value)) 4) +'at pop ='+ str (np.round (ks_pop, 4)) # chart plt.plot (ksds.tile, ksds.cumsum_good, label='cum_good', color='blue', linestyle='-', linewidth=2) plt.plot (ksds.tile, ksds.cumsum_bad, label='cum_bad', color='red', linestyle='-', linewidth=2) plt.plot (ksds.tile Ksds.ks, label='ks', color='green', linestyle='-', linewidth=2) plt.axvline (ks_pop, color='gray', linestyle='--') plt.axhline (ks_value, color='green', linestyle='--') plt.axhline (ksds.loc [ksds.ks.idxmax (), 'cumsum_good'], color='blue', linestyle='--') plt.axhline (ksds.loc [ksds.ks.idxmax () 'cumsum_bad'], color='red', linestyle='--') plt.title (' KS=%s'% np.round (ks_value, 4) +'at Pop=%s'% np.round (ks_pop, 4), fontsize=15) return ksds### over
The effect of drawing is as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.