0% found this document useful (0 votes)
20 views9 pages

Exp Aiml 5

The document contains a Python code snippet for analyzing employee data using logistic regression. It involves generating synthetic data for employee attributes such as age, gender, education, job level, and salary, and then training a model to predict promotions. The code also includes steps for data preprocessing, model training, and evaluating the model's performance using classification reports and confusion matrices.

Uploaded by

Kavya Panu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Exp Aiml 5

The document contains a Python code snippet for analyzing employee data using logistic regression. It involves generating synthetic data for employee attributes such as age, gender, education, job level, and salary, and then training a model to predict promotions. The code also includes steps for data preprocessing, model training, and evaluating the model's performance using classification reports and confusion matrices.

Uploaded by

Kavya Panu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
so/10726, 12:06 PM Unite ipyn -Colab start coding o se with AL Snport pandas as pa # changed np to pa npsrandon 2006(333), age = ap-randon.cansint (22, 48, a) # Sxitched the ones of 10 and 4B to gererate ages between 18 and 42 gender = npcrandon.chotce(( Male", “Tenale"), 0) fdueation ='np.randor.choice({‘high School'," ‘college’, “graduate'}, 9) ob_level = np.rancor.chotce(["Juntor’, "sendor’), ) lnse_evolustion = rp.ranaam-univorn(®.¢, 9%, 7) sverage_sonthly_hours = np-randon-randine(i80, 388, ‘Sne_spend_conpany = np-ranéon.rangine(3, 28, n) nunberof projects = np.randon.candine(2, 7,9) ork azctdent = np.randn.chatce((®, 1], 5) pronation = np.rangar.chaice([®, 1], a) Salary = aperandon.chotce(('Jow, “ediun’, “high*], 9) = pa.vatarranet( “age: 366, ender" gender, ‘edueation' edeeation, ob_lovel": Joh level, ‘overage aonthly_hours'? average monthly, hours, "ne_spend_conpany": tine_spend_conpany, umber of projects": nunber_of projects, ‘work accldent': work sccsaent, "salary': salary » a¢-se.csu¢ ploy fata.cw", tndewstalze) Snport seatorn 25 srs nport aatplotlib.pyplot as pit ‘rom skiearn-nodelnselection snport train test split fron skiearn Linear podel Inport Logistickegression fron skiearn-preprocessing Inport LabelEncoder ‘from sklearnonetries Inport classitication_report, confuston_patrsx dats = pé.reae_csvt" employee data. csv') data.neaet) ‘age gender education job level last_evaluation average sonthly hours tine 073 Male calloge——sonor oar9sss 100 112 Male cologe junior ossrre3 oer 2-28 Female graduate junior ossrsas 2 312 Female college senior oarasss oy 416 Fomale graduate sone osa646: 2a data. snut2()- suet) Intps:ilcolab research google. coridrvee?v8ZogsNiUbarVViLATaQnKFZ_BiiKifprintMode 19 so/10726, 12:06 PM Unite ipynb -Colab age o gender o {ob oval o last_evaluton 0 average monthly hours 0 time_spend_company 0 ‘umber_of projects 0 work accident 0 promotion oo salary ° type it ae = Laetencoderd) Gatat[" gender", ‘education’, “Joe level’, “salary')] = datal(*gender', ‘education’, prantidaranesaQ)) age gender education jad tevel Last evaluation average_sonthiy_ hours DR 8 i a 8.472353 ue ‘ine_spend_conany nunber_of_projects work accident pronotion salary 4 ° a @ fd X = datedropt‘pronetion’, axise1) Y = aatal ‘promotion’ ) \ joe level Kitrain, x test, y_train, y_test = train test split(t, ¥, test size-0.3, random statens4) print(X train. shape, X test-shape, y_trainshape, y_test.shape) (700, 10) (280, 28) (722,) (200,) nodel = LogtstteRegression() nodel F804 train, y-train) B+ togisescregression Logistictegression() print(nodel.coet_) Drinttnogelsnserceps_) a3ii62 007689883 29729172 0.02595137)}) (e.0:360362} Yopred «= model predict (x test) yetest.hesd() Intps:ilcolab research google.coridrve1e?v8ZogsNiUbarVViLATaQnKFZ_éiiKifprintMode salary’) apoly(le.#it_transtora) United. ipynb ~Colab so/10726, 12:06 PM romotion 0 on a0 120 type eportty_test, Ypred)) print etassitication weighted ave 00025951379] yopred = model predict(X.test) yitest.nead() g t 20 on a0 20 print y_pred) a 3 z = z 5 8 5 i i 3 g : 4 $ 3 8 3 i E sort0rzs, 1208 Pat Unite ipynb -Colab print(classification report(y_test,y_oree)) Gn = confurion-astrix(y.testJ.9768)| 3x = pit sapploe0) ns heetang ea, aronteTru, fats’! samen = (‘Predicted Labels") ™ je" True Labels") aucset_title( contusion matete’) aucsands.set_tieelabels( ("Not Promoted", "Promoted axcyands. set tieklabels("Not Promoted", "Pronoted]) meron MET eae os s wit me 8a ta i Confusion Matrix 88 z 95 z 5. oe 5 3 95 i Leo : “ 6 70 i “0 wot romated srometed : Predicted Labels Snport matplotlib.pyplot as plt Xr datal{ age’, “gender', ‘education’, “Job level", ‘last_evaluation', ‘average sonthly. hours", ‘tine spend company", ‘nunber_of projects") Y = ¢atal ‘promotion’ ) Katrain, Xtest, y_train, y_test = train test spLit(K, ¥, test sizer8.3, random staterse) print(x_train.shape, Xtest-shape, y_trainshape, y_test.shape) nodel = LogisticRegression() nodel #8804 train, y-teain) Nipred’ = node preait(K test) print classification report(y_test, Y.peed)) fn = confusion natrix(y-test,¥_2re@) a= plt-simploe) ‘ns, naataap(en,annot-Toue,fnt~'g"2X-at,cHBp- 61025") auc set lapel Predicted Labels") ax.set_ylasei("True Labs") Sec set tiela(Cantusion matrse’) Su sad. set_tietlabels ("Not Promoted Sucyoxs set tleelabels ("Rat Promoted”, pit. shou() Promoted" }) Promoted") Intps:ilcolab research google. coridrvee?v8ZogsNiUbarVViLATaQnKFZ_BiiKifprintMode sort0rzs, 1208 Pat (700, 8) (380, 8) (709,) (29,) Unite ipynb -Colab precision "recall #i-score support 1 eu 59 9.52 135 wittd me 8 tat Confusion Matrix 20 z z os 5 é 0 i Ln b 8 0s 10 wot rometed rrometed - Predicted Labele nport natplotlib.pyplot 95 plt X's data.drop( ‘pronation’, 3835-1) Y = datat 'pramotion’) nodel = Lagistienegression() fodel.#8¢(% train, y_teata) ipred’ = wodel.preatt(x test) print(elassi¢ieation.report(y test, Yared) en = confusion_natrix(y_test,¥_2re@) 3x = ple rapploe0) {rss heataap(enannot=T-ue fats" g" xen, cnape blues") aucset_daen( ‘Predicted Labels") sxcset_ylanel ("True Labels") Sucset title ‘contusion matese’) axcxands.set_ticelabels({ Not Promoted", "Promoted" aucyands.set_tieelabels( (‘Not Promoted", Pronated}) prt. shou() Intps:ilcolab research google. coridrvee?v8ZogsNiUbarVViLATaQnKFZ_BiiKifprintMode seen, Y, kest_siz000.2, randon_seatens4) so/10726, 12:06 PM Unite ipynb -Colab precision recall f2-sc0re support wihted we 8a baat Confusion Matrix 88 z 95 z 5. oe 5 3 95 i Leo : “ 6 70 i “0 wot romated srometed : Predicted Labels ta{L'age", "gender", "education", “jos tevel"]} ta("pronetion") Ktrain, Xtest, y_train, y test = train test split, ¥, test sizes8.3, random statensd) rint(X train. shape, X test-shave, y_train.shape, y_test-stape) nodel = Logisttcregression() nodel F804 train, y-teain) “Epred = node preaict(x cert) print classification report(y_test, Y.pred)) fm = contusion_natrix(y_test,¥_2re@) ax = put sumplaet) ‘ns, eataap (en annot=True,fat='g"axea4,cma9-" blues") faxsset_xdavel( ‘Predicted Labels") axcset_ylabel(‘True Labels") axcset_title( ‘contusion matrix’) ductors. ret_ttetlabels("hot Promoted" "Promoted" 1) Suiyanis.set_tietlabels( {hot Promoted", "Pronated”) pit shou() Intps:ilcolab research google.coridrve1e?v8ZogsNiUbarVViLATaQnKFZ_éiiKifprintMode so/10726, 12:06 PM Unite ipynb -Colab (700, 4) (380, 4) (700,) (38,) precision” © recall #-score support 1 eas 62 est 15, come 0. wind eat ‘Confusion Matrix z 100 z 5. “ é %0 3 0 & : - a wot romated romoted Predicted Labels ‘port sepsis np a8 Xenia, “genders aueaion', “Joplevel’, “astevaletion', “average tonthiypoors 1 dati promotion print (X_train.shape, XLtest-shave, y_train.s ABEL, Y, test sizest.2, random states24) 1 yatest shape) rnodel = Lopisticregression() odel.F1t04 train, y_teain) pred = nodel.precict(x test) print(elassification_roport(y_sest, Yared) Gn © confurion_aatrix(y.test,¥_are@) 3x = plt-sabploe() snasheataag(enarnoteTeuefats'g!atear enap aucset_dasen( ‘Predicted Labels") fax.set_ylabel( "True Labels") aucset_title( ‘contusion matetx’) axcxands.set_ticelabels( "Not Promoted", "Promoted axcyanis.sef_tictlabels({'Not Promoted" "Promoted" pit. shout) Intps:ilcolab research google.coridrve1e?v8ZogsNiUbarVViLATaQnKFZ_éiiKifprintMode 19 so/10726, 12:06 PM Unite ipynb -Colab (700, 6) (380, 6) (709,) (229,) precision recall #-score support cro ave 858 weighed me 38 100 z 3 z4 ® n02 0 s g 7 b 2 2 not rooted rome Predicted Labels snport natplotlib.pyplot a5 pit X's datalL ‘age’, “gender’, ‘ecueation', “Joh level’, ‘last_evaluation', ‘average.vonthly_hours", ‘tine_spend_company', ‘nunber_of projects", Y = datat ‘promotion’ 7 préne(X/train.shape, Xtestishape, y_train.st BLO, Y, test_aizest.2, random states24) + ytest shape) rnodel = Lopisticregression() rodel.F2€04 train, y_teain) ‘pred = nodel.precict(x test) print(elnssification_roport(y_sest, Yared) Gm © confurion_aatrix(y,test,¥_are@) ax = pt subplot) snasheataag(en,armoteTeue fats’ g!atear enap aucset_daen( ‘Predicted Labels") fx.set_ylabel( True Labels") ausset title contusion matrix’) axcxands.set_ticelabels( "Not Promoted", "Promoted ax.yanis.sef_sictlabels({'Not Promoted", "Pronated") pit. shou() Intps:ilcolab research google. coridrvee?v8ZogsNiUbarVViLATaQnKFZ_BiiKifprintMode so/10726, 12:06 PM Unite ipynb -Colab (700, 8) (380, 9) (709,) (29,) precision © retail support ‘ase /ocat/Lib/nythond.1/ist-packages/sklearn/Linear_nodel/ Intps:ilcolab research google.coridrve1e?v8ZogsNiUbarVViLATaQnKFZ_éiiKifprintMode

You might also like