You are on page 1of 22

Question -1)

import numpy as np
import pandas as pd
import os

os.chdir(r"D: Download\Data Analysis")

df = pd.read_csv("kc_house_data_NaN.csv")
df.sample(2)

Unnamed: 0 id date price bedrooms


bathrooms \
21209 21209 3448720020 20140613T000000 385000.0 4.0
2.5
3876 3876 3626039228 20140918T000000 408000.0 3.0
1.0

sqft_living sqft_lot floors waterfront ... grade


sqft_above \
21209 2050 5276 2.0 0 ... 7
2050
3876 1380 7015 1.5 0 ... 7
1380

sqft_basement yr_built yr_renovated zipcode lat long


\
21209 0 2006 0 98059 47.4910 -122.15

3876 0 1925 0 98117 47.6987 -122.36

sqft_living15 sqft_lot15
21209 2480 5447
3876 1160 6700

[2 rows x 22 columns]

col = df.columns[3:]
col

Index(['price', 'bedrooms', 'bathrooms', 'sqft_living', 'sqft_lot',


'floors',
'waterfront', 'view', 'condition', 'grade', 'sqft_above',
'sqft_basement', 'yr_built', 'yr_renovated', 'zipcode', 'lat',
'long',
'sqft_living15', 'sqft_lot15'],
dtype='object')

df1 = df[col]
df1
price bedrooms bathrooms sqft_living sqft_lot floors \
0 221900.0 3.0 1.00 1180 5650 1.0
1 538000.0 3.0 2.25 2570 7242 2.0
2 180000.0 2.0 1.00 770 10000 1.0
3 604000.0 4.0 3.00 1960 5000 1.0
4 510000.0 3.0 2.00 1680 8080 1.0
... ... ... ... ... ... ...
21608 360000.0 3.0 2.50 1530 1131 3.0
21609 400000.0 4.0 2.50 2310 5813 2.0
21610 402101.0 2.0 0.75 1020 1350 2.0
21611 400000.0 3.0 2.50 1600 2388 2.0
21612 325000.0 2.0 0.75 1020 1076 2.0

waterfront view condition grade sqft_above


sqft_basement \
0 0 0 3 7 1180 0

1 0 0 3 7 2170 400

2 0 0 3 6 770 0

3 0 0 5 7 1050 910

4 0 0 3 8 1680 0

... ... ... ... ... ... ...

21608 0 0 3 8 1530 0

21609 0 0 3 8 2310 0

21610 0 0 3 7 1020 0

21611 0 0 3 8 1600 0

21612 0 0 3 7 1020 0

yr_built yr_renovated zipcode lat long


sqft_living15 \
0 1955 0 98178 47.5112 -122.257
1340
1 1951 1991 98125 47.7210 -122.319
1690
2 1933 0 98028 47.7379 -122.233
2720
3 1965 0 98136 47.5208 -122.393
1360
4 1987 0 98074 47.6168 -122.045
1800
... ... ... ... ... ... ..
.
21608 2009 0 98103 47.6993 -122.346
1530
21609 2014 0 98146 47.5107 -122.362
1830
21610 2009 0 98144 47.5944 -122.299
1020
21611 2004 0 98027 47.5345 -122.069
1410
21612 2008 0 98144 47.5941 -122.299
1020

sqft_lot15
0 5650
1 7639
2 8062
3 5000
4 7503
... ...
21608 1509
21609 7200
21610 2007
21611 1287
21612 1357

[21613 rows x 19 columns]

df1.isnull().sum()

price 0
bedrooms 13
bathrooms 10
sqft_living 0
sqft_lot 0
floors 0
waterfront 0
view 0
condition 0
grade 0
sqft_above 0
sqft_basement 0
yr_built 0
yr_renovated 0
zipcode 0
lat 0
long 0
sqft_living15 0
sqft_lot15 0
dtype: int64
df1 = df1.dropna()

df1

price bedrooms bathrooms sqft_living sqft_lot floors \


