To develop a neural network regression model for the given dataset.
Neural networks consist of simple input/output units called neurons. These units are interconnected and each connection has a weight associated with it. Neural networks are flexible and can be used for both classification and regression. In this article, we will see how neural networks can be applied to regression problems.
Regression helps in establishing a relationship between a dependent variable and one or more independent variables. Regression models work well only when the regression equation is a good fit for the data. Although neural networks are complex and computationally expensive, they are flexible and can dynamically pick the best type of regression, and if that is not enough, hidden layers can be added to improve prediction.
Build your training and test set from the dataset, here we are making the neural network 3 hidden layer with activation layer as relu and with their nodes in them. Now we will fit our dataset and then predict the value.
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.
Developed By: SWATHIKA G
Register Number: 212221230113
from google.colab import auth
import gspread
from google.auth import default
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from sklearn.preprocessing import MinMaxScaler
import matplotlib.pyplot as plt
auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)
worksheet = gc.open('Student_Tables').sheet1
rows = worksheet.get_all_values()
df = pd.DataFrame(rows[1:], columns=rows[0])
df = df.astype({'Table':'int'})
df = df.astype({'Scores':'int'})
df.head()
x=df[['Table']].values
y=df[['Scores']].values
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=0)
scaler=MinMaxScaler()
scaler.fit(x_train)
x_t=scaler.transform(x_train)
x_t
ai=Sequential([
Dense(8,activation='relu'),
Dense(13,activation='relu'),
Dense(1)
])
ai.compile(optimizer='rmsprop',loss='mse')
ai.fit(x_t,y_train,epochs=2000)
ai.fit(x_t,y_train,epochs=700)
loss_df=pd.DataFrame(ai.history.history)
loss_df.plot()
x_t2=scaler.transform(x_test)
ai.evaluate(x_t2,y_test)
err = rmse()
preds = ai.predict(x_test)
err(y_test,preds)
z=[[7]]
z_1=scaler.transform(z)
ai.predict(z_1)
Thus a neural network regression model for the given dataset is written and executed successfully.