To develop a neural network regression model for the given dataset.
Neural network regression is a supervised learning method, and therefore requires a tagged dataset, which includes a label column. Because a regression model predicts a numerical value, the label column must be a numerical data type. You can train the model by providing the model and the tagged dataset as an input to Train Model.
In this experiment we need to develop a Neural Network Regression Model so first we need to create a dataset (i.e : an excel file with some inputs as well as corresponding outputs).Then upload the sheet to drive then using corresponding code open the sheet and then import the required python libraries for porcessing.
Use df.head to get the first 5 values from the dataset or sheet.Then assign x and y values for input and coressponding outputs.Then split the dataset into testing and training,fit the training set and for the model use the "relu" activation function for the hidden layers of the neural network (here two hidden layers of 9 and 10 neurons are taken to process).To check the loss mean square error is uesd.Then the testing set is taken and fitted, at last the model is checked for accuracy via preiction.
Loading the dataset
Split the dataset into training and testing
Create MinMaxScalar objects ,fit the model and transform the data.
Build the Neural Network Model and compile the model.
Train the model with the training data.
Plot the performance plot
Evaluate the model with the testing data.
Name:M.Hariharan
Reg.No:212221230034
from google.colab import auth
import gspread
from google.auth import default
import pandas as pd
auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)
worksheet = gc.open('deeplearning_ex_1').sheet1
rows = worksheet.get_all_values()
df = pd.DataFrame(rows[1:], columns=rows[0])
df = df.astype({'Input':'float'})
df = df.astype({'Output':'float'})
df.head()
X=df[['Input']].values
y=df[['Output']].values
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.33,random_state=33)
from sklearn.preprocessing import MinMaxScaler
Scaler =MinMaxScaler()
Scaler.fit(X_train)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
neuron=Sequential([
Dense(9,activation='relu'),
Dense(10,activation='relu'),
Dense(1)
])
neuron.compile(optimizer = 'rmsprop',loss = 'mse')
X_train1=Scaler.transform(X_train)
neuron.fit(X_train1,y_train,epochs = 3000)
loss_df = pd.DataFrame(neuron.history.history)
loss_df.plot()
neuron.evaluate(X_test,y_test)
X_n1 = [[150]]
X_n1_1 = Scaler.transform(X_n1)
neuron.predict(X_n1_1)
Thus a neural network regression model for the given dataset is written and executed successfully