"""
![Adsız.png](attachment:5b9cfc51-041d-4cd4-ae0b-22d0ee4da3d6.png)

<center><h1 style = "background:black;color:white;border:0;border-radius:3px;font-family:Comic Sans MS" >📜 Introduction</h1></center>

<p style = "color:black;font-weight:500;text-indent:20px;font-size:16px;font-family:Comic Sans MS">We will first analyze the data we have in a good way. We'll visualize it later. Then we will refine our model for training. Creating multiple models at once. We will compare the success of these models.</p>

<h2 style = "background:black;color:white;border:0;border-radius:3px;font-family:Comic Sans MS">📋 Content :</h2>

<ul>
    <li style = "color:darkgray;font-size:15px"> <a href = "#1" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Load and Check Data </a> </li>
    <li style = "color:darkgray;font-size:15px"> <a href = "#2" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Variable Description </a> </li>   
    <li style = "color:darkgray;font-size:15px"> <a href = "#3" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Basic Data Analysiss </a> <ul> 
        <li style = "color:lightgray"><a href = "#4" style = "color:black;font-weight:500;font-family:Comic Sans MS"> fixed acidity - quality  </a></li> 
        <li style = "color:lightgray"><a href = "#5" style = "color:black;font-weight:500;font-family:Comic Sans MS"> volatile acidity - quality </a></li>
        <li style = "color:lightgray"><a href = "#6" style = "color:black;font-weight:500;font-family:Comic Sans MS"> citric acid - quality </a></li>
        <li style = "color:lightgray"><a href = "#7" style = "color:black;font-weight:500;font-family:Comic Sans MS"> residual sugar - quality </a></li>
                <li style = "color:lightgray"><a href = "#8" style = "color:black;font-weight:500;font-family:Comic Sans MS"> chorides - quality </a></li>
        <li style = "color:lightgray"><a href = "#9" style = "color:black;font-weight:500;font-family:Comic Sans MS"> free sulfur dioxide - quality </a></li>
        <li style = "color:lightgray"><a href = "#10" style = "color:black;font-weight:500;font-family:Comic Sans MS"> total sulfur dioxide - quality </a></li>
        <li style = "color:lightgray"><a href = "#11" style = "color:black;font-weight:500;font-family:Comic Sans MS"> density - quality </a></li>
                <li style = "color:lightgray"><a href = "#12" style = "color:black;font-weight:500;font-family:Comic Sans MS"> pH - quality </a></li>
                <li style = "color:lightgray"><a href = "#13" style = "color:black;font-weight:500;font-family:Comic Sans MS"> sulphates - quality </a></li>
                <li style = "color:lightgray"><a href = "#14" style = "color:black;font-weight:500;font-family:Comic Sans MS"> alcohol - quality </a></li>
        </ul>            
    <li style = "color:darkgray;font-size:15px"> <a href = "#15" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Missing Value  </a> </li>
        <li style = "color:darkgray;font-size:15px"> <a href = "#16" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Visualization </a> <ul> 
        <li style = "color:lightgray"><a href = "#17" style = "color:black;font-weight:500;font-family:Comic Sans MS"> fixed acidity  </a></li> 
        <li style = "color:lightgray"><a href = "#18" style = "color:black;font-weight:500;font-family:Comic Sans MS"> volatile acidity </a></li>
        <li style = "color:lightgray"><a href = "#19" style = "color:black;font-weight:500;font-family:Comic Sans MS"> citric acid </a></li>
        <li style = "color:lightgray"><a href = "#21" style = "color:black;font-weight:500;font-family:Comic Sans MS"> residual sugar </a></li>
                <li style = "color:lightgray"><a href = "#12" style = "color:black;font-weight:500;font-family:Comic Sans MS"> chorides </a></li>
        <li style = "color:lightgray"><a href = "#23" style = "color:black;font-weight:500;font-family:Comic Sans MS"> free sulfur dioxide </a></li>
        <li style = "color:lightgray"><a href = "#24" style = "color:black;font-weight:500;font-family:Comic Sans MS">total sulfur dioxide </a></li>
                    <li style = "color:lightgray"><a href = "#15" style = "color:black;font-weight:500;font-family:Comic Sans MS"> density </a></li>
        <li style = "color:lightgray"><a href = "#26" style = "color:black;font-weight:500;font-family:Comic Sans MS">pH </a></li>
                    <li style = "color:lightgray"><a href = "#27" style = "color:black;font-weight:500;font-family:Comic Sans MS"> sulphates </a></li>
        <li style = "color:lightgray"><a href = "#28" style = "color:black;font-weight:500;font-family:Comic Sans MS">alcohol </a></li>
                    <li style = "color:lightgray"><a href = "#29" style = "color:black;font-weight:500;font-family:Comic Sans MS">quality </a></li>
</ul>   
         <li style = "color:darkgray;font-size:15px"> <a href = "#30" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Skewness Correction </a> <ul> 
         <li style = "color:lightgray"><a href = "#31" style = "color:black;font-weight:500;font-family:Comic Sans MS"> fixed acidity  </a></li>
        <li style = "color:lightgray"><a href = "#32" style = "color:black;font-weight:500;font-family:Comic Sans MS"> residual sugar </a></li>
        <li style = "color:lightgray"><a href = "#33" style = "color:black;font-weight:500;font-family:Comic Sans MS"> free sulfur dioxide </a></li>
        <li style = "color:lightgray"><a href = "#34" style = "color:black;font-weight:500;font-family:Comic Sans MS">total sulfur dioxide </a></li>
                    <li style = "color:lightgray"><a href = "#35" style = "color:black;font-weight:500;font-family:Comic Sans MS"> alcohol </a></li>
</ul>  
             <li style = "color:darkgray;font-size:15px"> <a href = "#36" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Outlier Detection </a> </li>
    <li style = "color:darkgray;font-size:15px"> <a href = "#37" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Modeling   </a> <ul> <li style = "color:lightgray"><a href = "#38" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px">Import Model Library </a></li> <li style = "color:lightgray"><a href = "#39" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px">Train - Test Split </a></li> <li style = "color:lightgray"><a href = "#40" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> Smote </a></li> <li style = "color:lightgray"><a href = "#41" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px">StandartScaler </a></li> <li style = "color:lightgray"><a href = "#42" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ① KNeighborsClassifier </a></li> <li style = "color:lightgray"><a href = "#43" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ② GradientBoostingClassifier </a></li> <li style = "color:lightgray"><a href = "#44" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ③ SVC</a></li> <li style = "color:lightgray"><a href = "#45" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ④ XGBClassifier</a></li> <li style = "color:lightgray"><a href = "#46" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ⑤ CatBoostClassifier</a></li> <li style = "color:lightgray"><a href = "#47" style = "background:white;color:brown;border:0;border-radius:3px;font-family:Impact;font-size:14px"> ⑥ RandomForestClassifier</a></li> </ul>
      <li style = "color:darkgray;font-size:15px"> <a href = "#48" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Wrong Predictions </a> </li>
        <li style = "color:darkgray;font-size:15px"> <a href = "#49" style = "color:black;font-weight:bold;font-family:Comic Sans MS"> Model Result </a> </li>
</ul> 


"""
"""
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS">📖 Import Library</h2>
"""
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import seaborn as sns
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn.metrics import plot_confusion_matrix
from scipy.stats import norm, boxcox
from collections import Counter
from scipy import stats