0 221900.0 3.0 1.00 1180 5650 1.0
1 538000.0 3.0 2.25 2570 7242 2.0
2 180000.0 2.0 1.00 770 10000 1.0
3 604000.0 4.0 3.00 1960 5000 1.0
4 510000.0 3.0 2.00 1680 8080 1.0
... ... ... ... ... ... ...
21608 360000.0 3.0 2.50 1530 1131 3.0
21609 400000.0 4.0 2.50 2310 5813 2.0
21610 402101.0 2.0 0.75 1020 1350 2.0
21611 400000.0 3.0 2.50 1600 2388 2.0
21612 325000.0 2.0 0.75 1020 1076 2.0

waterfront view condition grade sqft_above


sqft_basement \
0 0 0 3 7 1180 0

1 0 0 3 7 2170 400

2 0 0 3 6 770 0

3 0 0 5 7 1050 910

4 0 0 3 8 1680 0

... ... ... ... ... ... ...

21608 0 0 3 8 1530 0

21609 0 0 3 8 2310 0

21610 0 0 3 7 1020 0

21611 0 0 3 8 1600 0

21612 0 0 3 7 1020 0

yr_built yr_renovated zipcode lat long


sqft_living15 \
0 1955 0 98178 47.5112 -122.257
1340
1 1951 1991 98125 47.7210 -122.319
1690
2 1933 0 98028 47.7379 -122.233
2720
3 1965 0 98136 47.5208 -122.393
1360
4 1987 0 98074 47.6168 -122.045
1800
... ... ... ... ... ... ..
.
21608 2009 0 98103 47.6993 -122.346
1530
21609 2014 0 98146 47.5107 -122.362
1830
21610 2009 0 98144 47.5944 -122.299
1020
21611 2004 0 98027 47.5345 -122.069
1410
21612 2008 0 98144 47.5941 -122.299
1020

sqft_lot15
0 5650
1 7639
2 8062
3 5000
4 7503
... ...
21608 1509
21609 7200
21610 2007
21611 1287
21612 1357

[21597 rows x 19 columns]

stat = df1.describe().transpose()
stat

count mean std min


25% \
price 21597.0 540202.919757 367133.730890 78000.0000
322000.0000
bedrooms 21597.0 3.373200 0.926299 1.0000
3.0000
bathrooms 21597.0 2.115826 0.768984 0.5000
1.7500
sqft_living 21597.0 2080.321850 918.106125 370.0000
1430.0000
sqft_lot 21597.0 15099.408760 41412.636876 520.0000
5040.0000
floors 21597.0 1.494096 0.539683 1.0000
1.0000
waterfront 21597.0 0.007547 0.086549 0.0000
0.0000
view 21597.0 0.234292 0.766390 0.0000
0.0000
condition 21597.0 3.409825 0.650546 1.0000
3.0000
grade 21597.0 7.657915 1.173200 3.0000
7.0000
sqft_above 21597.0 1788.596842 827.759761 370.0000
1190.0000
sqft_basement 21597.0 291.725008 442.667800 0.0000
0.0000
yr_built 21597.0 1970.999676 29.375234 1900.0000
1951.0000
yr_renovated 21597.0 84.464787 401.821438 0.0000
0.0000
zipcode 21597.0 98077.951845 53.513072 98001.0000
98033.0000
lat 21597.0 47.560093 0.138552 47.1559
47.4711
long 21597.0 -122.213982 0.140724 -122.5190 -
122.3280
sqft_living15 21597.0 1986.620318 685.230472 399.0000
1490.0000
sqft_lot15 21597.0 12758.283512 27274.441950 651.0000
5100.0000

50% 75% max


price 450000.0000 645000.000 7.700000e+06
bedrooms 3.0000 4.000 3.300000e+01
bathrooms 2.2500 2.500 8.000000e+00
sqft_living 1910.0000 2550.000 1.354000e+04
sqft_lot 7618.0000 10685.000 1.651359e+06
floors 1.5000 2.000 3.500000e+00
waterfront 0.0000 0.000 1.000000e+00
view 0.0000 0.000 4.000000e+00
condition 3.0000 4.000 5.000000e+00
grade 7.0000 8.000 1.300000e+01
sqft_above 1560.0000 2210.000 9.410000e+03
sqft_basement 0.0000 560.000 4.820000e+03
yr_built 1975.0000 1997.000 2.015000e+03
yr_renovated 0.0000 0.000 2.015000e+03
zipcode 98065.0000 98118.000 9.819900e+04
lat 47.5718 47.678 4.777760e+01
long -122.2310 -122.125 -1.213150e+02
sqft_living15 1840.0000 2360.000 6.210000e+03
sqft_lot15 7620.0000 10083.000 8.712000e+05

