<jupyter_start><jupyter_text>**This notebook is an exercise in the [Intro to Deep Learning](https://www.kaggle.com/learn/intro-to-deep-learning) course.  You can reference the tutorial at [this link](https://www.kaggle.com/ryanholbrook/a-single-neuron).**---  Introduction In the tutorial we learned about the building blocks of neural networks: *linear units*. We saw that a model of just one linear unit will fit a linear function to a dataset (equivalent to linear regression). In this exercise, you'll build a linear model and get some practice working with models in Keras.Before you get started, run the code cell below to set everything up. The *Red Wine Quality* dataset consists of physiochemical measurements from about 1600 Portuguese red wines.  Also included is a quality rating for each wine from blind taste-tests. First, run the next cell to display the first few rows of this dataset.<jupyter_code>import pandas as pd
from IPython.display import display

red_wine = pd.read_csv('winequality-red.csv')
#for setting up train and test sets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
y = red_wine['quality']
X = red_wine.drop(columns = 'quality')

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=1)

print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
red_wine.describe()
from tensorflow import keras
from tensorflow.keras import layers

model = keras.Sequential([
    layers.Dense(1024, activation='relu', input_shape=[11]),
    layers.Dropout(0.3),
    layers.BatchNormalization(),
    layers.Dense(1024, activation='relu'),
    layers.Dropout(0.3),
    layers.BatchNormalization(),
    layers.Dense(1024, activation='relu'),
    layers.Dropout(0.3),
    layers.BatchNormalization(),
    layers.Dense(1),
])
# from tensorflow import keras
# from tensorflow.keras import layers, callbacks

# early_stopping = callbacks.EarlyStopping(
#     min_delta=0.001, # minimium amount of change to count as an improvement
#     patience=20, # how many epochs to wait before stopping
#     restore_best_weights=True,
# )
model.compile(
    optimizer='adam',
    loss='mae',
)
model.summary()
history = model.fit(
    X_train, y_train,
    validation_data=(X_test, y_test),
    batch_size=256,
    epochs=1000,
#    callbacks=[early_stopping],
    verbose=0,
)
# Show the learning curves
history_df = pd.DataFrame(history.history)
history_df.loc[:, ['loss', 'val_loss']].plot();
print(("Minimum Validation Loss: {:0.4f}").format(history_df['val_loss'].min()))

#making the predictions
dnn_pred = model.predict(X_test)
from sklearn.metrics import mean_squared_error
#getting our results
dnn_mse = mean_squared_error(y_test,dnn_pred)
#printing rmse
print("MSE =",(round(dnn_mse,2)))
#result table
from tabulate import tabulate
#gathering the results
result_table = [['Deep Learning', round(dnn_mse,2)]]

#defining header names
col_names = ["Model", "MSE"]

#creating a results table
print(tabulate(result_table, headers=col_names))<jupyter_output>Model            MSE
-------------  -----
Deep Learning   0.38
{'fraction_non_alphanumeric': 0.11280298321939093, 'fraction_numerical': 0.015226848974518334, 'mean_word_length': 5.0507518796992485, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '309150', 'license': 'MIT', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1008, 'n_words': 297, 'path': 'ML/Part2-deeplearning.ipynb', 'repo_name': 'JSJeong-me/Machine_Learning', 'size': '3218'}