SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
RAMCO INSTITUTE OF TECHNOLOGY
RAJAPALAYAM
13.04.2020
Prepared by Dr.M.Kaliappan, Associate Professor/CSE
--------------------------------------------------------------------------------------------------------------------
Topic: Implementation of Regression with Neural Networks using TensorFlow in Amazon
Deep Learning Server
---------------------------------------------------------------------------------------------------------------------
1. Visit to https://aws.amazon.com/deep-learning/
2. Sign in to console , if not, signup with your data and make payment of Rs.2/-
3. Click on services  then, click on EC2
4. Click on EC2 Dashboard and launch instances
5. Press Ctrl+F (search) : Search a keyword deep learning
6. Select Deep learning AMI(Amazon Linux2)
7. Choose an instance type
8. Click Review and launch
9. Click launch
10. Select create a new keypair
11. Give key file name: key(any name)
12. Download key pair
A key.pem file is downloaded and saved in your computer(Download section)
13. Select your created instances
14. Click connect button
Copy the Public DNS: ec2-3-133-153-1.us-east-2.compute.amazonaws.com
15. Open command prompt  go to Downloads
Type the following command
ssh -L localhost:8888:localhost:8888 -i key1.pem ec2-user@ec2-3-133-153-1.us-east-
2.compute.amazonaws.com
Now, we got Amazon Linux system
16. Type jupyter notebook
The jupyter notebook is running at the following URL.
17. Type this URL in browser.
Click on new button. Select Environment (conda_tensorflow_p36)
Regression with Neural Networks using TensorFlow Keras API
(Blue color represents code, copy and paste in jupyter notebook)
Figure 1: Neural Network
In regression, the computer/machine should be able to predict a value – mostly numeric.
Generate Data: Here we are going to generate some data using our own function. This function
is a non-linear function and a usual line fitting may not work for such a function
def myfunc(x):
if x < 30:
mult = 10
elif x < 60:
mult = 20
else:
mult = 50
return x*mult
Let us check what does this function return.
print(myfunc(10))
print(myfunc(30))
print(myfunc(60))
It should print something like:
100
600
3000
Now, let us generate data. Let us import numpy library as np. here x is a numpy array of input
values. Then, we are generating values between 0 and 100 with a gap of 0.01 using arange
function. It generates a numpy array.
import numpy as np
x = np.arange(0, 100, .01)
print(x)
data:
array([0.000e+00, 1.000e-02, 2.000e-02, ..., 9.997e+01, 9.998e+01, 9.999e+01])
To call a function repeatedly on a numpy array we first need to convert the function using
vectorize. Afterwards, we are converting 1-D array to 2-D array having only one value in the
second dimension – you can think of it as a table of data with only one column.
myfuncv = np.vectorize(myfunc)
y = myfuncv(x)
X = x.reshape(-1, 1)
Print(X)
[[0.000e+00],
[1.000e-02],
[2.000e-02],
...
[9.997e+01],
[9.998e+01],
[9.999e+01]]
Now, we have X representing the input data with single feature and y representing the output.
We will now split this data into two parts: training set (X_train, y_train) and test set (X_test
y_test). We are going make neural ne
to produce y from X – we are going to test the model on the test set.
import sklearn.model_selection as sk
X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state
Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You
can try plotting X vs y, as well as, X_test vs y_test.
import matplotlib.pyplot as plt
plt.scatter(X_train,y_train)
plt.scatter(X_test,y_test)
Now, we have X representing the input data with single feature and y representing the output.
We will now split this data into two parts: training set (X_train, y_train) and test set (X_test
y_test). We are going make neural network learn from training data, and once it has learnt
we are going to test the model on the test set.
import sklearn.model_selection as sk
X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state
Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You
can try plotting X vs y, as well as, X_test vs y_test.
Figure 2: X_train vs y_train
Now, we have X representing the input data with single feature and y representing the output.
We will now split this data into two parts: training set (X_train, y_train) and test set (X_test
twork learn from training data, and once it has learnt – how
X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state = 42)
Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You
Let us import TensorFlow libraries and check the version.
import tensorflow as tf
print(tf.__version__)
Now, let us create a neural network using Keras API of TensorFlow.
# Import the kera modules
from keras.layers import Input, Dense
from keras.models import Model
# This returns a tensor. Since the input only has one column
inputs = Input(shape=(1,))
# a layer instance is callable on a tensor, and returns a tensor
# To the first layer we are feeding inputs
x = Dense(32, activation='relu')(inputs)
# To the next layer we are feeding the result of previous call here it is h
x = Dense(64, activation='relu')(x)
x = Dense(64, activation='relu')(x)
# Predictions are the result of the neural network. Notice that the predictions are also having one
column.
predictions = Dense(1)(x)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)
# Here the loss function is mse -
model.compile(optimizer='rmsprop',
loss='mse',
Figure 2: X_test vs y_test
et us import TensorFlow libraries and check the version.
us create a neural network using Keras API of TensorFlow.
from keras.layers import Input, Dense
from keras.models import Model
# This returns a tensor. Since the input only has one column
# a layer instance is callable on a tensor, and returns a tensor
# To the first layer we are feeding inputs
x = Dense(32, activation='relu')(inputs)
# To the next layer we are feeding the result of previous call here it is h
)(x)
x = Dense(64, activation='relu')(x)
# Predictions are the result of the neural network. Notice that the predictions are also having one
# This creates a model that includes
# the Input layer and three Dense layers
odel = Model(inputs=inputs, outputs=predictions)
Mean Squared Error because it is a regression problem.
model.compile(optimizer='rmsprop',
# Predictions are the result of the neural network. Notice that the predictions are also having one
Mean Squared Error because it is a regression problem.
metrics=['mse'])
Let us now train the model. First, it would initialize the weights of each neuron with random
values and the using backpropagation it is going to tweak the weights in order to get the
appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of
X at a time.
model.fit(X_train, y_train, epochs=500, batch_size=100) # starts training
Once we have trained the model. We can do predictions using the predict method of the model.
In our case, this model should predict y using X. Let us test it over our test set. Plot the results.
y_test = model.predict(X_test)
plt.scatter(X_test, y_test)
References:
1. https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n
eural_networks.htm
2. https://cloudxlab.com/blog/regression
. First, it would initialize the weights of each neuron with random
values and the using backpropagation it is going to tweak the weights in order to get the
appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of
model.fit(X_train, y_train, epochs=500, batch_size=100) # starts training
Once we have trained the model. We can do predictions using the predict method of the model.
In our case, this model should predict y using X. Let us test it over our test set. Plot the results.
https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n
https://cloudxlab.com/blog/regression-using-tensorflow-keras-api/
. First, it would initialize the weights of each neuron with random
values and the using backpropagation it is going to tweak the weights in order to get the
appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of
Once we have trained the model. We can do predictions using the predict method of the model.
In our case, this model should predict y using X. Let us test it over our test set. Plot the results.
https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n

Weitere ähnliche Inhalte

Was ist angesagt?

Keras cheat sheet_python
Keras cheat sheet_pythonKeras cheat sheet_python
Keras cheat sheet_pythonCoding Tonic
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert홍배 김
 
Probabilistic Programming in Scala
Probabilistic Programming in ScalaProbabilistic Programming in Scala
Probabilistic Programming in ScalaBeScala
 
Gentlest Introduction to Tensorflow
Gentlest Introduction to TensorflowGentlest Introduction to Tensorflow
Gentlest Introduction to TensorflowKhor SoonHin
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to TensorflowTzar Umang
 
TensorFlow Tutorial
TensorFlow TutorialTensorFlow Tutorial
TensorFlow TutorialNamHyuk Ahn
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learnCheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learnKarlijn Willems
 
알고리즘 중심의 머신러닝 가이드 Ch04
알고리즘 중심의 머신러닝 가이드 Ch04알고리즘 중심의 머신러닝 가이드 Ch04
알고리즘 중심의 머신러닝 가이드 Ch04HyeonSeok Choi
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonChristoph Matthies
 
Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3Khor SoonHin
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheetNishant Upadhyay
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Namgee Lee
 
Build your own Convolutional Neural Network CNN
Build your own Convolutional Neural Network CNNBuild your own Convolutional Neural Network CNN
Build your own Convolutional Neural Network CNNHichem Felouat
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheetNishant Upadhyay
 
Machine Learning Algorithms
Machine Learning AlgorithmsMachine Learning Algorithms
Machine Learning AlgorithmsHichem Felouat
 
MLHEP 2015: Introductory Lecture #2
MLHEP 2015: Introductory Lecture #2MLHEP 2015: Introductory Lecture #2
MLHEP 2015: Introductory Lecture #2arogozhnikov
 
07 Machine Learning - Expectation Maximization
07 Machine Learning - Expectation Maximization07 Machine Learning - Expectation Maximization
07 Machine Learning - Expectation MaximizationAndres Mendez-Vazquez
 

Was ist angesagt? (19)

Keras cheat sheet_python
Keras cheat sheet_pythonKeras cheat sheet_python
Keras cheat sheet_python
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
 
Probabilistic Programming in Scala
Probabilistic Programming in ScalaProbabilistic Programming in Scala
Probabilistic Programming in Scala
 
Gentlest Introduction to Tensorflow
Gentlest Introduction to TensorflowGentlest Introduction to Tensorflow
Gentlest Introduction to Tensorflow
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
 
TensorFlow Tutorial
TensorFlow TutorialTensorFlow Tutorial
TensorFlow Tutorial
 
Cheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learnCheat Sheet for Machine Learning in Python: Scikit-learn
Cheat Sheet for Machine Learning in Python: Scikit-learn
 
알고리즘 중심의 머신러닝 가이드 Ch04
알고리즘 중심의 머신러닝 가이드 Ch04알고리즘 중심의 머신러닝 가이드 Ch04
알고리즘 중심의 머신러닝 가이드 Ch04
 
Lect24 hmm
Lect24 hmmLect24 hmm
Lect24 hmm
 
Pybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in PythonPybelsberg — Constraint-based Programming in Python
Pybelsberg — Constraint-based Programming in Python
 
Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3Gentlest Introduction to Tensorflow - Part 3
Gentlest Introduction to Tensorflow - Part 3
 
Python matplotlib cheat_sheet
Python matplotlib cheat_sheetPython matplotlib cheat_sheet
Python matplotlib cheat_sheet
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
Build your own Convolutional Neural Network CNN
Build your own Convolutional Neural Network CNNBuild your own Convolutional Neural Network CNN
Build your own Convolutional Neural Network CNN
 
Python seaborn cheat_sheet
Python seaborn cheat_sheetPython seaborn cheat_sheet
Python seaborn cheat_sheet
 
Machine Learning Algorithms
Machine Learning AlgorithmsMachine Learning Algorithms
Machine Learning Algorithms
 
MLHEP 2015: Introductory Lecture #2
MLHEP 2015: Introductory Lecture #2MLHEP 2015: Introductory Lecture #2
MLHEP 2015: Introductory Lecture #2
 
07 Machine Learning - Expectation Maximization
07 Machine Learning - Expectation Maximization07 Machine Learning - Expectation Maximization
07 Machine Learning - Expectation Maximization
 

Ähnlich wie Implement Neural Networks Regression with TensorFlow

Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Ganesan Narayanasamy
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learningMax Kleiner
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Max Kleiner
 
Assignment 6.1.pdf
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdfdash41
 
How to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make PredictionsHow to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make PredictionsDeveloper Helps
 
APPLIED MACHINE LEARNING
APPLIED MACHINE LEARNINGAPPLIED MACHINE LEARNING
APPLIED MACHINE LEARNINGRevanth Kumar
 
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...NANDHINIS900805
 
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Thomas Fan
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Chapter3 bp
Chapter3   bpChapter3   bp
Chapter3 bpkumar tm
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnnDebarko De
 
Training course lect2
Training course lect2Training course lect2
Training course lect2Noor Dhiya
 
# Neural network toolbox
# Neural network toolbox # Neural network toolbox
# Neural network toolbox VineetKumar508
 
DPLYR package in R
DPLYR package in RDPLYR package in R
DPLYR package in RBimba Pawar
 

Ähnlich wie Implement Neural Networks Regression with TensorFlow (20)

Naïve Bayes.pptx
Naïve Bayes.pptxNaïve Bayes.pptx
Naïve Bayes.pptx
 
Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117Power ai tensorflowworkloadtutorial-20171117
Power ai tensorflowworkloadtutorial-20171117
 
K Means Clustering in ML.pptx
K Means Clustering in ML.pptxK Means Clustering in ML.pptx
K Means Clustering in ML.pptx
 
maxbox starter60 machine learning
maxbox starter60 machine learningmaxbox starter60 machine learning
maxbox starter60 machine learning
 
Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62Machine Learning Guide maXbox Starter62
Machine Learning Guide maXbox Starter62
 
E10
E10E10
E10
 
BPstudy sklearn 20180925
BPstudy sklearn 20180925BPstudy sklearn 20180925
BPstudy sklearn 20180925
 
Neural networks
Neural networksNeural networks
Neural networks
 
Assignment 6.1.pdf
Assignment 6.1.pdfAssignment 6.1.pdf
Assignment 6.1.pdf
 
How to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make PredictionsHow to Build a Neural Network and Make Predictions
How to Build a Neural Network and Make Predictions
 
APPLIED MACHINE LEARNING
APPLIED MACHINE LEARNINGAPPLIED MACHINE LEARNING
APPLIED MACHINE LEARNING
 
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
wepik-breaking-down-spam-detection-a-deep-learning-approach-with-tensorflow-a...
 
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
Pydata DC 2018 (Skorch - A Union of Scikit-learn and PyTorch)
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
RNN.pdf
RNN.pdfRNN.pdf
RNN.pdf
 
Chapter3 bp
Chapter3   bpChapter3   bp
Chapter3 bp
 
Image classification using cnn
Image classification using cnnImage classification using cnn
Image classification using cnn
 
Training course lect2
Training course lect2Training course lect2
Training course lect2
 
# Neural network toolbox
# Neural network toolbox # Neural network toolbox
# Neural network toolbox
 
DPLYR package in R
DPLYR package in RDPLYR package in R
DPLYR package in R
 

Mehr von Ramco Institute of Technology, Rajapalayam, Tamilnadu, India

Mehr von Ramco Institute of Technology, Rajapalayam, Tamilnadu, India (20)

AD3251-Data Structures Design-Notes-Tree.pdf
AD3251-Data Structures  Design-Notes-Tree.pdfAD3251-Data Structures  Design-Notes-Tree.pdf
AD3251-Data Structures Design-Notes-Tree.pdf
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
ASP.NET-stored procedure-manual
ASP.NET-stored procedure-manualASP.NET-stored procedure-manual
ASP.NET-stored procedure-manual
 
Mobile Computing-Unit-V-Mobile Platforms and Applications
Mobile Computing-Unit-V-Mobile Platforms and ApplicationsMobile Computing-Unit-V-Mobile Platforms and Applications
Mobile Computing-Unit-V-Mobile Platforms and Applications
 
CS8601 mobile computing Two marks Questions and Answer
CS8601 mobile computing Two marks Questions and AnswerCS8601 mobile computing Two marks Questions and Answer
CS8601 mobile computing Two marks Questions and Answer
 
Mobile computing Unit III MANET Notes
Mobile computing Unit III MANET NotesMobile computing Unit III MANET Notes
Mobile computing Unit III MANET Notes
 
Unit II -Mobile telecommunication systems
Unit II -Mobile telecommunication systemsUnit II -Mobile telecommunication systems
Unit II -Mobile telecommunication systems
 
Mobile computing unit-I-notes 07.01.2020
Mobile computing unit-I-notes 07.01.2020Mobile computing unit-I-notes 07.01.2020
Mobile computing unit-I-notes 07.01.2020
 
Virtual lab - Routing in Mobile Adhoc Networks
Virtual lab - Routing in Mobile Adhoc NetworksVirtual lab - Routing in Mobile Adhoc Networks
Virtual lab - Routing in Mobile Adhoc Networks
 
Flipped class collaborative learning-kaliappan-rit
Flipped class collaborative learning-kaliappan-ritFlipped class collaborative learning-kaliappan-rit
Flipped class collaborative learning-kaliappan-rit
 
Web services-Notes
Web services-NotesWeb services-Notes
Web services-Notes
 
Building Service Oriented Architecture based applications
Building Service Oriented Architecture based applicationsBuilding Service Oriented Architecture based applications
Building Service Oriented Architecture based applications
 
Innovative Practice-ZigSaw
Innovative Practice-ZigSaw Innovative Practice-ZigSaw
Innovative Practice-ZigSaw
 
SOA unit-3-notes-Introduction to Service Oriented Architecture
SOA unit-3-notes-Introduction to Service Oriented ArchitectureSOA unit-3-notes-Introduction to Service Oriented Architecture
SOA unit-3-notes-Introduction to Service Oriented Architecture
 