result = pd.DataFrame()

result["Mean"] = stat["mean"]
result["Std"] = stat["std"]
result["Var"] = df1.var()
result["Median"] = df1.median()

result

Mean Std Var Median


price 540202.919757 367133.730890 1.347872e+11 450000.0000
bedrooms 3.373200 0.926299 8.580296e-01 3.0000
bathrooms 2.115826 0.768984 5.913368e-01 2.2500
sqft_living 2080.321850 918.106125 8.429189e+05 1910.0000
sqft_lot 15099.408760 41412.636876 1.715006e+09 7618.0000
floors 1.494096 0.539683 2.912575e-01 1.5000
waterfront 0.007547 0.086549 7.490729e-03 0.0000
view 0.234292 0.766390 5.873534e-01 0.0000
condition 3.409825 0.650546 4.232096e-01 3.0000
grade 7.657915 1.173200 1.376397e+00 7.0000
sqft_above 1788.596842 827.759761 6.851862e+05 1560.0000
sqft_basement 291.725008 442.667800 1.959548e+05 0.0000
yr_built 1970.999676 29.375234 8.629044e+02 1975.0000
yr_renovated 84.464787 401.821438 1.614605e+05 0.0000
zipcode 98077.951845 53.513072 2.863649e+03 98065.0000
lat 47.560093 0.138552 1.919659e-02 47.5718
long -122.213982 0.140724 1.980311e-02 -122.2310
sqft_living15 1986.620318 685.230472 4.695408e+05 1840.0000
sqft_lot15 12758.283512 27274.441950 7.438952e+08 7620.0000

df1.mode().transpose()

0 1 2 3
price 350000.0000 450000.0000 NaN NaN
bedrooms 3.0000 NaN NaN NaN
bathrooms 2.5000 NaN NaN NaN
sqft_living 1300.0000 NaN NaN NaN
sqft_lot 5000.0000 NaN NaN NaN
floors 1.0000 NaN NaN NaN
waterfront 0.0000 NaN NaN NaN
view 0.0000 NaN NaN NaN
condition 3.0000 NaN NaN NaN
grade 7.0000 NaN NaN NaN
sqft_above 1300.0000 NaN NaN NaN
sqft_basement 0.0000 NaN NaN NaN
yr_built 2014.0000 NaN NaN NaN
yr_renovated 0.0000 NaN NaN NaN
zipcode 98103.0000 NaN NaN NaN
lat 47.5322 47.5491 47.6624 47.6846
long -122.2900 NaN NaN NaN
sqft_living15 1540.0000 NaN NaN NaN
sqft_lot15 5000.0000 NaN NaN NaN
Question - 2)

IRIS Dataset
df = pd.read_csv("iris.csv")
df

sepal.length sepal.width petal.length petal.width variety


0 5.1 3.5 1.4 0.2 Setosa
1 4.9 3.0 1.4 0.2 Setosa
2 4.7 3.2 1.3 0.2 Setosa
3 4.6 3.1 1.5 0.2 Setosa
4 5.0 3.6 1.4 0.2 Setosa
.. ... ... ... ... ...
145 6.7 3.0 5.2 2.3 Virginica
146 6.3 2.5 5.0 1.9 Virginica
147 6.5 3.0 5.2 2.0 Virginica
148 6.2 3.4 5.4 2.3 Virginica
149 5.9 3.0 5.1 1.8 Virginica

[150 rows x 5 columns]

df1 = df[df["variety"] == "Setosa"]


df1.sample(5)

sepal.length sepal.width petal.length petal.width variety


49 5.0 3.3 1.4 0.2 Setosa
30 4.8 3.1 1.6 0.2 Setosa
35 5.0 3.2 1.2 0.2 Setosa
10 5.4 3.7 1.5 0.2 Setosa
36 5.5 3.5 1.3 0.2 Setosa

df1.shape

(50, 5)

df2 = df[df["variety"] == "Virginica"]


df2.sample(5)

sepal.length sepal.width petal.length petal.width variety


