Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Univariant Variable Analysis - Multiple Plots

# Visualization is the easiest way to have an inference about the overall data and the outliers.
#Plotting Graphs Before treating outliers 
for col in df.describe().columns:
  fig, ax =plt.subplots(1,3, constrained_layout=True)
  fig.set_size_inches(20, 3)
  sns.distplot(df[col], ax=ax[0]).set(title="Distplot")
  sns.histplot(df[col], ax=ax[1]).set(title="Histplot")
  sns.boxplot(df[col], ax=ax[2]).set(title="Boxplot")
  plt.suptitle(f'{col.title()}',weight='bold')
  fig.show()
Comment

Univariant Variable Analysis - Multiple Plots

# Defining a function to Notate the percent count of each value on the bars
def annot_percent(axes):
  '''Takes axes as input and labels the percent count of each bar in a countplot'''
  for p in plot.patches:
    total = sum(p.get_height() for p in plot.patches)/100
    percent = round((p.get_height()/total),2)
    x = p.get_x() + p.get_width()/2
    y = p.get_height()
    plot.annotate(f'{percent}%', (x, y), ha='center', va='bottom')
    

# Defining r to autofit the number and size of plots
r = int(len(catagorical_columns)/3 +1)


# Plotting the countplots for each target variable
plt.figure(figsize=(18,r*3))
for n,column in enumerate(catagorical_columns):
  plot = plt.subplot(r,3,n+1)
  sns.countplot(df[column]).margins(y=0.15)
  plt.title(f'{column.title()}',weight='bold')
  plt.tight_layout()
  annot_percent(plot)
Comment

PREVIOUS NEXT
Code Example
Python :: timedistributed pytorch 
Python :: how can i get the data from a queryset in django template 
Python :: The simplest way to start using doctest in python 
Python :: google.api_core.exceptions.ServiceUnavailable: 503 The datastore operation timed out, or the data was temporarily unavailable when using stream 
Python :: How split() works when maxsplit is specified 
Python :: function with parameters python 
Python :: install cs50 library python 
Python :: use python logging to log user ips+time in a file whenever a request comes to the server, this should be done in a custom middleware. 
Python :: Take input of any number and generate all possible binary strings without recursion 
Python :: How to Remove Items in a Set in Python Using the remove() Method 
Python :: py decorateur 
Python :: axios post to django rest return fobidden 403 
Python :: Python Tkinter Menu Widget Syntax 
Python :: generate a random string with lowercase uppercase and numbers 
Python :: python get the X charecters at the end of a string 
Python :: python generate c array 
Python :: Joining String And Variable 
Python :: Common elements in a list(comparing two lists.) 
Python :: how to get total seconds in django queryset for timedelta field 
Python :: python how to not allow class instance 
Python :: how to give tab space in python 
Python :: how to classify numbers in python 
Python :: msg to pdf converter using python 
Python :: Random parola uretme 
Python :: non venomous snakes 
Python :: python dash bootstrap buttons with icons 
Python :: how to write flow of execution in python 
Python :: cudf - merge dataframes 
Python :: jhon wick 
Python :: student notebook (finish), INB (finish), Food and Fitness log (log necessary), debate speech (finish) 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =