<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Distribution Analysis of the data
Now that we have familarity with the basic characterstics, lets look at the distribution of various variables starting with the continuous variable
Distribution analysis of continuous variable using the describe()
Step1:  Distribution analysis of categorical variable by using the value_counts()
Step2:  Converting the categorical predictor to numeric using Label Encoder from the sklearn library
Step3:  Data Visualization of various predictors for this study
Step4:  Distributions of observations within categories
At a certain point, the categorical scatterplot approach becomes limited in the information it can provide about the distribution of values within each category. There are several ways to summarize this information in ways that facilitate easy comparisons across the category levels.
Boxplots
This kind of plot shows the three quartile values of the distribution along with extreme values. The “whiskers” extend to points that lie within 1.5 IQRs of the lower and upper quartile, and then observations that fall outside this range are displayed independently. Importantly, this means that each value in the boxplot corresponds to an actual observation in the data.
Step5:  Violinplots
A different approach is a violinplot(), which combines a boxplot with the kernel density estimation procedure.
Step6:  Statistical distribution within categories
Often, rather than showing the distribution within each category, you might want to show the central tendency of the values.
Barplots
Step7:  A special case for the bar plot is when you want to show the number of observations in each category rather than computing a statistic for a second variable. This is similar to a histogram over a categorical, rather than quantitative, variable. In seaborn, it’s easy to do so with the countplot() function
Step8:  Point plots
An alternative style for visualizing the same information is offered by the pointplot() function. This function also encodes the value of the estimate with height on the other axis, but rather than show a full bar it just plots the point estimate and confidence interval. Additionally, pointplot connects points from the same hue category. This makes it easy to see how the main relationship is changing as a function of a second variable
<ASSISTANT_TASK:>
Python Code:
sub1.describe()
Explanation: Distribution Analysis of the data
Now that we have familarity with the basic characterstics, lets look at the distribution of various variables starting with the continuous variable
Distribution analysis of continuous variable using the describe()
End of explanation
sub1['extraction_type_class'].value_counts()
sub1['payment_type'].value_counts()
sub1['quality_group'].value_counts()
sub1['quantity_group'].value_counts()
sub1['waterpoint_type_group'].value_counts()
sub1['water_quality'].value_counts()
sub1['source_type'].value_counts()
Explanation: Distribution analysis of categorical variable by using the value_counts()
End of explanation
from sklearn.preprocessing import LabelEncoder
var_mod = ['extraction_type_class','payment_type','quality_group','quantity_group','waterpoint_type_group','water_quality','source_type']
le = LabelEncoder()
for i in var_mod:
    sub1[i] = le.fit_transform(sub1[i])
sub1.dtypes 
Explanation: Converting the categorical predictor to numeric using Label Encoder from the sklearn library
End of explanation
%matplotlib inline
sub1['permit'].hist(bins=10)
t1=pd.crosstab(sub2['water_quality'],sub2['source_type'])
t1.plot(kind='hist', stacked=True, grid=False, legend=True, title="Water quality based on type of water source")
t2=pd.crosstab(sub2['source_type'],sub2['payment_type'])
t2.plot(kind='hist', stacked=True, grid=False, legend=True, title="Water quality and types of payment")
%matplotlib inline
sns.violinplot(x=sub1.extraction_type_class, y=sub1.source_type)
%matplotlib inline
sns.pointplot(x="extraction_type_class", y="water_quality", data=sub1)
%matplotlib inline
sns.violinplot(x="waterpoint_type_group", y="source_type", hue="water_quality", data=sub1)
Explanation: Data Visualization of various predictors for this study
End of explanation
sns.boxplot(x="source_type", y="payment_type",data=sub1)
Explanation: Distributions of observations within categories
At a certain point, the categorical scatterplot approach becomes limited in the information it can provide about the distribution of values within each category. There are several ways to summarize this information in ways that facilitate easy comparisons across the category levels.
Boxplots
This kind of plot shows the three quartile values of the distribution along with extreme values. The “whiskers” extend to points that lie within 1.5 IQRs of the lower and upper quartile, and then observations that fall outside this range are displayed independently. Importantly, this means that each value in the boxplot corresponds to an actual observation in the data.
End of explanation
sns.violinplot(x="extraction_type_class", y="source_type", scale="count", data=sub1)
sns.violinplot(x="extraction_type_class", y="source_type", split="True", data=sub1)
Explanation: Violinplots
A different approach is a violinplot(), which combines a boxplot with the kernel density estimation procedure.
End of explanation
sns.barplot(x="extraction_type_class", y="source_type", data=sub1)
sns.barplot(x="quantity_group", y="quality_group", data=sub1)
Explanation: Statistical distribution within categories
Often, rather than showing the distribution within each category, you might want to show the central tendency of the values.
Barplots
End of explanation
sns.countplot(x="quality_group", data=data)
sns.countplot(y="payment_type", data=sub1)
Explanation: A special case for the bar plot is when you want to show the number of observations in each category rather than computing a statistic for a second variable. This is similar to a histogram over a categorical, rather than quantitative, variable. In seaborn, it’s easy to do so with the countplot() function
End of explanation
sns.pointplot(x="extraction_type_class", y="waterpoint_type_group", data=sub1)
sns.pointplot(x="extraction_type_class", y="water_quality", markers=["^", "o"], linestyles=["-", "--"],data=sub1)
Explanation: Point plots
An alternative style for visualizing the same information is offered by the pointplot() function. This function also encodes the value of the estimate with height on the other axis, but rather than show a full bar it just plots the point estimate and confidence interval. Additionally, pointplot connects points from the same hue category. This makes it easy to see how the main relationship is changing as a function of a second variable
End of explanation
<END_TASK>