Innovative practice -Three step interview-Dr.M.Kaliappan
Innovative practice -Three step interview-Dr.M.KaliappanInnovative practice -Three step interview-Dr.M.Kaliappan
Innovative practice -Three step interview-Dr.M.Kaliappan
 
Service Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML SchemaService Oriented Architecture-Unit-1-XML Schema
Service Oriented Architecture-Unit-1-XML Schema
 
IT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notesIT6801-Service Oriented Architecture-Unit-2-notes
IT6801-Service Oriented Architecture-Unit-2-notes
 
Innovative Practice-Think-pair-share-Topic: DTD for TV schedule
Innovative Practice-Think-pair-share-Topic: DTD for TV scheduleInnovative Practice-Think-pair-share-Topic: DTD for TV schedule
Innovative Practice-Think-pair-share-Topic: DTD for TV schedule
 
IT6801-Service Oriented Architecture- UNIT-I notes
IT6801-Service Oriented Architecture- UNIT-I notesIT6801-Service Oriented Architecture- UNIT-I notes
IT6801-Service Oriented Architecture- UNIT-I notes
 
Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019Soa unit-1-well formed and valid document08.07.2019
Soa unit-1-well formed and valid document08.07.2019
 

Kürzlich hochgeladen

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 

Kürzlich hochgeladen (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 

Implement Neural Networks Regression with TensorFlow

  • 1. RAMCO INSTITUTE OF TECHNOLOGY RAJAPALAYAM 13.04.2020 Prepared by Dr.M.Kaliappan, Associate Professor/CSE -------------------------------------------------------------------------------------------------------------------- Topic: Implementation of Regression with Neural Networks using TensorFlow in Amazon Deep Learning Server --------------------------------------------------------------------------------------------------------------------- 1. Visit to https://aws.amazon.com/deep-learning/ 2. Sign in to console , if not, signup with your data and make payment of Rs.2/-
  • 2. 3. Click on services  then, click on EC2 4. Click on EC2 Dashboard and launch instances
  • 3. 5. Press Ctrl+F (search) : Search a keyword deep learning 6. Select Deep learning AMI(Amazon Linux2) 7. Choose an instance type 8. Click Review and launch 9. Click launch
  • 4. 10. Select create a new keypair 11. Give key file name: key(any name) 12. Download key pair A key.pem file is downloaded and saved in your computer(Download section)
  • 5. 13. Select your created instances 14. Click connect button
  • 6. Copy the Public DNS: ec2-3-133-153-1.us-east-2.compute.amazonaws.com 15. Open command prompt  go to Downloads Type the following command ssh -L localhost:8888:localhost:8888 -i key1.pem ec2-user@ec2-3-133-153-1.us-east- 2.compute.amazonaws.com
  • 7. Now, we got Amazon Linux system
  • 8. 16. Type jupyter notebook
  • 9. The jupyter notebook is running at the following URL. 17. Type this URL in browser. Click on new button. Select Environment (conda_tensorflow_p36) Regression with Neural Networks using TensorFlow Keras API (Blue color represents code, copy and paste in jupyter notebook) Figure 1: Neural Network
  • 10. In regression, the computer/machine should be able to predict a value – mostly numeric. Generate Data: Here we are going to generate some data using our own function. This function is a non-linear function and a usual line fitting may not work for such a function def myfunc(x): if x < 30: mult = 10 elif x < 60: mult = 20 else: mult = 50 return x*mult Let us check what does this function return. print(myfunc(10)) print(myfunc(30)) print(myfunc(60)) It should print something like: 100 600 3000 Now, let us generate data. Let us import numpy library as np. here x is a numpy array of input values. Then, we are generating values between 0 and 100 with a gap of 0.01 using arange function. It generates a numpy array. import numpy as np x = np.arange(0, 100, .01) print(x) data: array([0.000e+00, 1.000e-02, 2.000e-02, ..., 9.997e+01, 9.998e+01, 9.999e+01]) To call a function repeatedly on a numpy array we first need to convert the function using vectorize. Afterwards, we are converting 1-D array to 2-D array having only one value in the second dimension – you can think of it as a table of data with only one column. myfuncv = np.vectorize(myfunc) y = myfuncv(x)
  • 11. X = x.reshape(-1, 1) Print(X) [[0.000e+00], [1.000e-02], [2.000e-02], ... [9.997e+01], [9.998e+01], [9.999e+01]] Now, we have X representing the input data with single feature and y representing the output. We will now split this data into two parts: training set (X_train, y_train) and test set (X_test y_test). We are going make neural ne to produce y from X – we are going to test the model on the test set. import sklearn.model_selection as sk X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You can try plotting X vs y, as well as, X_test vs y_test. import matplotlib.pyplot as plt plt.scatter(X_train,y_train) plt.scatter(X_test,y_test) Now, we have X representing the input data with single feature and y representing the output. We will now split this data into two parts: training set (X_train, y_train) and test set (X_test y_test). We are going make neural network learn from training data, and once it has learnt we are going to test the model on the test set. import sklearn.model_selection as sk X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You can try plotting X vs y, as well as, X_test vs y_test. Figure 2: X_train vs y_train Now, we have X representing the input data with single feature and y representing the output. We will now split this data into two parts: training set (X_train, y_train) and test set (X_test twork learn from training data, and once it has learnt – how X_train, X_test, y_train, y_test = sk.train_test_split(X,y,test_size=0.33, random_state = 42) Let us visualize how does our data looks like. Here, we are plotting only X_train vs y_train. You
  • 12. Let us import TensorFlow libraries and check the version. import tensorflow as tf print(tf.__version__) Now, let us create a neural network using Keras API of TensorFlow. # Import the kera modules from keras.layers import Input, Dense from keras.models import Model # This returns a tensor. Since the input only has one column inputs = Input(shape=(1,)) # a layer instance is callable on a tensor, and returns a tensor # To the first layer we are feeding inputs x = Dense(32, activation='relu')(inputs) # To the next layer we are feeding the result of previous call here it is h x = Dense(64, activation='relu')(x) x = Dense(64, activation='relu')(x) # Predictions are the result of the neural network. Notice that the predictions are also having one column. predictions = Dense(1)(x) # This creates a model that includes # the Input layer and three Dense layers model = Model(inputs=inputs, outputs=predictions) # Here the loss function is mse - model.compile(optimizer='rmsprop', loss='mse', Figure 2: X_test vs y_test et us import TensorFlow libraries and check the version. us create a neural network using Keras API of TensorFlow. from keras.layers import Input, Dense from keras.models import Model # This returns a tensor. Since the input only has one column # a layer instance is callable on a tensor, and returns a tensor # To the first layer we are feeding inputs x = Dense(32, activation='relu')(inputs) # To the next layer we are feeding the result of previous call here it is h )(x) x = Dense(64, activation='relu')(x) # Predictions are the result of the neural network. Notice that the predictions are also having one # This creates a model that includes # the Input layer and three Dense layers odel = Model(inputs=inputs, outputs=predictions) Mean Squared Error because it is a regression problem. model.compile(optimizer='rmsprop', # Predictions are the result of the neural network. Notice that the predictions are also having one Mean Squared Error because it is a regression problem.
  • 13. metrics=['mse']) Let us now train the model. First, it would initialize the weights of each neuron with random values and the using backpropagation it is going to tweak the weights in order to get the appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of X at a time. model.fit(X_train, y_train, epochs=500, batch_size=100) # starts training Once we have trained the model. We can do predictions using the predict method of the model. In our case, this model should predict y using X. Let us test it over our test set. Plot the results. y_test = model.predict(X_test) plt.scatter(X_test, y_test) References: 1. https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n eural_networks.htm 2. https://cloudxlab.com/blog/regression . First, it would initialize the weights of each neuron with random values and the using backpropagation it is going to tweak the weights in order to get the appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of model.fit(X_train, y_train, epochs=500, batch_size=100) # starts training Once we have trained the model. We can do predictions using the predict method of the model. In our case, this model should predict y using X. Let us test it over our test set. Plot the results. https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n https://cloudxlab.com/blog/regression-using-tensorflow-keras-api/ . First, it would initialize the weights of each neuron with random values and the using backpropagation it is going to tweak the weights in order to get the appropriate result. Here we are running the iteration 500 times and we are feeding 100 records of Once we have trained the model. We can do predictions using the predict method of the model. In our case, this model should predict y using X. Let us test it over our test set. Plot the results. https://www.tutorialspoint.com/python_deep_learning/python_deep_learning_artificial_n