110 6.5 3.2 5.1 2.0 Virginica
122 7.7 2.8 6.7 2.0 Virginica
128 6.4 2.8 5.6 2.1 Virginica
123 6.3 2.7 4.9 1.8 Virginica
101 5.8 2.7 5.1 1.9 Virginica

df3 = df[df["variety"] == "Versicolor"]


df3.sample(5)
sepal.length sepal.width petal.length petal.width variety
94 5.6 2.7 4.2 1.3 Versicolor
61 5.9 3.0 4.2 1.5 Versicolor
58 6.6 2.9 4.6 1.3 Versicolor
75 6.6 3.0 4.4 1.4 Versicolor
71 6.1 2.8 4.0 1.3 Versicolor

df.variety.unique()

array(['Setosa', 'Versicolor', 'Virginica'], dtype=object)

std = df1.std()
std

C:\Users\AppData\Local\Temp/ipykernel_6828/4192088619.py:1:
FutureWarning:

Dropping of nuisance columns in DataFrame reductions (with


'numeric_only=None') is deprecated; in a future version this will
raise TypeError. Select only valid columns before calling the
reduction.

sepal.length 0.352490
sepal.width 0.379064
petal.length 0.173664
petal.width 0.105386
dtype: float64

fig = px.bar(x = df1.columns[:-1], y = df1.std(), color = std)


fig.update_layout(
title='IRIS-setosa std bar-plot',
xaxis_title='Iris flower type',
yaxis_title='size of flower type'
)
fig.show()

C:\Users\AppData\Local\Temp/ipykernel_6828/2989641672.py:1:
FutureWarning:

Dropping of nuisance columns in DataFrame reductions (with


'numeric_only=None') is deprecated; in a future version this will
raise TypeError. Select only valid columns before calling the
reduction.

{"config":{"plotlyServerURL":"https://plotly.com"},"data":
[{"alignmentgroup":"True","hovertemplate":"x=%{x}<br>y=%{y}<br>color=%
{marker.color}<extra></extra>","legendgroup":"","marker":{"color":
[0.35248968721345136,0.3790643690962887,0.17366399648018407,0.10538558
938004565],"coloraxis":"coloraxis","pattern":
{"shape":""}},"name":"","offsetgroup":"","orientation":"v","showlegend
":false,"textposition":"auto","type":"bar","x":
["sepal.length","sepal.width","petal.length","petal.width"],"xaxis":"x
","y":
[0.35248968721345136,0.3790643690962887,0.17366399648018407,0.10538558
938004565],"yaxis":"y"}],"layout":{"barmode":"relative","coloraxis":
{"colorbar":{"title":{"text":"color"}},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]]},"legend":{"tracegroupgap":0},"margin":
{"t":60},"template":{"data":{"bar":[{"error_x":
{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":
{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"barpo
lar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"
carpet":[{"aaxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"ch
oropleth":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"choropleth"}],"contour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"contour"}],"contourcarpet":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"contourcarpet"}],"heatmap":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmap"}],"heatmapgl":[{"colorbar":
{"outlinewidth":0,"ticks":""},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmapgl"}],"histogram":[{"marker":{"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],
"histogram2d":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2d"}],"histogram2dcontour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2dcontour"}],"mesh3d":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"mesh3d"}],"parcoords":[{"line":
{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"parcoords"}],"pie":
[{"automargin":true,"type":"pie"}],"scatter":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter"}],"scatter3d":
[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":
{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter3d"}],"scattercarpet":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattercarpet"}],"scattergeo":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergeo"}],"scattergl":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergl"}],"scattermapbox":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattermapbox"}],"scatterpolar"
:[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolar"}],"scatterpolargl
":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolargl"}],"scatterterna
ry":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterternary"}],"surface":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"surface"}],"table":[{"cells":{"fill":
{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":
{"color":"#C8D4E3"},"line":
{"color":"white"}},"type":"table"}]},"layout":{"annotationdefaults":
{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"autotypenumbers
":"strict","coloraxis":{"colorbar":
{"outlinewidth":0,"ticks":""}},"colorscale":{"diverging":
[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],
[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],
[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]],"sequential":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"sequentialminus":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]]},"colorway":
["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692"
,"#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"geo":
{"bgcolor":"white","lakecolor":"white","landcolor":"#E5ECF6","showlake
s":true,"showland":true,"subunitcolor":"white"},"hoverlabel":
{"align":"left"},"hovermode":"closest","mapbox":
{"style":"light"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","po
lar":{"angularaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","radialaxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"scene":
{"xaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"yaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"zaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
},"shapedefaults":{"line":{"color":"#2a3f5f"}},"ternary":{"aaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","caxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"title":
{"x":5.0e-2},"xaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2},"yaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2}}},"title":
{"text":"IRIS-setosa std bar-plot"},"xaxis":{"anchor":"y","domain":
[0,1],"title":{"text":"Iris flower type"}},"yaxis":
{"anchor":"x","domain":[0,1],"title":{"text":"size of flower type"}}}}

fig = px.bar(x = df2.columns[:-1], y = df2.var(), color = df2.var())


fig.update_layout(
title='IRIS-Versicolor std bar-plot',
xaxis_title='Iris flower type',
yaxis_title='size of flower type'
)
fig.show()

C:\Users\AppData\Local\Temp/ipykernel_6828/1933175752.py:1:
FutureWarning:

Dropping of nuisance columns in DataFrame reductions (with


'numeric_only=None') is deprecated; in a future version this will
raise TypeError. Select only valid columns before calling the
reduction.

{"config":{"plotlyServerURL":"https://plotly.com"},"data":
[{"alignmentgroup":"True","hovertemplate":"x=%{x}<br>y=%{y}<br>color=%
{marker.color}<extra></extra>","legendgroup":"","marker":{"color":
[0.4043428571428573,0.10400408163265305,0.30458775510204084,7.54326530
6122449e-2],"coloraxis":"coloraxis","pattern":
{"shape":""}},"name":"","offsetgroup":"","orientation":"v","showlegend
":false,"textposition":"auto","type":"bar","x":
["sepal.length","sepal.width","petal.length","petal.width"],"xaxis":"x
","y":
[0.4043428571428573,0.10400408163265305,0.30458775510204084,7.54326530
6122449e-2],"yaxis":"y"}],"layout":{"barmode":"relative","coloraxis":
{"colorbar":{"title":{"text":"color"}},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]]},"legend":{"tracegroupgap":0},"margin":
{"t":60},"template":{"data":{"bar":[{"error_x":
{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":
{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"barpo
lar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"
carpet":[{"aaxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"ch
oropleth":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"choropleth"}],"contour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"contour"}],"contourcarpet":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"contourcarpet"}],"heatmap":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmap"}],"heatmapgl":[{"colorbar":
{"outlinewidth":0,"ticks":""},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmapgl"}],"histogram":[{"marker":{"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],
"histogram2d":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2d"}],"histogram2dcontour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2dcontour"}],"mesh3d":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"mesh3d"}],"parcoords":[{"line":
{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"parcoords"}],"pie":
[{"automargin":true,"type":"pie"}],"scatter":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter"}],"scatter3d":
[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":
{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter3d"}],"scattercarpet":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattercarpet"}],"scattergeo":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergeo"}],"scattergl":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergl"}],"scattermapbox":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattermapbox"}],"scatterpolar"
:[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolar"}],"scatterpolargl
":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolargl"}],"scatterterna
ry":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterternary"}],"surface":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"surface"}],"table":[{"cells":{"fill":
{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":
{"color":"#C8D4E3"},"line":
{"color":"white"}},"type":"table"}]},"layout":{"annotationdefaults":
{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"autotypenumbers
":"strict","coloraxis":{"colorbar":
{"outlinewidth":0,"ticks":""}},"colorscale":{"diverging":
[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],
[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],
[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]],"sequential":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"sequentialminus":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]]},"colorway":
["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692"
,"#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"geo":
{"bgcolor":"white","lakecolor":"white","landcolor":"#E5ECF6","showlake
s":true,"showland":true,"subunitcolor":"white"},"hoverlabel":
{"align":"left"},"hovermode":"closest","mapbox":
{"style":"light"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","po
lar":{"angularaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","radialaxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"scene":
{"xaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"yaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"zaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
},"shapedefaults":{"line":{"color":"#2a3f5f"}},"ternary":{"aaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","caxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"title":
{"x":5.0e-2},"xaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2},"yaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2}}},"title":
{"text":"IRIS-Versicolor std bar-plot"},"xaxis":
{"anchor":"y","domain":[0,1],"title":{"text":"Iris flower
type"}},"yaxis":{"anchor":"x","domain":[0,1],"title":{"text":"size of
flower type"}}}}

fx = px.bar(x = df2.columns[:-1], y = df3.var(), color = df3.var(),


title = "Virginica")
fx.update_layout(
title='IRIS-Virginica std bar-plot',
xaxis_title='Iris flower type',
yaxis_title='size of flower type'
)
fx.show()

C:\Users\AppData\Local\Temp/ipykernel_6828/1933840232.py:1:
FutureWarning:

Dropping of nuisance columns in DataFrame reductions (with


'numeric_only=None') is deprecated; in a future version this will
raise TypeError. Select only valid columns before calling the
reduction.

{"config":{"plotlyServerURL":"https://plotly.com"},"data":
[{"alignmentgroup":"True","hovertemplate":"x=%{x}<br>y=%{y}<br>color=%
{marker.color}<extra></extra>","legendgroup":"","marker":{"color":
[0.2664326530612245,9.846938775510206e-
2,0.22081632653061228,3.910612244897959e-
2],"coloraxis":"coloraxis","pattern":
{"shape":""}},"name":"","offsetgroup":"","orientation":"v","showlegend
":false,"textposition":"auto","type":"bar","x":
["sepal.length","sepal.width","petal.length","petal.width"],"xaxis":"x
","y":[0.2664326530612245,9.846938775510206e-
2,0.22081632653061228,3.910612244897959e-2],"yaxis":"y"}],"layout":
{"barmode":"relative","coloraxis":{"colorbar":{"title":
{"text":"color"}},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]]},"legend":{"tracegroupgap":0},"template":{"data":
{"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":
{"color":"#2a3f5f"},"marker":{"line":
{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"barpo
lar":[{"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"barpolar"}],"
carpet":[{"aaxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"baxis":
{"endlinecolor":"#2a3f5f","gridcolor":"white","linecolor":"white","min
orgridcolor":"white","startlinecolor":"#2a3f5f"},"type":"carpet"}],"ch
oropleth":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"choropleth"}],"contour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"contour"}],"contourcarpet":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"contourcarpet"}],"heatmap":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmap"}],"heatmapgl":[{"colorbar":
{"outlinewidth":0,"ticks":""},"colorscale":[[0,"#0d0887"],
[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],
[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],
[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],
[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"heatmapgl"}],"histogram":[{"marker":{"pattern":
{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],
"histogram2d":[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2d"}],"histogram2dcontour":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"histogram2dcontour"}],"mesh3d":[{"colorbar":
{"outlinewidth":0,"ticks":""},"type":"mesh3d"}],"parcoords":[{"line":
{"colorbar":{"outlinewidth":0,"ticks":""}},"type":"parcoords"}],"pie":
[{"automargin":true,"type":"pie"}],"scatter":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter"}],"scatter3d":
[{"line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":
{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatter3d"}],"scattercarpet":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattercarpet"}],"scattergeo":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergeo"}],"scattergl":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattergl"}],"scattermapbox":
[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scattermapbox"}],"scatterpolar"
:[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolar"}],"scatterpolargl
":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterpolargl"}],"scatterterna
ry":[{"marker":{"colorbar":
{"outlinewidth":0,"ticks":""}},"type":"scatterternary"}],"surface":
[{"colorbar":{"outlinewidth":0,"ticks":""},"colorscale":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],
[1,"#f0f921"]],"type":"surface"}],"table":[{"cells":{"fill":
{"color":"#EBF0F8"},"line":{"color":"white"}},"header":{"fill":
{"color":"#C8D4E3"},"line":
{"color":"white"}},"type":"table"}]},"layout":{"annotationdefaults":
{"arrowcolor":"#2a3f5f","arrowhead":0,"arrowwidth":1},"autotypenumbers
":"strict","coloraxis":{"colorbar":
{"outlinewidth":0,"ticks":""}},"colorscale":{"diverging":
[[0,"#8e0152"],[0.1,"#c51b7d"],[0.2,"#de77ae"],[0.3,"#f1b6da"],
[0.4,"#fde0ef"],[0.5,"#f7f7f7"],[0.6,"#e6f5d0"],[0.7,"#b8e186"],
[0.8,"#7fbc41"],[0.9,"#4d9221"],[1,"#276419"]],"sequential":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]],"sequentialminus":
[[0,"#0d0887"],[0.1111111111111111,"#46039f"],
[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],
[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],
[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],
[0.8888888888888888,"#fdca26"],[1,"#f0f921"]]},"colorway":
["#636efa","#EF553B","#00cc96","#ab63fa","#FFA15A","#19d3f3","#FF6692"
,"#B6E880","#FF97FF","#FECB52"],"font":{"color":"#2a3f5f"},"geo":
{"bgcolor":"white","lakecolor":"white","landcolor":"#E5ECF6","showlake
s":true,"showland":true,"subunitcolor":"white"},"hoverlabel":
{"align":"left"},"hovermode":"closest","mapbox":
{"style":"light"},"paper_bgcolor":"white","plot_bgcolor":"#E5ECF6","po
lar":{"angularaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","radialaxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"scene":
{"xaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"yaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
,"zaxis":
{"backgroundcolor":"#E5ECF6","gridcolor":"white","gridwidth":2,"lineco
lor":"white","showbackground":true,"ticks":"","zerolinecolor":"white"}
},"shapedefaults":{"line":{"color":"#2a3f5f"}},"ternary":{"aaxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"baxis":
{"gridcolor":"white","linecolor":"white","ticks":""},"bgcolor":"#E5ECF
6","caxis":
{"gridcolor":"white","linecolor":"white","ticks":""}},"title":
{"x":5.0e-2},"xaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2},"yaxis":
{"automargin":true,"gridcolor":"white","linecolor":"white","ticks":"",
"title":
{"standoff":15},"zerolinecolor":"white","zerolinewidth":2}}},"title":
{"text":"IRIS-Virginica std bar-plot"},"xaxis":{"anchor":"y","domain":
[0,1],"title":{"text":"Iris flower type"}},"yaxis":
{"anchor":"x","domain":[0,1],"title":{"text":"size of flower type"}}}}

