Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
5 views
Decision Tree
Decision tree
Uploaded by
2023aa05902
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Decision Tree For Later
Download
Save
Save Decision Tree For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
5 views
Decision Tree
Decision tree
Uploaded by
2023aa05902
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Decision Tree For Later
Carousel Previous
Carousel Next
Save
Save Decision Tree For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 9
Search
Fullscreen
sav eae import pandas 35 aypd Amport nunsy 25 nye from sklearn.tree import DectsionTreeclassi fen from sklearn nodel_selection dnport train test split from sklearn.netrics import confusion nacrix from sklearninctrics dnpert accuracy_score from sklearn.netrics import classification report import natplotisb.ayplot as ayplot from sklearn import tree from skiearn.ensenole Inport RandenForest¢iassifter ssydatannypd.read_csv("C:/Users/hp/Oounoads /data csv") sydata, info)
Rangelndex: S69 entries, @ to S6B Data colunns (total 33 colums) clue Hon-mull Count type ie 59 nonnull inte agnosis Se9 nonsnll object, radius nean Ses on-ruldFlstea ectre nean Sco non-null Floated perinetar-nean 565 non-null floated brea aes 5s non-null Floated Snoothness_nean 565 non-null floated Comoctnessinean ——-SeD non-null Floated concavity. naan 565 non-null floats Concave polnts_tean—SeD non-null Floated symetryaean 565 non-null floats Stactaldnension_pean 569 non-null floated radius. se 565 non-null floates texture se 565 non-null floats perinetarse 565 non-null floated tease 565 non-null floates snocthness_se Se5 non-nail Floatet Conpactnesi se 565 non-null flootet toneaity 58 Fister floates Syme se ‘Homessavnaa. sae a 2 2 2 23 28 2 28 2 Fr a 32 evr: fractal_dinension_se rodiue_poret texture worst perineter worst area_worst Enoathness worst compactness uorst concavity worst concave paints worst symetry worst fractal dinension worst Unnared: 32 memory usage: 146.84 XB sydata.deop("id", syaata. info) 569 369 569 569 569 569 569 569 569 569 569 non-null fon-nuld ron-nuld fon-nuld ron-rull fon-nuld non-null fon-nuld ron-nuld fon-nuld oa-ruld @ non-null floate4(31), intsa(2), ebject(2) "uonaned: 32"), axiseL, inpla
Rangetndex: loatsa floatet Floatsa Floats Floatsa ‘floatet floats floated floats #loatet Hloatss Floats Non-Mull Count type 569 entries, @ to 568 Data coluns (total 31 colums): elu diagnosis radius_nean texture ean perineter_nean snoothness. ean compactness mean concavity. nen concave paints mean symetry scan ‘ractal_dinension mean redius_ se texture_se perinetér_se snoathness_ se compactness se concavity se concave points se 569 569 569 569 569 569 569 569 569 569 559 569 569 569 559 569 569 569 569 on-nul ron-nuld fon-nuld ron-ruld fon-null ogra fon-nul fon-rall mon-nul ron-rull fon-rull fon-nul fon-null fon-null fon-rull fon-rull roa-rull ron-ruld fon-nuld ail (sig ain on RATE [gst object Floatsa Floats Floatsa Floats ‘loatoa floated loatoa floated Floated Aloatss Floatea Floated Floated Aloatss Floated Aoatss Floatsa floatet Floated floatetsav eae con Ye 21 radius worst 569 non-null fleatsa 22 texture worst 569 non-null floated 23 perineter worst 569 non-null fleatsa 24 breaworst 5369 non-null fleatsa 25 Snoothness worst 569 non-null fleatsa 25 compactness worst 569 non-null floated 27 concavity worst 568 non-null floats 2B concave paints worst 569 non-null floatsd 29 symetry worst 568 non-null floats 5 fractal. dinension worst $69 non-null floatéd types: #loatea(se), object(1) memory usage: 137.94 KB 4 Separating the target vartable X = mydata.values[:, 2] Y= mydatavalues{:, &] Ktrain, xzest,¥ train, Y_test = train sest_split(x, ¥, test_size Yirainisie 455 4 Function t0 perform training with giniindex. fee train using gial(%,¥) ¥ creating the clossifter object ‘clf_gind = DecistontreeClassifier(criterson ni" randon_state = 100,max dept 4 performing training ce gin EK, return clf_gink # Function to perform training with entropy. def Carin using. entropy (X,Y) 1 bectston tree with entropy cLfLentropy * Decistontreeclassifier(criterion » "entropy", randon_state = 18¢ymax_depth = 28, nin_sanples_lsaf = 3) 4 performing training eLf_entropy- 4806) _eading Nat afaoutg/ConmontTMl fone ontsav eae # Function to perform training with random forest classifier, def tarin_using efe(A¥yn est) rfc = RanconForestClassirien(n_estinatorsen_est, randon_stater fee fitOK ¥) return rf 1+ Function to make predictions det prediction(x test, clf object) # Predicton on test Yyapred = elf object.predict(X test) Dprint( "Predicted vaiues:") print(y pred) return y_pred det cal_aceuracy(y_test, y_pred) prlat("confusian Matcie: "confusion matebx(y_test, y_preé)) print ("Accuracy : ",accunacy_score(y.test,y- pred) +108) Drint("Repart : ",classifieation, renert(y_ test, y-pred)) ‘ranyaatacoluans.values ene['h, 8") fet gen tree(ci#) Fig, sx08 » yplot.subplots(nrous = Lyncols = 2, flgsize = (747), spie500) ‘Eree.plot_tree(elf, feature nanes ~ fn,class_sanee-cn, filled ~ true) nypiot. show) ‘Fipssaveftgt"snagenane.prg') cle gin » erotn_using pint (X train, V_tratn) Prediction using gint print("Results Using Gini Tadex:") Yopred_gint = predietion(X test, elf_gint) cal_aceuracy(¥_test, y_pred_gini) fenctrea(el ins) _eading Mat liopoiConmeniTM foneiTRonestsPredicted values c 3° tm ae me ae aoe 18 Ww Confusion Matrix: (433]] Accuracy Report: 8 " accuracy cro ave weighted avg. oe ee % Bas a m] (1683) 93.85964912280701 precision 0.96 ean 0.93 2.94 recall _eading ataaoupuiConmeniTMt oneness aa ane mon OW an Fi-seore support n 8 aa ua uaclt_entropy = tarin_using_entropy( train, ¥_train) # prediction using entropy print(*Results Using tntropy:*) Yuprea_entropy = preaiction(X test, elf_entropy) al sccuracy(_test, y_pres_entrony) enstree(elt_entrony) Results Using Entropy Predicted values (at kw a ae on ow sow oa! ON Ee woe ae a eee aN aN om ~ a ~ a ~Confusion Matrix: [178 2] T3491] Accuracy : 96.49122807017544 Report: ‘precision recall. fi-score support 8 0.96 0990.97 n Meme 083 019s a accuracy 0.96 macro avg 0.97 0.96 0.96 td weighted avg 0.970.950.9518 _eading Mat aop ConmanITM faneiTRonstsclé_rfe = tarin_using efc(X train, Y_train, 28) 4 Prediction using entropy prine(Results Using Fntrony:*) Ypres rfe = prediction(x test, clf_rfe) cal aceuracy(Y_test, y predr#e) Results Using Entropy: Predicted values (at nw a at ow Bee ee ee eae See see WB Bt Ow) Confusion Matrix: [[78 1] T3491] Accuracy : 96.49122807017544 Report precision recall. fl-score 8 0.96 0990.97 n M098 0.93 8.95 8 aa supportsav eae con Ye macroyg 8.57, 096 us weighted avg 0.97. 4 view the feature scores colefois"] feature scorescrypd.Sentes(clf_rfc. Feature teportances.index=col).sort_values(ascendingsFalse) Feature scores, area_se 0.182502 concave points_nean 2.169849, Concave points.worst 0.112208 radius worst 000198 concavity-nean 0.083746, perineter_worst 074382 Fadlus_se 0.045875 area_vorst 0.033503, perineter_mean 0.022796, kexture worst 0.022662 radius. ean 0.016896, fractal dinension worst 0.016442 fractal_dimension_ce 0.013438 symetry worst 0.012875 concavity worst ecena3e conpactness_se 2.011388 farea.nean 010982 texture mean 2.010007 penineter-se 0009439, compactness worst 2.006927 swoothness se 2.006619 ‘fractal dinension 2.005590 texture se 2085804 symetry_nean 2.002044 snoothness.nean 0.003662 symetry £2 2.003557, concavity. se 2.003287 conpactness_nean 2002886, concave poiats se 0.002658, snoothness worst 0.002522 type: floates _eading at anoupuiConmeniTMl faneiTX ont
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6129)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (933)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel