Download as pdf
Download as pdf
You are on page 1of 2
LUNTAR CAPTALSON BHO. > Machine. Lanning Rozsn > Notebooks © Awontepces Bawaitiatoninns | Binvaditontotages% | [ Apphinginearagre:X @ Home = Dy Nedetcattog mare (> sing 2 1 Notebooks & tomated ot Desget >= Prompttow mee © baw A ee components pines B. owonmens © Moats eooea oo 2 Eatin vScode | @ compute: [ist Applications of Classification Inths ib you wil prom swo- ls asiiation xing lagi regression A csr is mactne ering moc thst separates th abel io {ategaes or elas In lier wrt cstiion models ate superied mache lung Model whieh pect acaagorcal abe ‘The Geman cred ban customer data is used to determine ia pata persons good orb ce isk Thus ce sk of he customer ithe leer ou ru pret Inia. the cot the bank of ung alan bad re tomer tne tht of denying loan 0» good faster Ths fw beer important when essing he prior fhe mde Logistic reession a iear ode bu with 2 none response. The respersesbnay, (0,1), o postive and negative The response the nhs ab you wen the flowing: + How to prepare tao clasiicaon model sings om + Canaructng ation model wing sea, 1 Evdunng te perormare fhe dasiieaton mode 1 Ging ecniues sun a5 eveghting the labels an changing he dein esol to change the vade-off betven fe poste and ae rege ror tes ss anpore Ruy o2"0p" 5 ore nunpy ean 38 or 7 fon sklearn ingore preprocessing eee eet 9 fron sklearn tort Tinear model 22 snutplothibsntine Legatireresion widely eda clan adel Logie egesion near model witha bina esporse, (False, True) of (8, 4} You can think ofthis pone at having a inom strbton, For ner regreson te exponee jut wel hn. Lag regression ira near egreston model ha naninear ouput. The eons lhe lear model snore or squehe'to ves costo Dan ng stgmoialunetion i trow 35 he lege unetien The eu of ths wastonston sa respons hich shel kcood oe the swoclres ‘The sigmoidal ar gic neon can be enprsied los: terprcnst§Esceutethcondinthcelliclutocorputeandplotanczempleofthelogsticfunction. seg = nparanee(Ps 76 8.2) eghetbe = (nathoeno(9/(8 + methep(0)) for v nate Iogiete, color = "rey ly [.5,0-5], color = "blue") Precptitoy6], {0,3}, eouer = “olve') Pls ttia( Lopteste fnseson far ta-clete elassstscatsen) Preayloel( Top 2ikeshooe") pusccaoei( value of outaur tron Linear repression) Tert(@, @, "Velue of output fron naar regrzsion’) Logistic function for two-class classification 10 00 Valu of output rm near regression Ath Now cepesing onthe value of we want to cety he eutput rm ogi regrerson model a ether or 2. Subang he near mode ino te ogi uncon rsa he fli epreston PO - aaa rhs wy we tani he continous output a then model deine on —n0 otercing oanstenceser() * 5 fertres reshepe(-1)) 5 Sanine atenga erane/onane cat fastures-reshapaiy3))-t08ery() 1 exvaporicalcolums + (Jedis history’, ‘purpose, “gander status", 2 eine inarentdencey “property Hk Faxtunas = ncode ctring(credie{eneckdng sccount_satue']) 25 For col iy eategorieen slum Ee eee rea 27 Features rpceonestngte({festurs, tare], axis © 1) 29 prine(Featunes. shape) Baeste are ‘ase, 21) [2 Leeereceeceeecerececere. ene) 9.91. 8.1 Next the amen esures stb concatenated tthe numpy aa by executing the coe inthe al below woOh~ @ Ee ee ae eee ee payment pert incone', "e_yre°]})], de * 2) freneece a.oabeeeee,e0esvep feeeeoe Z.leseee 4,a000r88 7296-81) 8.686000 5.6064060 ©.0066r68 420001 58516009 2.0006160 2 206461)] ith the dey sabes the rg categorie fetes are now 31 dummy varies With hed namerieaties there ae total oF 5 Now anes Question 2 on he couse sage Yeu must split he aes in ning an tes ats et Thi step cic. fmchine ring medel te estes onthe tring dt, the ess ‘The codein the cel below psfoms the flowing rocesing 1. An nsx vector i Btrol ample ung he s_test sp uncon from tha nadel_selecton packge of clam, 2 The fet column oth resting nex ary cons the nies of he ples othe tring ces. 2 The second clan ofthe resuing index aay contin thence ofthe als for the testcase, mraceed(ons)| {hats ange(Peetures.shape[eD) not + actrain_testsplie(anot, test size © 300) Ketoein © fentrestindey 7 YFaeain © noceavel debe ingn(@))) SCtest = reetresl antes} Seat = op tavei{Jabele{ inal ‘Tres ne more sep in pepsin ths dat, Numeric estres mute escald othe ve sim ange of values Rescang prevents feature fom ving an unde influence on model ang spy Sea then have age ange of ane arabes ‘The code in the cll blow ues the tral function rm the ct aa preprocessing pctage te scr sel the ume etre Note that te scar ony en he aig data The aed cles these apps to the es ata Tet data shoud anys Be scaled using the parameters fom he aig dt. 2 sealer = prepeocensing.Seansandscaler() (trata: 28:]) 2 eeninfssoer} = sender -ecanetonb terials 3) 3 cpese[: See] © sea eontx selss2eeD) & Seaintian ervey Lt 1 o1a8e656008, Te four muti festures ae nw see Construct the logistic regression model Now its tne t compte the logit egreon mel The coe nthe cellisow deste flowing 1. Dene lag regression moc abet feature andthe label othe ting data at. : ee een 2 lopisticnnes.Fi¢( train, y- train) {Jsescanda/nva/suayter_ an 88/nythns.0/2tte-pakages/skianr/linasn pesel/_logsetc.oya50: Convergeesiarnsn: tafge faled to converge (statues) nerease the miner of tarations (ni_Ster) ot seale the deta es sho Sn betes //schtst-Leara ra/stable/mndules/ereorecessiog. ota lense also refer to the docinentation for alternative selver options betes/Vasikit-Leer.ore/stabhe/mtules/Lineer mde) henltlesstic:ceeression nize reset Lestictepestion Logsseicagresesen() The model as been ompute Note iat heconfgueton fhe ode! bctha een pine nth ces, ely dl stings ae hon, Now pint ana examine the mael coscens by eesti the code inthe cel blo 2 prlnn(iontstte oa. tnterce Peas reece cect [-avetzeista) Fi fant tt model cof nk they ould for on reprexson model Thi empeced a previous expnes. Aeon earl cosets have the same magnitude dating this model Way to be oe, un the nmber of estes, cal thatthe logis regreson mos! output robbs ores ces The das wth the highest probabil tena the sare ritn) ect te code andthe cel teow to compat nds a sample of hese cls probable forte ts ete set. 2 pobeolatetes = togistte nod predict prose tess) 2 prine(presantesee(35)3]) Lce.ssrasens 230868) ev soeaass 9.6095572) (o.seeaze2 0.036857798) {o-aesaaes o.71321957] ecesurias. o.senaes ] {e.saseer7 00489373] [esiessee (o.sarease (e.sieis38 (e.seseess (esu7serr (eacaeses 0 ss19351] Cenensese (orrassi2 0 228008] Tecsisess7 oveessaes 1) E The fat column the probaity of cote oO a the second cou isthe probity ofa core of Noe hat for mort bt nota, the probably oa scre of Ui higher than 2 Score and evaluate the classification model Now tat the cls robabities have been computed these values must be westnmad nto aca ass cores. Real tthe hod fo twos regression ae competed y ping the grad ort ransforaton tthe output ofthe near model The sinpl che {osetthe deol betaeen he wo itelhoods sO. The cade i the ce below apes hs il esha othe probably fa scare for the testa. few examples along wth he cu abl ethan dplayd, Execute th coc and eae he res 2 (orbs, threshold) 2 sray({i Sf > threshod else @ for Sn srobel2s10]) : oae(pransiseues, 8) 4S prlne(novereey(eeoretl 35D) S prdnety teretaish feiere aaey [seers aaea] Serve fhe postive praictons spe wth te tt basin the second row, but sve do nt Gren the resus ofthe est data how can you guy he penance tthe med genta you ust aways use mltipe mets to ‘vauat the performance of any mathine leaning modeling css Forster there ara nurberof metrics commonly use. The anion mati bso the crecty an increased cases 9 abl ‘As aeady stata, the conson matic ay cu coat rice sid casts. Fo then vols cave te conson mati ‘organized as fotows ‘Scored Portve | Scored Negative ‘Rema Peatre | Tos Pose | Fake Negatve ‘AcmalNegatve |e ste | Te Negtive “re Pstv or TP are cate wth ote bl nich hve ben comet citi spot “rae Negative o TN are caes th negate abel hich hoe been ceed a raga Fate Poti or FP eases wit eg bes which have bee income casted as poste Fate Negative or FN ar cases with pote abl whch ve been coc assted nai ‘ine renting 3 confxon mitts import to understand an manana commento fer hichiferenisting positive ad negative be salu The sul ements to cate Lease poste ad the case negate Notice ta theres an abit in ich aes onsidered pov and whch ir onside ego hen he consion mats compte inenere you amine acofsion mata good Hea a spend arrament and decide which ase whch Thsstep al ip you relate he res othe problem aha ‘ecarsey -Aceuneyis simple and often misused metic in simple terns, acer the facon fase comecy csi Fora wo- das dase. pecacy = BP +EN tow eey = TPE EPs TINY FN ‘Accu can be quite seating For empl, 50 clsteris sed to detect adler count ae he rate of au es an 1 A se model woud bet yal account ae not aude. Tis model hae acraey exceeding 099 This sounds mpesve bi clay eles. rection Preson the frscon af cont cased abl cases ot fl cats sie with hat ibe ale We cn exes peso bythe folowing relatos Pe Inthe words, the pecan sat ithe number comets cae forthe bev ded byl th eae in the clue, Ts presions serie ote number of cases comecy arsed fora gen score va. cals the faction of cases of label value eect dss ut of allcases tha actuay have that abel ale. We an egress rca bythe folowing reatonsp eat = Me Inctner ore, the rec sti the numba of correc cei cae forth belie aided yah aes nthe om Thus. pecison it ‘The sie weights rage of precion ans recat We cin expres byte flaming eons ny Brction recall 2 Speciaion Freel Inctner wore. ea weights metro oral mode perfomance The esr operting carci or ROC ice tht ply the relstneip betwen he re poi ate on he vet mi nee below : Ini youn pc the deste operting point fora iro thi ce Toward the vos low ae poste ate at he oxpene of AUC = 1.0 J Perfect classifier a ROC Curve + “ 1.0 > AUC > 0.5 \ Random guess AUC =0.5 True Positive Rate 9 1.0 False Positive Rate Rc with les of AUC fr balnced oc prob The AUCIs the tae intgtal unde the ROC cave The aera performance ofthe dss is mesied by the ae unde the cu oF ALC. But owen you tenet a peti A aie Te hgh the AUX the ler ts nese mae ponte ate requredt achieve 3 eae re fer comparing casters. The cer wth gher AUC generate bate ne Fortalmce cates random guessing gies n AUC or. balnced at has sia numbers of post and negate aes. $0 Bo sping {andom guesn) with probably porte ponte cane wl roe ROC carve tat rane gory or 020,000 10 1.0 The aca under the tangulr region #23 is cen ss that car than AUC of reser than tar than dom us, tr bland eases this statment notin rein general. ngneering ara mete to mest th tad between radar snl recive come dtacting stage anata rd producing pote response rom nose, sich fn bis ruts rar eee wou beast the dered operating pot sng ROC cae are computed sing the precision recat_tscore support and accuracy_seore functions rom the mecr'es package of sit ret forthe lot regression ods 2 (setae, eevee) 5 Fine Score positive _‘Seore negeve’) © prime kena porsesve Sea"™8 confo,o) +" se" 8 conten 7 Feine(“aeton peuative 36H" 8 cone.e] © we x conta 5 prime) 5 Brlnt(‘Aceurcy 80.26" skin. aceurcy_score(Lobela, scores) ze prime?) inet oateive nega?) Hprine(wum case Sas" A netese{sffo] © seo) 8 netetes 1100) 13 peineCorecinion a4" weetrie(O¥le] + se.2e" x eetrien(OlL)) Bo prine('gcail a 8 peergetalfel + Sear feed = SSeS eereeta}te] $ Soe $ mesec10) 25 print aeeeteaiy sare, scares) amine these rests 1 Thecentison mabe shows the foloning haart a most fe postive cases re corety dssiied, 1826.30 ver ray negative cae re aso ico, thon 49 comet ve. 38inconet 2. The overallaccorcy 77 Howeitat ered he xtemely milange the ease cates re poor ad tie ‘hepicien 3: The cles mtalance cond Of he 300 et caer 21 a pote and Bare naga, The precio rcalland Fal show that poste cases ae dase reasonsty nek bt the negative aes ae not salad mentioned tis thee gabe aes hte of aetest Final, tne codein the al below computes and pis the ROC cure and AUC. The 8G_EUFVE and AE functions ram the cit am ‘ce his ode, vain the res and nser Question 3 onthe couse page. 2s piot suc(tavete, sree) foes tery teanaia a a roe-curve(tabels, prosetss$]) Stee akineuctepr, tor) 2 plesdin(e, 3D) 23 plevitatto, aD) % pltylant 35 —_pleseoei(-False Positive Rate") 16 pltcaho) 1S plot aue(y test, probansicias) to Receiver Operating Characteristic “ue Postive Rate 00 False postve Rate ‘The ROC cure i abo th agonal etd Ine ad the Ai 77 But gn te cs mbes of two pois aso each naga aes (ne point of compton aie "dae th set cates to pote The cde nthe al below contain sch ci. Thi lore at realy cto Th cleo shard coded. To ROC cave and ALC at than computed and played an the code, nd wane he 2 provs.porstive = npuconcatente((rp-one((grababshitis. shape], 1), 2 ecrere((praoebilities.shanefe}, 13), 3 eae) 4S sores positive robe postive, 5 peineaneerdesy. seat, seore_ponstive) © plotaavety test, probe pecttive) Postelve gneve UrceFineawtriciarning: Precision and Foecore are Sll-dofined and Geing tet 6.8 in ibele with no preaicted “wer peFlaverege, editier, wat)? Receiver Operating Characteristic vestart, Lent 10 “ue Postive Rate cy) 2 oe oe 08 10 Note the acura rom thi air is 0.71 Thi rales the cs males, The ROC cue det along the dagons which ges an RUC of Compute a weighted model Fecal that ae casing aba creat isk custome as good costs the bank ve nes mare thancasthing a good eat sk cstema as ba {Geen station the reals ofthe frat mode ae nt hat good Tere ar two ressne or hi 1. The sialic othe abel hase the ting fhe made Ayu carved rm the curacy of he naive eee noth “ferent rom the logit rerestion mode. 2. Natng has ben dene to weight the ests ova conecy ssiyjing the bad ced sk cstomesat the expense of th ood red rit ‘ne sporach these rblensis to wiht the ds when computing the logic gression model The code ithe cl below 2s 8 oe note ombinaon sete ts code a gisticagression Lopietinagrecsion(clazewespree(@s 0.45, 1 ss) Next excite the cde nthe cel eo to compat td splay the ds praise ase the nea predit_pronact test) 35D Ie.s1365746 0, 10838254) o.aszuse o.64937282] {o.s2ss0%e 0.070002 | {o.anrasaa 0.206278) estas evcesent | (1.755537 o.eczeses] (o.seeia773 0.695652271) E By eyebl the above probit re nat ey erent om the unweighted mode Ton ters any sian een with he vighted made compute te scores and the mets and play the rics by executing ‘The answer Question 4on he couse pope 2 printed 5 pletaavety testy pro Receiver Operating Characteristic 3 a 2 & 00. ‘The acy slg changed wh resect tothe neigted model. The change cal be more had we ove mre wean one of hele Notice so, the ROC cue ane AL ae tenance. The ade tween ue postive ad eps Snr oe ung Find a better threshold Theres another way op the model scaring tard corey entying the bad cre cases. The scrng resol can be adjusts, Ui now that te sore determined by sting th threshold along the sed rag uncon poset evo ether ote or eave aes of ve ante esol wales et sco and enamine how hanging the hes ae changes te scoing for he mode a sprechols «+ cto(eneznots)) 5 printineerea(latels, sores) 7 eyesnente © 0.48, 0.60, 0.38, 0.5, 0.25] 2" test theeshola(protensseses, y test, ©) For snranone « 0.25 Ae the testo decreazed the number of corey ced negative aes bd re citomer cee a the expense of corey Parc sell mei ee ‘act wich tirestold to pick isa buss dection Notice tat witha threshold vale of 25 the number of fae negates nisifed good summary features sed ny vie cdg the calor festures he eu a apy ara of etre anda uy aay of te abel els, 2 Compsted logs mgresson model 3. ranted the pertomance of he mol xing mile etic dear aca ent 8 parcul well met hee The rae se produced accra hat ws on Somewhat worse 36ers mbslance. The {olson mae and the resin real ap F sass gave rearing measures of adel peornatce, spec when coed ogee ‘4 Rewsgtod the libel and changed te dation resol for he renighted mal Thee sep hp overoms bah tec moaance

You might also like