Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# A klay c dosya olan 'agaricus - lepiota.names' dosyas n okuyarak i eri ine bak yoruz . file _ path = 'agaricus - lepiota.names'
# Aklayc dosya olan 'agaricuslepiota.names' dosyasn okuyarak ieriine bakyoruz
filepath 'agaricuslepiota.names'
# Dosyann ieriini okuma
with openfilepath, r as file:
namescontent file.read
# eriin ilk karakterini gstermek iin ksaltma yaparak ierii gsterelim
printnamescontent: # lk karakteri gsteriyoruz
#
import pandas as pd
# Veri setini okuyarak DataFrame oluturma
datafilepath 'agaricuslepiota.data.csv
columnnames class 'capshape', 'capsurface', 'capcolor', 'bruises', 'odor',
'gillattachment', 'gillspacing', 'gillsize', 'gillcolor',
'stalkshape', 'stalkroot', 'stalksurfaceabovering',
'stalksurfacebelowring', 'stalkcolorabovering',
'stalkcolorbelowring', 'veiltype', 'veilcolor', 'ringnumber',
'ringtype', 'sporeprintcolor', 'population', 'habitat'
mushroomdata pdreadcsvdatafilepath, headerNone, namescolumnnames
# lk satr gstererek veri yapsn inceleyelim
mushroomdata.head
#
printmushroomdata.describe
#
mushroomdata.info
#All features are categorical but given as 'object' type. First, it is converted into 'category' type.
#
from plotly.subplots import makesubplots
import plotly.graphobjects as go
specs type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'type:'domain'
fig makesubplotsrows cols specsspecs
a
b
xx
yy
l
for col in mushroomdata.columns:
fig.addtracegoPielabelsn for n in mushroomdatacolvaluecountsindex valuesv for v in mushroomdatacolvaluecountssummushroomdatacolvaluecounts namecol
a b
lappenddicttextcol, xxxb yyya fontsize showarrowFalse
a
if a:
a
b
fig.updatelayouttitletext'Features',
layoutshowlegendFalse
fig.updatelayout
titlefontfamily"Arial",
titlefontsize
annotationsl
fig.updatetraceshole hoverinfo"labelpercentname",textinfo'none'
fig.show
#
def makecategoricalmushroomdata, columns:
for column in columns:
mushroomdatacolumn pdCategoricalmushroomdatacolumn
return mushroomdata
#
columns mushroomdata.columns
data makecategoricalmushroomdata, columns
#
mushroomdata.info
#
mushroomdata.shape
#There observation and features in mushroom dataset.
#
mushroomdata.isnullany
#There is no missing value in mushroom dataset.
#
# Veri trleri incelemesi
datatypes mushroomdata.dtypes
datatypes
#
mushroomdatahabitat mushroomdatahabitatgroupbymushroomdataclassvaluecountsnormalize Truerenamefrequencytoframeresetindex
mushroomdatahabitat
#
from matplotlib import pyplot as plt
import seaborn as sns
# Lets create a bar plot to show the Habitat Distribution
snsbarplotdata mushroomdatahabitat,x'habitat',y'frequency',hue'class'
pltxlabelHabitat
pltylabelfrequenncy
plttitleHabitat Distribution: Edible Vs Poisonous";
#
mushroomdatapopu mushroomdatapopulationgroupbymushroomdataclassvaluecountsnormalize Truerenamefrequencytoframeresetindex
mushroomdatapopu
#
## Lets create a bar plot to show the population: Edible Vs Poisonous
import plotly.express as px
fig pxbardataframe mushroomdatapopu x 'population', y 'frequency',color 'class', barmode 'group', title'population: Edible Vs Poisonous'
fig.updatelayoutxaxistitle 'population' yaxistitle 'frequenncy
#
ringnum
o:
t:
n:
ringnum
mushroomdataring mushroomdataringnumber'replaceringnumgroupbymushroomdataclassvaluecountsnormalize Truerenamefrequencytoframeresetindex
mushroomdataring
#
#Lets create a barchart to visualize the number of rings in each class
fig pxbardataframe mushroomdataring x 'ringnumber' y 'frequency' color 'class' barmode 'group',title 'Number of rings: Edible Vs Poisonous'
fig.updatelayoutxaxistitle 'number of rings' yaxistitle 'frequency THE PYTHON CODE GIVEN ABOVE IS RELATED TO RANDOM FOREST CLASSIFICATION IN THE DATA SCIENCE COURSE.
PLEASE INTERPRET THIS CODE AND PREPARE A REPORT ACCORDING TO THE SUBJECTS AND CODES.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started