Code Monkey home page Code Monkey logo

basic-nn-model's Introduction

Developing a Neural Network Regression Model

AIM

To develop a neural network regression model for the given dataset.

THEORY

The problem statement for developing a neural network regression model involves predicting a continuous value output based on a set of input features. In regression tasks, the goal is to learn a mapping from input variables to a continuous target variable.

Neural Network Model

OP

DESIGN STEPS

STEP 1:

Loading the dataset

STEP 2:

Split the dataset into training and testing

STEP 3:

Create MinMaxScalar objects ,fit the model and transform the data.

STEP 4:

Build the Neural Network Model and compile the model.

STEP 5:

Train the model with the training data.

STEP 6:

Plot the performance plot

STEP 7:

Evaluate the model with the testing data.

PROGRAM

Name: Sowmiya N

Register Number: 212221230106

from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
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('dl1').sheet1
data=worksheet.get_all_values()

dataset1=pd.DataFrame(data[1:],columns=data[0])
dataset1=dataset1.astype({'A':'float'})
dataset1=dataset1.astype({'B':'float'})
dataset1.head()

X = dataset1[['A']].values
y = dataset1[['B']].values

X

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.33,random_state = 33)

import numpy as np
from sklearn.metrics import mean_squared_error
mse = mean_squared_error(X_test, y_test)
rmse = np.sqrt(mse)

print("Root Mean Squared Error:", rmse)

Scaler = MinMaxScaler()
Scaler.fit(X_train)

X_train1 = Scaler.transform(X_train)

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

Model = Sequential ([
    Dense(units = 5, activation ='relu', input_shape = [1]),
    Dense(units = 3, activation ='relu'),
    Dense(units = 4, activation ='relu'),
    Dense(units=1)
])

Model.compile(optimizer='rmsprop',loss='mse')

Model.fit(x=X_train1,y=y_train,epochs=2000)

loss_df = pd.DataFrame(Model.history.history)
loss_df.plot()

X_test1 = Scaler.transform(X_test)
Model.evaluate(X_test1,y_test)

X_n1 = [[30]]
X_n1_1 = Scaler.transform(X_n1)
Model.predict(X_n1_1)

Dataset Information

op

OUTPUT

Values of X :

op

Appling Scaler :

op

Evaluation:

op

Training Loss Vs Iteration Plot

Model fitting :

op

Loss function Plot:

op

Test Data Root Mean Squared Error

op

New Sample Data Prediction

Data set :

op

Prediction :

op

Thus it is evident that on prediction we get the output as 52.29072 for the given input 5.

RESULT

A neural network regression model for the given dataset is developed .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.