<jupyter_start><jupyter_text>Importing the Dependencies<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score<jupyter_output><empty_output><jupyter_text>Data Collection<jupyter_code># loading the dataset to a Pandas DataFrame
wine_dataset = pd.read_csv('/content/winequality-red.csv')
# number of rows & columns in the dataset
wine_dataset.shape
# first 5 rows of the dataset
wine_dataset.head()
# checking for missing values
wine_dataset.isnull().sum()<jupyter_output><empty_output><jupyter_text>Data Analysis and Visulaization<jupyter_code># statistical measures of the dataset
wine_dataset.describe()
# number of values for each quality
sns.catplot(x='quality', data = wine_dataset, kind = 'count')
# volatile acidity vs Quality
plot = plt.figure(figsize=(5,5))
sns.barplot(x='quality', y = 'volatile acidity', data = wine_dataset)
# citric acid vs Quality
plot = plt.figure(figsize=(5,5))
sns.barplot(x='quality', y = 'citric acid', data = wine_dataset)<jupyter_output><empty_output><jupyter_text>Correlation 1. Positive Correlation2. Negative Correlation<jupyter_code>correlation = wine_dataset.corr()
# constructing a heatmap to understand the correlation between the columns
plt.figure(figsize=(10,10))
sns.heatmap(correlation, cbar=True, square=True, fmt = '.1f', annot = True, annot_kws={'size':8}, cmap = 'Blues')<jupyter_output><empty_output><jupyter_text>Data Preprocessing<jupyter_code># separate the data and Label
X = wine_dataset.drop('quality',axis=1)
print(X)<jupyter_output>fixed acidity  volatile acidity  citric acid  ...    pH  sulphates  alcohol
0               7.4             0.700         0.00  ...  3.51       0.56      9.4
1               7.8             0.880         0.00  ...  3.20       0.68      9.8
2               7.8             0.760         0.04  ...  3.26       0.65      9.8
3              11.2             0.280         0.56  ...  3.16       0.58      9.8
4               7.4             0.700         0.00  ...  3.51       0.56      9.4
...             ...               ...          ...  ...   ...        ...      ...
1594            6.2             0.600         0.08  ...  3.45       0.58     10.5
1595            5.9             0.550         0.10  ...  3.52       0.76     11.2
1596            6.3             0.510         0.13  ...  3.42       0.75     11.0
1597            5.9             0.645         0.12  ...  3.57       0.71     10.2
1598            6.0             0.310         0.47  ...  3.39       0.66     11.0

[1599 rows x 11[...]<jupyter_text>Label Binarizaton<jupyter_code>Y = wine_dataset['quality'].apply(lambda y_value: 1 if y_value>=7 else 0)
print(Y)<jupyter_output>0       0
1       0
2       0
3       0
4       0
       ..
1594    0
1595    0
1596    0
1597    0
1598    0
Name: quality, Length: 1599, dtype: int64<jupyter_text>Train & Test Split<jupyter_code>X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=3)
print(Y.shape, Y_train.shape, Y_test.shape)<jupyter_output>(1599,) (1279,) (320,)<jupyter_text>Model Training:Random Forest Classifier<jupyter_code>model = RandomForestClassifier()
model.fit(X_train, Y_train)<jupyter_output><empty_output><jupyter_text>Model Evaluation Accuracy Score<jupyter_code># accuracy on test data
X_test_prediction = model.predict(X_test)
test_data_accuracy = accuracy_score(X_test_prediction, Y_test)
print('Accuracy : ', test_data_accuracy)<jupyter_output>Accuracy :  0.925<jupyter_text>Building a Predictive System<jupyter_code>input_data = (7.5,0.5,0.36,6.1,0.071,17.0,102.0,0.9978,3.35,0.8,10.5)

# changing the input data to a numpy array
input_data_as_numpy_array = np.asarray(input_data)

# reshape the data as we are predicting the label for only one instance
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)

prediction = model.predict(input_data_reshaped)
print(prediction)

if (prediction[0]==1):
  print('Good Quality Wine')
else:
  print('Bad Quality Wine')<jupyter_output>[0]
Bad Quality Wine
{'fraction_non_alphanumeric': 0.11212484993997598, 'fraction_numerical': 0.07707082833133254, 'mean_word_length': 2.6802120141342756, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '124264', 'license': 'MIT', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1454, 'n_words': 335, 'path': 'Project_7_Wine_Quality_Prediction.ipynb', 'repo_name': 'jaweherbensalah/Advanced-Deep-Learning-with-Keras', 'size': '4165'}