<jupyter_start><jupyter_text>Case-study on real Time dataset using Artificial Neural Networks 2 We are going to do a case study on case study on real time dataset using Arificial Neural Network(ANN).The dataset in which we going to do the ANN is related to the red variants of the Portuguese "Vinho Verde" wine whether a red wine is of good quality or not according to its chemical properties.<jupyter_code>#Import the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sb
#Import the dataset
data=pd.read_csv('C:/Users/aksha/Desktop/ai/datasets/winequal/redwinequal.csv')
data.head()
data.shape<jupyter_output><empty_output><jupyter_text>This dataset contains 1599 rows and 12 columns. The  columns are namely the different chemical properties in a wine that helps in maintaining the quality of a wine.1) fixed acidity: most acids involved with wine or fixed or nonvolatile (do not evaporate readily).2) volatile acidity: the amount of acetic acid in wine, which at too high of levels can lead to an unpleasant, vinegar taste.3) citric acid: found in small quantities, citric acid can add 'freshness' and flavor to wines.4) residual sugar: the amount of sugar remaining after fermentation stops, it's rare to find wines with less than 1 gram/liter and wines with greater than 45 grams/liter are considered sweet.5) chlorides: he amount of salt in the wine.6) free sulfur dioxide: the free form of SO2 exists in equilibrium between molecular SO2 (as a dissolved gas) and bisulfite ion; it prevents microbial growth and the oxidation of wine.7) total sulfur dioxide: amount of free and bound forms of S02; in low concentrations, SO2 is mostly undetectable in wine, but at free SO2 concentrations over 50 ppm, SO2 becomes evident in the nose and taste of wine.8) density: the density of water is close to that of water depending on the percent alcohol and sugar content.9) pH: 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 pH scale.10) sulphates: a wine additive which can contribute to sulfur dioxide gas (S02) levels, wich acts as an antimicrobial and antioxidant.11) alcohol: the percent alcohol content of the wine.12) quality: output variable (based on sensory data, score between 0 and 10).7 or higher getting classified as 'good' and the remainder as 'not good'<jupyter_code>sb.heatmap(data.isnull())<jupyter_output><empty_output><jupyter_text>the above data shows that there is no null value.<jupyter_code>sb.countplot(data['quality'])<jupyter_output><empty_output><jupyter_text>the above data contains highest number of results that lead to 5 followed by 6.<jupyter_code>for index, row in data.iterrows():
    A=row['quality']
    if(A>=7):
        data.loc[index,'Good'] = 1
    else:
        data.loc[index,'Good'] = 0
data
data.drop('quality',axis=1,inplace=True)
data
x=data.iloc[:,0:11].values
y=data.iloc[:,11].values
x
y
#Splitting the dataset into train and test set
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)
#Feature scaling
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x_train=sc.fit_transform(x_train)
x_test=sc.transform(x_test)
x_test
#import the keras libraries
import keras
from keras.models import Sequential
from keras.layers import Dense
#Initialising the ANN
classifier=Sequential()
#Adding the input and first hidden layer
classifier.add(Dense(units=6,kernel_initializer='uniform',activation='relu',input_dim=11))
#Adding the second hidden layer
classifier.add(Dense(units=6,kernel_initializer='uniform',activation='relu'))
#Adding the output layer
classifier.add(Dense(units=1,kernel_initializer='uniform',activation='sigmoid'))
#Compiling the ANN
classifier.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
#Fitting the ANN to the training set
classifier.fit(x_train,y_train,batch_size=10,epochs=100)
y_pred=classifier.predict(x_test)
y_pred=(y_pred>0.5)
#Accuracy score
from sklearn.metrics import accuracy_score
print('accuracy score:',accuracy_score(y_test,y_pred))
y_pred
#confusion matrix and classification report
from sklearn.metrics import confusion_matrix
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
print('confusion_matrix:',confusion_matrix(y_test,y_pred),sep='\n')
print('accuracy score:',accuracy_score(y_test,y_pred))
print(classification_report(y_test,y_pred))<jupyter_output>precision    recall  f1-score   support

         0.0       0.95      0.92      0.93       290
         1.0       0.39      0.50      0.44        30

   micro avg       0.88      0.88      0.88       320
   macro avg       0.67      0.71      0.69       320
weighted avg       0.90      0.88      0.89       320<jupyter_text>ROC<jupyter_code>#Importing ROC-AUC packages
from sklearn.metrics import roc_curve
from sklearn.metrics import roc_auc_score
def plot_roc_curve(fpr,tpr):
    plt.plot(fpr,tpr,color='red',label='ROC')
    plt.plot([1,0],[0,1],color='black',linestyle='--')
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('ROC(Receiver Operating Curve)')
    plt.legend()
    plt.show()
    
probs=classifier.predict_proba(x_test)
probs
auc=roc_auc_score(y_test,probs)
print('AUC:%.2f'%auc)
fpr,tpr,thresholds=roc_curve(y_test,probs)
plot_roc_curve(fpr,tpr)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08680555555555555, 'fraction_numerical': 0.025584795321637425, 'mean_word_length': 5.1911764705882355, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '659102', 'license': 'MIT', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1664, 'n_words': 581, 'path': 'Vino Verde Red wine Quality using ANN.ipynb', 'repo_name': 'ak-cell/Vino-Verde-Red-Wine-Quality-using-ANN', 'size': '5472'}