0% found this document useful (0 votes)
10 views5 pages

B Question5

Uploaded by

linux lover
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)
10 views5 pages

B Question5

Uploaded by

linux lover
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/ 5
Question 5 IRIS ?ython for Data Science - Perform Data Visualization on Iris Dataset a)Load the Titanic dataset into one of the data structures (NumPy or Fandas). )Display header rows and description of the loaded dataset. ©) Clean the data if applicable d) Find the average petal width of each category of IRIS Species @) Data Visualization for: (i) How many flowers of each species exists for each value of sepal width (i) How many flowers are there whose petal width is <1, between 1 to 2 and >2 (i) Tally the Iris-Versicolour and Iris-Virginica species according to the value of Sepal Width Click here to download dataset fnumpy - Deals multi-dimensional arrays and matrices aseaborn - Deals with data visualization ‘matplotlib - Plotting; pyplot-interactive plotting pandas - data structures and data analysis tools import seaborn as sns import pandas as pd import matplotiib.pyplot as plot a#Import csv file into variable (dataframe) Aris df = pd.read_csv(‘iris.csv') iris df.head() Sepal_Length Sepal Width Petal_Length Petal Width Class 0 35 14 02 Iris-setosa 1 49 30 14 012 Iris-setosa 2 47 32 13 0.2 ris-setosa 3 46 34 15 012 ris-setosa 4 5c 36 14 0.2 Iris-setosa print info about datafrane print("This is info() output\n") print (inis_df.info()) print("\nthis is describe() output\n") print (iris_df.describe()) This is info() output RangeIndex: 150 entries, @ to 148 bata columns (total § columns) Non-Nul1 Count Dtype # Column 2 Sepal_tength 1 Sepal_width 2 Petal_tength 3 Petal_width 4 Class 150 150 150 150 150 non-null non-null non-null non-null non-null dtypes: floate4(4), object(1) memory usag None 6.0+ KB This is describer() output Sepal_Length count 150. mean std min 25% 50%, 75% max drop sepal_U Anis_d#.drop(['Sepal_Length’ ), axis=1, inplace=True) inis_d*.head( 200000 843333 828066 - 300800 108000 800000 408600 902800 ‘ength ) se u spal_Width 50.600000 054000, 433594 208000 800000 208000 308000 408000 PeuNvew Floated Floate4 floated Floated object Petal_Length 150.000000 758667 764426 00000 600000 350000 100008 -980008 One EEY Sepal Width Petal Length Petal Width Class ° 35 1 30 2 32 3 3, 4 36 14 14 13 15 14 02 tis-setosa 02. tis-setosa 02. tis-setosa 02. tis-setosa 02. tis-setosa Petal_width 150 200000 -198667 -763161 100000 -308000 300008 800000 500000 inis_df.groupby( ‘Class’ ,as_index=False)[' Petal_Width" ].mean() Class 0 ris-setose 1 ris-versicolor 2 ris-virginice Petal Width 9244 1326 2.026 # we increase the size of output graph plot. Figure(figsize=[12,6])
‘plot graph of class vs sepalwidth ax=sns.countplot (data=iris_df,x=" Sepal_width’ hue= "Class", palette="Set1") ax.set(title='Flower of each species’ ,xlabel="Sepal Width" ,ylabel='No. of flowers") plot.tight_layout() plot .show() Flower of each species lass mm ris-setosa lm Iris-versicolor mE Iris-virginica No. of flowers 2.0 2.22.3 2.42.5 2.6 2.72.8 2.93.0 3.13.2 333.435 3.63.73.83.9404.14244 Sepal Width Cut petal width accoding to interval and give Labels from categories interval = (0,1,2,4) category = ["<1','1 to 2","22'] Anis_df['Petal_catg') = pd.cut(iris_df[' Petal_Width' ), interval, labels=category) ax = sns.countplot(data = iris df,x = 'Petal_catg' ,hue='Class' ,palette='seti') ax.set(title='Petal Width’, xlabel='Category of Petals’ ,ylabel='No. of flowers") plot.show() Petal Width 50 Class lm Iris-setosa lm ris-versicolor 0 mE Iris-virginica % 30 & 2 2 20 10 o <1 ax = sns.countplot (data 1to2 Category of Petals iris_df[iris_df[ ‘Class’ >2 "Inis-setosa’],x = * Sepal_widt ax.set(title='Versicolor vs virginica’ ,xlabel="Sepal Width’ ,ylabel='No. of flowers’ plot.show() No. of flowers 2 10 © a Versicolor vs virginica Class lm iris-versicolor Mm ris-virginica 20 22 2.3 2.4 25 26 27 2829 3031 32 33 34 36 38 Sepal Width

You might also like