Question - 3)
print("The size of each sub-matrix of the IRIS Dataset: ", df1.shape)

The size of each sub-matrix of the IRIS Dataset: (50, 5)

Question - 4)
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt

scaler = MinMaxScaler()

df = df.drop(columns=["variety"])

df_normalized = pd.DataFrame(scaler.fit_transform(df),
columns=df.columns)
df_normalized

sepal.length sepal.width petal.length petal.width


0 0.222222 0.625000 0.067797 0.041667
1 0.166667 0.416667 0.067797 0.041667
2 0.111111 0.500000 0.050847 0.041667
3 0.083333 0.458333 0.084746 0.041667
4 0.194444 0.666667 0.067797 0.041667
.. ... ... ... ...
145 0.666667 0.416667 0.711864 0.916667
146 0.555556 0.208333 0.677966 0.750000
147 0.611111 0.416667 0.711864 0.791667
148 0.527778 0.583333 0.745763 0.916667
149 0.444444 0.416667 0.694915 0.708333

[150 rows x 4 columns]

variance_data = df_normalized.var()

variance_data

sepal.length 0.052908
sepal.width 0.032983
petal.length 0.089522
petal.width 0.100869
dtype: float64

plt.figure(figsize=(10, 8))
sns.barplot(x=variance_data.index, y=variance_data.values)

plt.title('Variance of Normalized Iris Dataset Features')


plt.xlabel('Features')
plt.ylabel('Variance')

plt.show()
Question - 5)
from sklearn.preprocessing import StandardScaler

scalar2 = StandardScaler()

df = df.drop(columns=["variety"])

df_standardized = pd.DataFrame(scaler.fit_transform(df),
columns=df.columns)

variance_data2 = df_standardized.var()

plt.figure(figsize=(10, 8))
sns.barplot(x=variance_data2.index, y=variance_data2.values)

plt.title('Variance of Normalized Iris Dataset Features')


plt.xlabel('Features')
plt.ylabel('Variance')
plt.show()

You might also like