# warning library
import warnings
warnings.filterwarnings("ignore")

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
"""
<a id ='1' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS">Load and Check Data</h2>
"""
data = pd.read_csv("/kaggle/input/red-wine-quality-cortez-et-al-2009/winequality-red.csv")
data.head()
# the columns 
data.columns
print("Data Shape --> ",data.shape)
data.describe()
"""
<a id ='2' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Variable Description</h2>

<ol>
    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>fixed acidity : </strong> most acids involved with wine or fixed or nonvolatile (do not evaporate readily) </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>volatile acidity : </strong> the amount of acetic acid in wine, which at too high of levels can lead to an unpleasant, vinegar taste</p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>citric acid : </strong> found in small quantities, citric acid can add 'freshness' and flavor to wines</p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>residual sugar : </strong>the amount of sugar remaining after fermentation stops, it's rare to find wines with less than 1 gram/liter and </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>chlorides : </strong>  the amount of salt in the wine </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>free sulfur dioxide : </strong> the free form of SO2 exists in equilibrium between molecular SO2 (as a dissolved gas) and bisulfite ion; it prevents </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>total sulfur dioxide : </strong> amount of free and bound forms of S02; in low concentrations, SO2 is mostly undetectable in wine, but at free SO2 </p> </li>
    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>density : </strong>the density of water is close to that of water depending on the percent alcohol and sugar content </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>ph : </strong>  describes how acidic or basic a wine is on a scale from 0 (very acidic) to 14 (very basic); most wines are between 3-4 on the </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>sulphates : </strong> a wine additive which can contribute to sulfur dioxide gas (S02) levels, wich acts as an antimicrobial and </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>alcohol sulfur dioxide : </strong> the percent alcohol content of the wine </p> </li>
            <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS" > <strong>quality : </strong> output variable (based on sensory data, score between 0 and 10) </p> </li>
</ol>
"""
print("Data Info")
data.info()
"""
<a id ='3' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Basic Data Analysis</h2>

<p style = "color:darkred;font-family:Comic Sans MS;font-weight:bold" >In this section, we will look at how properties have an effect on the target variable.</p> 

<ul>
    <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > fixed acidity - <strong>  quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > volatile acidity -<strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > citric acid - <strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > residual sugar - <strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > chlorides - <strong>  quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > free sulfur dioxide -<strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > total sulfur dioxide - <strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > density - <strong> quality </strong> </p> </li>  
            <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > pH - <strong>  quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > sulphates -<strong> quality </strong> </p> </li>
        <li style = "color:darkgreen"> <p style = "color:black;font-family:Comic Sans MS" > alcohol - <strong> quality </strong> </p> </li>
</ul>
"""
"""
<a id ='4' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">fixed acidity - quality </h4>
"""
data[["fixed acidity","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >We can say that the increase in fixed acidity positively affects the given vote.but it is difficult to make a full conclusion at this stage. </p> </li>
</ul>
"""
"""
<a id ='5' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">volatile acidity - quality </h4>
"""
data[["volatile acidity","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >here we can make a more precise sentence according to the comment we made above. The decrease in volatile acidity affects the votes positively.</p> </li>
</ul>
"""
"""
<a id ='6' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">cidric acid - quality </h4>
"""
data[["citric acid","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >From here, we see that the increase in citric acid positively affected the votes.</p> </li>
</ul>
"""
"""
<a id ='7' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">residual sugar - quality </h4>
"""
data[["residual sugar","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >It seems difficult to make an inference about residual sugar from here.</p> </li>
</ul>
"""
"""
<a id ='8' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">chlorides - quality </h4>
"""
data[["chlorides","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >The decrease in chlorides positively affects the votes cast.</p> </li>
</ul>
"""
"""
<a id ='9' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">free sulfur dioxide - quality </h4>
"""
data[["free sulfur dioxide","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >It doesn't seem easy to comment on free sulfur dioxide either. The 13, 14 levels seem to have been voted well.</p> </li>
</ul>
"""
"""
<a id ='10' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">total sulfur dioxide - quality </h4>
"""
data[["total sulfur dioxide","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >It doesn't make sense to comment on total sulfur dioxide. It changed according to the votes. There is no order.</p> </li>
</ul>
"""
"""
<a id ='11' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">density - quality </h4>
"""
data[["density","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >The intensity is almost the same in all votes, but there is only a slight decrease. Density drop seems to have a positive effect on the votes.</p> </li>
</ul>
"""
"""
<a id ='12' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">pH - quality </h4>
"""
data[["pH","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >We can say that the decrease in pH affects the votes positively.</p> </li>
</ul>
"""
"""
<a id ='13' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">sulphates - quality</h4>
"""
data[["sulphates","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >It is clear from here that the increase in sulphates has a positive effect.</p> </li>
</ul>
"""
"""
<a id ='14' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">alcohol - quality</h4>
"""
data[["alcohol","quality"]].groupby(["quality"], as_index = False).mean().sort_values(by = "quality").style.background_gradient("Reds")
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print;font-weight:bold" > <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >In general, it can be said that the increase in alcohol ratio affects the votes well.</p> </li>
</ul>
"""
"""
<a id ='15' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Missing Value</h2>

<p style = "color:darkred;font-family:Comic Sans MS;font-weight:bold" >We will take a look at if there is any missing data in our data. If there are, we will try to eliminate them.</p> 
"""
print("Do we have data with null in columns?")
data.columns[data.isnull().any()]
data.isnull().sum()
"""
<ul>
    <li style = "color:darkred;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >we see that there is no missing data in the data.</p> </li>
</ul>
"""
"""
<a id ='16' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Visualization</h2>

<p style = "color:darkgreen;font-family:Comic Sans MS;font-weight:bold" >In this section, we will visualize our features one by one and make examinations on graphics.</p> 

<ul>
    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > fixed acidity </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > volatile acidity </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >citric acid </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > residual sugar </p> </li>
            <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >chlorides </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >free sulfur dioxide </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >total sulfur dioxide </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >density </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >pH </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >sulphates </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >alcohol </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >quality </p> </li>
</ul> 
"""
"""
<a id ='17' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">fixed acidity</h4>
"""
quality = [3,4,5,6,7,8]
fixedAcidityMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["fixed acidity"].mean()
    fixedAcidityMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["fixed acidity"], color="orange")
plt.xlabel("fixed acidity")
plt.ylabel("Frequency")
plt.title("fixed acidity histogram", color = "black", fontweight='bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["fixed acidity"], fit=norm, color="orange")
plt.title("fixed acidity Distplot", color = "black", fontweight='bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = fixedAcidityMean, palette="YlOrBr")
plt.title("the average value of fixed acidity by quality", color = "black", fontweight='bold', fontsize = 11)
plt.xlabel("fixed acidity")
plt.ylabel("Frequency")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["fixed acidity"], palette='YlOrBr')
plt.title("fixed acidity & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:orange;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >Fixed acidity may not have much effect on splitting votes.</p> </li>
        <li style = "color:orange;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >On the 2nd graph, we see that there is a skewness to the right. We need to fix this.</p> </li>
</ul>
"""
"""
<a id ='18' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">volatile acidity</h4>
"""
volatileAcidityMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["volatile acidity"].mean()
    volatileAcidityMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["volatile acidity"], color="purple")
plt.xlabel("volatile acidity")
plt.ylabel("Frequency")
plt.title("volatile acidity histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["volatile acidity"], fit=norm, color="purple")
plt.title("volatile acidity Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = volatileAcidityMean, palette= "rocket")
plt.title("the average value of volatile acidity by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("volatile acidity mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["volatile acidity"], palette='rocket')
plt.title("volatile acidity & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:purple;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >The decrease in volatile acidity seems to affect the votes positively.</p> </li>
        <li style = "color:purple;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine the second graph, we see that the distribution is good.</p> </li>
</ul>
"""
"""
<a id ='19' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">citric acid</h4>
"""
citricAcidMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["citric acid"].mean()
    citricAcidMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["citric acid"], color="lightgreen")
plt.xlabel("citric acid")
plt.ylabel("Frequency")
plt.title("citric acid histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["citric acid"], fit=norm, color="green")
plt.title("citric acid Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = citricAcidMean, palette= "Greens")
plt.title("the average value of citric acid by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("citric acid mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["citric acid"], palette='Greens')
plt.title("citric acid & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:darkgreen;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We can say that the increase in citric acid affects the votes positively.</p> </li>
</ul>
"""
"""
<a id ='21' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">residual sugar</h4>
"""
residualSugarMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["residual sugar"].mean()
    residualSugarMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["residual sugar"], color="blue")
plt.xlabel("residual sugar")
plt.ylabel("Frequency")
plt.title("residual sugar histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["residual sugar"], fit=norm, color="blue")
plt.title("residual sugar Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = residualSugarMean, palette= "crest")
plt.title("the average value of residual sugar by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("residual sugar mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["residual sugar"], palette='crest')
plt.title("residual sugar & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:blue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >The estimate of residual sugar does not seem to have much effect.</p> </li>
        <li style = "color:blue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that there is a skewness towards the right according to the normal distribution.</p> </li>
</ul>
"""
"""
<a id ='22' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">chlorides</h4>
"""
chloridesMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["chlorides"].mean()
    chloridesMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["chlorides"], color="brown")
plt.xlabel("chlorides")
plt.ylabel("Frequency")
plt.title("chlorides histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["chlorides"], fit=norm, color="brown")
plt.title("chlorides Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = chloridesMean, palette= "Set2")
plt.title("the average value of chlorides by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("chlorides mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["chlorides"], palette='Set2')
plt.title("chlorides & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:yellow;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that the decrease in chlorides has a positive effect on the votes..</p> </li>
        <li style = "color:yellow;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >If we look at the fourth graph, we see that there are too many outliers. We need to fix these. Otherwise, they will negatively affect our model.</p> </li>
</ul>
"""
"""
<a id ='23' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">free sulfur dioxide</h4>
"""
freeSulfurDioxideMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["free sulfur dioxide"].mean()
    freeSulfurDioxideMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["free sulfur dioxide"], color="darkred")
plt.xlabel("free sulfur dioxide")
plt.ylabel("Frequency")
plt.title("free sulfur dioxide histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["free sulfur dioxide"], fit=norm, color="darkred")
plt.title("free sulfur dioxide Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = freeSulfurDioxideMean, palette= "OrRd")
plt.title("the average value of free sulfur dioxide by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("free sulfur dioxide mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["free sulfur dioxide"], palette='OrRd')
plt.title("free sulfur dioxide & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:brown;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine the gariks here, we see that the graph is tailing to the right, we will correct this below.</p> </li>
        <li style = "color:brown;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >If we look at the fourth graph, we see that there are too many outliers. We need to fix these. Otherwise, they will negatively affect our model.</p> </li>
</ul>
"""
"""
<a id ='24' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">total sulfur dioxide</h4>
"""
totalSulfurDioxideMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["total sulfur dioxide"].mean()
    totalSulfurDioxideMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["total sulfur dioxide"], color="#F1E68C")
plt.xlabel("total sulfur dioxide")
plt.ylabel("Frequency")
plt.title("total sulfur dioxide histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["total sulfur dioxide"], fit=norm, color="#F5E68C")
plt.title("total sulfur dioxide Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = totalSulfurDioxideMean, palette= "BrBG")
plt.title("the average value of total sulfur dioxide by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("total sulfur dioxide mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["total sulfur dioxide"], palette='BrBG')
plt.title("total sulfur dioxide & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:#F1E68C;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine these graphs, we do not see that they have a regular effect on the target variable. It is not easy to draw conclusions.</p> </li>
        <li style = "color:#F1E68C;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >Here we see a skewness to the right.</p> </li>
</ul>
"""
"""
<a id ='25' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">density</h4>
"""
densityMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["density"].mean()
    densityMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["density"], color="lightblue")
plt.xlabel("density")
plt.ylabel("Frequency")
plt.title("density histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["density"], fit=norm)
plt.title("density Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = densityMean, palette= "ocean")
plt.title("the average value of density by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("density mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["density"], palette='ocean')
plt.title("density & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:lightblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >It seems quite difficult to predict the effect on the target variable.</p> </li>
        <li style = "color:lightblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine the scatterplot, we see that it has a normal distribution.</p> </li>
</ul>
"""
"""
<a id ='26' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">pH</h4>
"""
pHMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["pH"].mean()
    pHMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["pH"], color="#00FF00")
plt.xlabel("pH")
plt.ylabel("Frequency")
plt.title("pH histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["pH"], fit=norm, color = "#00FF00")
plt.title("pH Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = pHMean, palette= "hsv")
plt.title("the average value of pH by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("pH mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["pH"], palette='hsv')
plt.title("pH & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:#00FF00;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that the decrease in pH value has a positive effect on the votes.</p> </li>
        <li style = "color:#00FF00;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that the scatterplot has normal, outlier values. We need to identify and remove outliers.</p> </li>
</ul>
"""
"""
<a id ='27' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">sulphates</h4>
"""
sulphatesMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["sulphates"].mean()
    sulphatesMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["sulphates"], color="plum")
plt.xlabel("sulphates")
plt.ylabel("Frequency")
plt.title("sulphates histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["sulphates"], fit=norm, color="plum")
plt.title("sulphates Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = sulphatesMean, palette= "twilight")
plt.title("the average value of sulphates by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("sulphates mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["sulphates"], palette='twilight')
plt.title("sulphates & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:plum;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that the higher the value of the sulphates, the more positive the votes are.</p> </li>
        <li style = "color:plum;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We have so many outliers here that we need to remove them.</p> </li>
</ul>
"""
"""
<a id ='28' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">alcohol</h4>
"""
alcoholMean = []

for each in quality:
    x = data[data["quality"] == each]
    mean = x["alcohol"].mean()
    alcoholMean.append(mean)


plt.figure(figsize=(13,10))
plt.subplot(2,2,1)
plt.hist(data["alcohol"], color="#DAA520")
plt.xlabel("alcohol")
plt.ylabel("Frequency")
plt.title("alcohol histogram", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,2)
sns.distplot(data["alcohol"], fit=norm, color="#DAA520")
plt.title("alcohol Distplot", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(2,2,3)
sns.barplot(x = quality, y = alcoholMean, palette= "CMRmap")
plt.title("the average value of alcohol by quality", color = "black", fontweight= 'bold', fontsize = 11)
plt.xlabel("quality")
plt.ylabel("alcohol mean")
plt.subplot(2,2,4)
sns.boxplot(data['quality'], data["alcohol"], palette='CMRmap')
plt.title("alcohol & quality", color = "black", fontweight= 'bold', fontsize = 11)

plt.show()
"""
<ul>
    <li style = "color:#DAA520;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When the graph is examined in general, it can be said that the increase in alcohol has a positive effect on the votes.</p> </li>
        <li style = "color:#DAA520;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine the 2nd graph, we see that there is skewness. We will fix this.</p> </li>
</ul>
"""
"""
<a id ='29' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">quality</h4>
"""
Number = data.quality.value_counts().values
Label = data.quality.value_counts().index
circle = plt.Circle((0,0),0.2,color = "white")
explodeTuple = (0.0, 0.0, 0.0, 0.3, 0.5, 0.5)

plt.figure(figsize=(13,5))
plt.subplot(1,2,1)
sns.countplot(data["quality"])
plt.xlabel("quality")
plt.title("quality distribution", color = "black", fontweight= 'bold', fontsize = 11)
plt.subplot(1,2,2)
plt.pie(Number, labels = Label,autopct='%1.2f%%', explode=explodeTuple,startangle=60)
p = plt.gcf()
p.gca().add_artist(circle) 
plt.title("quality distribution", color = "black", fontweight= 'bold', fontsize = 11)
plt.legend()


plt.show()
"""
<ul>
    <li style = "color:red;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >Here we see the distribution of the votes.</p> </li>
</ul>
"""
"""
<a id ='30' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Skewness Correction</h2>

<p style = "color:darkred;font-family:Comic Sans MS;font-weight:bold" >In this section, we will try to correct the skewness in some features of our data. We will do this by seeing them through graphs.</p>

<ul>
    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > fixed acidity </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > residual sugar </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >free sulfur dioxide </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >total sulfur dioxide </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >sulphates </p> </li>
            
</ul> 
"""
"""
<a id ='31' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">fixed acidity</h4>
"""
(mu, sigma) = norm.fit(data["fixed acidity"])
print("mu {} : {}, sigma {} : {}".format("fixed acidity", mu, "fixed acidity", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["fixed acidity"], fit=norm, color="orange")
plt.title("fixed acidity Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["fixed acidity"], plot = plt)
plt.show()
"""
<ul>
    <li style = "color:red;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We were down above. On the second graph, we see that there is skewness.</p> </li>
</ul>
"""
data["fixed acidity"], lam_fixed_acidity = boxcox(data["fixed acidity"])
"""
<ul>
    <li style = "color:red;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We will try to eliminate the skewness here by using box cox.</p> </li>
</ul>
"""
(mu, sigma) = norm.fit(data["fixed acidity"])
print("mu {} : {}, sigma {} : {}".format("fixed acidity", mu, "fixed acidity", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["fixed acidity"], fit=norm, color="orange")
plt.title("fixed acidity Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["fixed acidity"], plot = plt)
plt.show()
"""
<ul>
    <li style = "color:red;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >When we examine the previous and current graphics, we see that we have eliminated the skewness at a good level.</p> </li>
</ul>
"""
"""
<a id ='32' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">residual sugar</h4>
"""
(mu, sigma) = norm.fit(data["residual sugar"])
print("mu {} : {}, sigma {} : {}".format("residual sugar", mu, "residual sugar", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["residual sugar"], fit=norm, color="orange")
plt.title("residual sugar Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["residual sugar"], plot = plt)
plt.show()
data["residual sugar"], lam_fixed_acidity = boxcox(data["residual sugar"])
(mu, sigma) = norm.fit(data["residual sugar"])
print("mu {} : {}, sigma {} : {}".format("residual sugar", mu, "residual sugar", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["residual sugar"], fit=norm, color="orange")
plt.title("residual sugar Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["residual sugar"], plot = plt)
plt.show()
"""
<a id ='33' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">free sulfur dioxide</h4>
"""
(mu, sigma) = norm.fit(data["free sulfur dioxide"])
print("mu {} : {}, sigma {} : {}".format("free sulfur dioxide", mu, "free sulfur dioxide", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["free sulfur dioxide"], fit=norm, color="orange")
plt.title("free sulfur dioxide Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["free sulfur dioxide"], plot = plt)
plt.show()
data["free sulfur dioxide"], lam_fixed_acidity = boxcox(data["free sulfur dioxide"])
(mu, sigma) = norm.fit(data["free sulfur dioxide"])
print("mu {} : {}, sigma {} : {}".format("free sulfur dioxide", mu, "free sulfur dioxide", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["free sulfur dioxide"], fit=norm, color="orange")
plt.title("free sulfur dioxide Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["free sulfur dioxide"], plot = plt)
plt.show()
"""
<a id ='34' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">total sulfur dioxide</h4>
"""
(mu, sigma) = norm.fit(data["total sulfur dioxide"])
print("mu {} : {}, sigma {} : {}".format("total sulfur dioxide", mu, "total sulfur dioxide", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["total sulfur dioxide"], fit=norm, color="orange")
plt.title("total sulfur dioxide Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["total sulfur dioxide"], plot = plt)
plt.show()
data["total sulfur dioxide"], lam_fixed_acidity = boxcox(data["total sulfur dioxide"])
(mu, sigma) = norm.fit(data["total sulfur dioxide"])
print("mu {} : {}, sigma {} : {}".format("total sulfur dioxide", mu, "total sulfur dioxide", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["total sulfur dioxide"], fit=norm, color="orange")
plt.title("total sulfur dioxide Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["total sulfur dioxide"], plot = plt)
plt.show()
"""
<a id ='35' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">alcohol</h4>
"""
(mu, sigma) = norm.fit(data["alcohol"])
print("mu {} : {}, sigma {} : {}".format("alcohol", mu, "alcohol", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["alcohol"], fit=norm, color="orange")
plt.title("alcohol Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["alcohol"], plot = plt)
plt.show()
data["alcohol"], lam_fixed_acidity = boxcox(data["alcohol"])
(mu, sigma) = norm.fit(data["alcohol"])
print("mu {} : {}, sigma {} : {}".format("alcohol", mu, "alcohol", sigma))
plt.figure(figsize=(10,4))
plt.subplot(1,2,1)
sns.distplot(data["alcohol"], fit=norm, color="orange")
plt.title("alcohol Distplot", color = "darkred")
plt.subplot(1,2,2)
stats.probplot(data["alcohol"], plot = plt)
plt.show()
"""
<a id ='36' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Outlier Detection</h2>

<p style = "color:darkred;font-family:Comic Sans MS;font-weight:bold" >We detect outliers in our data. and we will extract them from the data.</p>
"""
def detect_outliers(df,features):
    outlier_indices = []
    
    for c in features:
        # 1st quartile
        Q1 = np.percentile(df[c],25)
        # 3st quartile
        Q3 = np.percentile(df[c],75)
        # IQR
        IQR = Q3 - Q1
        # Outlier Step
        outlier_step = IQR * 1.5
        # detect outlier and their indeces
        outlier_list_col = df[(df[c] < Q1 - outlier_step) | (df[c] > Q3 + outlier_step)].index
        # store indeces 
        outlier_indices.extend(outlier_list_col)
        
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list(i for i, v in outlier_indices.items() if v > 1.5) 
    
    return multiple_outliers
print("number of outliers detected --> ",len(data.loc[detect_outliers(data,data.columns[:-1])]))
data.loc[detect_outliers(data,data.columns[:-1])]
data = data.drop(detect_outliers(data,data.columns[:-1]),axis = 0).reset_index(drop = True)
"""
<ul>
    <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We remove the detected outliers from our data.</p> </li>
</ul>
"""
"""
<a id ='37' ></a>
<h2 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Modeling</h2>

<p style = "color:darkblue;font-family:Comic Sans MS;font-weight:bold" >Now our data is ready for the model. Now we will create our models.</p>

<ul>
    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > Import Model Library </p> </li>
        <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" > Train - Test Split </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >Smote </p> </li>
                <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >StandardScaler </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >KNeighborsClassifier </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >GradientBoostingClassifier </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >SVC </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >XGBClassifier </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >KNeighborsClassifier </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >CatBoostClassifier </p> </li>
                    <li style = "color:darkred"> <p style = "color:black;font-family:Comic Sans MS;font-weight:bold" >RandomForestClassifier </p> </li>
            
</ul> 
"""
"""
<a id ='38' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Import Model Library</h4>
"""
from sklearn.model_selection import train_test_split, StratifiedKFold, GridSearchCV, RandomizedSearchCV
from sklearn.svm import SVC
from scipy.stats import uniform as sp_randFloat
from scipy.stats import randint as sp_randInt  
from xgboost import XGBClassifier
from catboost import CatBoostClassifier
from sklearn.ensemble import RandomForestClassifier, VotingClassifier, GradientBoostingClassifier
from sklearn.preprocessing import StandardScaler
from imblearn.over_sampling import SMOTE
from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
from sklearn.neighbors import KNeighborsClassifier
import collections
bins = (2, 6.5, 8)
labels = [0, 1]
data['quality'] = pd.cut(x = data['quality'], bins = bins, labels = labels)
"""
<ul>
    <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We make the variable quality into 2 variables, 0 and 1.</p> </li>
</ul>
"""
data['quality'].value_counts()
"""
<ul>
    <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >0 --> 1323</p> </li>
        <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >1 --> 208</p> </li>
        <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We see that there is a big difference between the 2 values. So we see that it is unbalanced. We will fix this.</p> </li>
</ul>
"""
"""
<a id ='39' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Train - Test Split</h4>
"""
y = data.quality
x = data.drop(["quality"], axis = 1)
test_size = 0.20
X_train, X_test, Y_train, Y_test = train_test_split(x, y, test_size = test_size, random_state = 206)
"""
<a id ='40' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Smote</h4>

<p style = "color:darkgreen;font-family:Comic Sans MS;font-weight:bold" >We saw above that our data is an unbalanced data. We fix this with the help of smote.</p>
"""
sm = SMOTE(random_state=14)
X_train_sm, y_train_sm = sm.fit_resample(X_train, Y_train)
print("Before smote --> ", collections.Counter(Y_train))
print("After smote --> ", collections.Counter(y_train_sm))
"""
<a id ='41' ></a>
<h4 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">StandardScaler</h4>
"""
scaler = StandardScaler()
X_train_sm = scaler.fit_transform(X_train_sm) 
X_test = scaler.transform(X_test) 
results = []
"""
<ul>
    <li style = "color:darkblue;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >To record our model achievements. We are making a list.</p> </li>
</ul>
"""
"""
<a id ='42' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">KNeighborsClassifier</h3>
"""
knn = KNeighborsClassifier(n_neighbors = 2)
knn.fit(X_train_sm, y_train_sm)
y_pred = knn.predict(X_test)
cm = confusion_matrix(Y_test, y_pred)

acc = accuracy_score(Y_test, y_pred)
score = knn.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("KNeighborsClassifier Acc : ", acc)

plot_confusion_matrix(knn, X_test, Y_test, cmap= "Greens")  
plt.show()
"""
<ul>
    <li style = "color:green;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We saw cm matrix. Let's take a look at the bidet classification report</p> </li>
</ul>
"""
print(" \t \t  KNN Classification Report")
print(classification_report(Y_test, y_pred))
"""
<a id ='43' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">GradientBoostingClassifier</h3>
"""
gbc = GradientBoostingClassifier(max_depth= 6, random_state=2)
gbc.fit(X_train_sm, y_train_sm)
y_pred_gbc = gbc.predict(X_test)
cm_aaa = confusion_matrix(Y_test, y_pred_gbc)
acc = accuracy_score(Y_test, y_pred_gbc)
score = gbc.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("GradientBoostingClassifier Acc : ", acc)

plot_confusion_matrix(gbc, X_test, Y_test, cmap= "binary")  
plt.show()
print(" \t \t  GradientBoostingClassifier Classification Report")
print(classification_report(Y_test, y_pred_gbc))
"""
<a id ='44' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">SVC</h3>
"""
svc = SVC()
svc.fit(X_train_sm, y_train_sm)
pred_svc = svc.predict(X_test)

cm_svc = confusion_matrix(Y_test, pred_svc)
acc = accuracy_score(Y_test, pred_svc)
score = svc.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("SVC Acc : ", acc)

plot_confusion_matrix(svc, X_test, Y_test, cmap= "Reds")  
plt.show()
print(" \t \t  SVC Classification Report")
print(classification_report(Y_test, pred_svc))
"""
<a id ='45' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">XGBClassifier</h3>
"""
xgb = XGBClassifier()
xgb.fit(X_train_sm, y_train_sm)
pred_xgb = xgb.predict(X_test)

cm_aaa = confusion_matrix(Y_test, pred_xgb)
acc = accuracy_score(Y_test, pred_xgb)
score = xgb.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("XGBClassifier Acc : ", acc)

plot_confusion_matrix(xgb, X_test, Y_test, cmap= "copper")  
plt.show()
print(" \t \t  XGBClassifier Classification Report")
print(classification_report(Y_test, pred_xgb))
"""
<a id ='46' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">CatBoostClassifier</h3>
"""
parameters = {  
                'depth'         : sp_randInt(4, 10),
                'learning_rate' : sp_randFloat(),
                'iterations'    : sp_randInt(10, 100)
             }
cat = CatBoostClassifier(iterations=1000, verbose = False, depth=8)
randm = RandomizedSearchCV(estimator=cat, param_distributions = parameters, 
                               cv = 2, n_iter = 10, n_jobs=-1)
randm.fit(X_train_sm, y_train_sm)

pred_cat = randm.predict(X_test)

cm_cat = confusion_matrix(Y_test, pred_cat)
acc = accuracy_score(Y_test, pred_cat)
score = randm.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("Basic KNN Acc : ", acc)

plot_confusion_matrix(randm, X_test, Y_test, cmap= "hot")  
plt.show()
print(" \t \t  CatBoostClassifier Classification Report")
print(classification_report(Y_test, pred_cat))
"""
<a id ='47' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">RandomForestClassifier</h3>
"""
rf = RandomForestClassifier(max_depth=18, random_state=44, bootstrap = False)
rf.fit(X_train_sm, y_train_sm)
y_pred_rf = rf.predict(X_test)
cm = confusion_matrix(Y_test, y_pred_rf)

acc = accuracy_score(Y_test, y_pred_rf)
score = rf.score(X_test, Y_test)
results.append(acc)

print("Score : ", score)
print("RandomForestClassifier Acc : ", acc)

plot_confusion_matrix(rf, X_test, Y_test, cmap= "pink")  
plt.show()
print(" \t \t  RandomForestClassifier Classification Report")
print(classification_report(Y_test, y_pred_rf))
"""
<ul>
    <li style = "color:green;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We got the best result in Random Forest. Let's take a look at the mistakes we made.</p> </li>
</ul>
"""
"""
<a id ='48' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Wrong Predictions</h3>
"""
test_data = pd.DataFrame()
test_data["citric acid"] = data["volatile acidity"][:307]
test_data["fixed acidity"] = data["fixed acidity"][:307]
test_data["y_pred_rf"] = y_pred_rf
test_data["Y_test"] = Y_test.values

plt.figure(figsize=(12,6))
sns.scatterplot(x="citric acid", y="fixed acidity", hue="Y_test", data=test_data, palette=["Black","darkgreen"])
plt.title("Classifications We Made Wrong", fontsize = 13, fontweight = "bold", color = "darkred")

diff = np.where(y_pred_rf!=Y_test)[0]
plt.scatter(test_data.iloc[diff,0],test_data.iloc[diff,1],label = "Wrong Classified", marker="x",alpha = 0.7, color = "Red",s = 300)
plt.legend()
plt.show()
"""
<ul>
    <li style = "color:green;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We also took a look at the guesses we made wrong. (For Random Forest)</p> </li>
</ul>
"""
"""
<a id ='49' ></a>
<h3 style = "background:black;color:white;border:0;font-family:Comic Sans MS;font-weight:bold">Model Result</h3>
"""
df_result = pd.DataFrame({"Score":results, "ML Models":["KNN","GradientBoostingClassifier",
             "SVC","XGBClassifier","CatBoostClassifier","RandomForestClassifier"]})
df_result.style.background_gradient("Greens")
g = sns.barplot("Score", "ML Models", data = df_result, palette='BrBG')
g.set_xlabel("Score")
g.set_title("Classifier Model Results", color = "Black")
plt.show()
"""
<ul>
    <li style = "color:green;font-family:Segoe Print" > <p style = "color:black;font-family:Comic Sans MS" >We achieved the highest success in Random Forest with 0.957.</p> </li>
</ul>
"""
"""
<p style = "text-shadow: 12px 12px 2px #333;color:brown;font-family:Segoe Print;font-weight:bold" > YES, WE HAVE COME TO AN END. THANK YOU</p>
"""