SlideShare a Scribd company logo
Robert John
GDE (GCP, ML)
@robert_thas
TensorFlow
What is TensorFlow and why do we use it?
TensorFlow is a numerical
computation library. It lets us
perform mathematical and
statistical operations on our
data.
Example
Predict the selling price of a house given the number of rooms
● Medv => y
● Rooms => x
● Constant => b
● Gradients => w
Formulate a Hypothesis
This hypothesis is called a model
Without TensorFlow
import pandas as pd
import numpy as np
train_df = pd.read_csv('/content/gdrive/My
Drive/boston/train.csv', index_col='ID')
train_df.head()
train_df[['rm', 'medv']].head()
y = train_df['medv'].values
train_df['constant'] = 1
columns = ['constant', 'rm']
x = train_df[columns].values
w = np.zeros((x.shape[1], 1))
y_pred = np.dot(x, w)
error = y - y_pred
print(error.shape)
squared_error = np.power(error, 2)
root_mean_squared_error = sqrt(squared_error.sum()) /
y_pred.shape[0]
print(root_mean_squared_error)
Training
costs = []
w_0_s = []
w_1_s = []
learning_rate = 1e-3
steps = 20
for a in range(steps):
w_0 = w[0][0]
w_1 = w[1][0]
# make prediction
y_pred = np.dot(x, w)
error = y - y_pred
error_squared = np.power(error, 2)
# cost function is Least Mean Squares
LMS = error_squared.sum() / (2 * y.shape[0])
costs.append(LMS)
w_0_s.append(w_0)
w_1_s.append(w_1)
# update
w_0 = w_0 + learning_rate/y.shape[0] * error.sum()
w_1 = w_1 + learning_rate/y.shape[0] * (error * x[1]).sum()
w[0][0] = w_0
w[1][0] = w_1
cost_df = pd.DataFrame({'cost': pd.Series(costs),
'w_0': pd.Series(w_0_s), 'w_1': pd.Series(w_1_s)})
cost_df['cost'].plot()
How good are the
predictions?
_w = [w_0, w_1]
_w = np.asarray(_w)
_x = train_df[['constant', 'rm']].values
y_pred = np.dot(_x, _w)
_p = pd.DataFrame(dict(actual=train_df['medv'].values,
predicted=y_pred.reshape(-1)))
_p.head()
How is TensorFlow different?
class Model(object):
def __init__(self):
self.W = None
self.b = None
def __call__(self, x):
if self.W == None:
self.W = tf.Variable(tf.random.normal(shape=(1, x.shape[1])))
if self.b == None:
self.b = tf.Variable(tf.random.normal(shape=(x.shape[0], 1)))
return tf.matmul(x, self.W, transpose_b=True) + self.b
model = Model()
output = model(tf.constant([3.0, 3.1, 1.9, 2.0, 2.5, 2.9],
shape=(3,2)))
print(output)
@tf.function
def loss(y_pred, y):
return tf.reduce_mean(tf.square(y-y_pred))
def train(model, x, y, alpha):
x = tf.convert_to_tensor(x, np.float32)
y = tf.convert_to_tensor(y, np.float32)
with tf.GradientTape() as t:
t.watch(x)
current_loss = loss(model(x), y)
#print(current_loss)
dW, db = t.gradient(current_loss, [model.W, model.b])
#print(dW, db)
model.W.assign_sub(alpha * dW)
model.b.assign_sub(alpha * db)
train_df = df.sample(frac=0.8,random_state=0)
test_df = df.drop(train_df.index)
columns = ['nox', 'rm', 'chas', 'dis', 'ptratio', 'lstat', 'rad']
X_train = train_df[columns].values
X_test = test_df[columns].values
y_train = train_df[['medv']].values
y_test = test_df[['medv']].values
epochs = 10
model = Model()
for i in range(epochs):
train(model, X_train, y_train, alpha=0.1)
print(model.W)
● Vectors & Matrices
● Matrix Dot Products
● Differentiation
What was all that?
We got introduced to
● Learning Rates
● Gradient Descent
● Training Epochs
All of that was Linear Regression. How
about Neural Networks?
import tensorflow as tf
from tensorflow import keras
model = keras.Sequential([
keras.layers.Dense(50, input_shape=(7,), activation='relu'),
keras.layers.Dense(50, activation='relu'),
keras.layers.Dense(50, activation='relu'),
keras.layers.Dropout(0.5),
keras.layers.Dense(1)
])
print(model.summary())
adam = keras.optimizers.Adam(0.001)
model.compile(optimizer=adam, loss='mse')
model.fit(X_train, y_train, epochs=2000, validation_split=0.1)
● Optimized operations
● Hardware acceleration
● Multiple languages/platforms
Benefits of using TensorFlow
● Layers
● Optimizers
● Loss Functions
● Feature Engineering
● Hyperparameter Tuning
● Model Optimization
● Transfer Learning
● Keras Preprocessing Layers
● Recommendations
● New features in tf.data
● Experimental Numpy support
What’s New in TensorFlow
● API Types (Keras, Estimators, etc)
● Originally graph-based vs. “pythonic”
Differences Between TensorFlow and Others
Learn More
Neural Networks and Deep Learning
http://neuralnetworksanddeeplearning.com/
Machine Learning Crash Course
https://developers.google.com/machine-learning/crash-course
TensorFlow
https://www.tensorflow.org/
Robert John
GDE (GCP, ML)
@robert_thas
Thank You!

More Related Content

What's hot

SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegressionDaniel K
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
Martin McBride
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
Emertxe Information Technologies Pvt Ltd
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
DataminingTools Inc
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Recursion in C
Recursion in CRecursion in C
Recursion in C
Lakshmi Sarvani Videla
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
Programming Homework Help
 
Matlab Visualizing Data
Matlab Visualizing DataMatlab Visualizing Data
Matlab Visualizing Data
DataminingTools Inc
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
phil_nash
 
PYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesPYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesTianqi Huang, CFA
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
shafiq sangi
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
Saurabh Singh
 
Day 4b iteration and functions for-loops.pptx
Day 4b   iteration and functions  for-loops.pptxDay 4b   iteration and functions  for-loops.pptx
Day 4b iteration and functions for-loops.pptx
Adrien Melquiond
 
Gauss seidal Matlab Code
Gauss seidal Matlab CodeGauss seidal Matlab Code
Gauss seidal Matlab Code
Taimoor Muzaffar Gondal
 
Project2
Project2Project2
Project2?? ?
 
Monte-carlo sim pricing EU call
Monte-carlo sim pricing EU callMonte-carlo sim pricing EU call
Monte-carlo sim pricing EU callTianqi Huang, CFA
 

What's hot (19)

SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegression
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
Lr5
Lr5Lr5
Lr5
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Matlab Visualizing Data
Matlab Visualizing DataMatlab Visualizing Data
Matlab Visualizing Data
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
 
PYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing TreesPYTHON. AM CALL Pricing Trees
PYTHON. AM CALL Pricing Trees
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Arrays
ArraysArrays
Arrays
 
Day 4b iteration and functions for-loops.pptx
Day 4b   iteration and functions  for-loops.pptxDay 4b   iteration and functions  for-loops.pptx
Day 4b iteration and functions for-loops.pptx
 
Gauss seidal Matlab Code
Gauss seidal Matlab CodeGauss seidal Matlab Code
Gauss seidal Matlab Code
 
Project2
Project2Project2
Project2
 
Monte-carlo sim pricing EU call
Monte-carlo sim pricing EU callMonte-carlo sim pricing EU call
Monte-carlo sim pricing EU call
 

Similar to What is TensorFlow and why do we use it

Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2
Khor SoonHin
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
台灣資料科學年會
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITians
Ashish Bansal
 
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager ExecutionTensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
Taegyun Jeon
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to Tensorflow
Tzar Umang
 
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
홍배 김
 
Python Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation LearningPython Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Lviv Startup Club
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Codemotion
 
TensorFlow in Practice
TensorFlow in PracticeTensorFlow in Practice
TensorFlow in Practice
indico data
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
Dr. Volkan OBAN
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
lauracallander
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
Chu An
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
Patrick Viafore
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
 
Generic Functional Programming with Type Classes
Generic Functional Programming with Type ClassesGeneric Functional Programming with Type Classes
Generic Functional Programming with Type Classes
Tapio Rautonen
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
Oswald Campesato
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
league
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Paulo Sergio Lemes Queiroz
 
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
Databricks
 

Similar to What is TensorFlow and why do we use it (20)

Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2Gentlest Introduction to Tensorflow - Part 2
Gentlest Introduction to Tensorflow - Part 2
 
Google TensorFlow Tutorial
Google TensorFlow TutorialGoogle TensorFlow Tutorial
Google TensorFlow Tutorial
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITians
 
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager ExecutionTensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
TensorFlow Dev Summit 2018 Extended: TensorFlow Eager Execution
 
Introduction to Tensorflow
Introduction to TensorflowIntroduction to Tensorflow
Introduction to 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
 
Python Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation LearningPython Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation Learning
 
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
Sergey Shelpuk & Olha Romaniuk - “Deep learning, Tensorflow, and Fashion: how...
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
 
TensorFlow in Practice
TensorFlow in PracticeTensorFlow in Practice
TensorFlow in Practice
 
ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions ggtimeseries-->ggplot2 extensions
ggtimeseries-->ggplot2 extensions
 
Need help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docxNeed help filling out the missing sections of this code- the sections.docx
Need help filling out the missing sections of this code- the sections.docx
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
Generic Functional Programming with Type Classes
Generic Functional Programming with Type ClassesGeneric Functional Programming with Type Classes
Generic Functional Programming with Type Classes
 
Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
Building Machine Learning Algorithms on Apache Spark: Scaling Out and Up with...
 

More from Robert John

DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
Robert John
 
DevFest 2022 - Nairobi ML Keynote.pptx
DevFest 2022 - Nairobi ML Keynote.pptxDevFest 2022 - Nairobi ML Keynote.pptx
DevFest 2022 - Nairobi ML Keynote.pptx
Robert John
 
Arduino Certification
Arduino CertificationArduino Certification
Arduino Certification
Robert John
 
Fundamentals of cloud computing
Fundamentals of cloud computingFundamentals of cloud computing
Fundamentals of cloud computing
Robert John
 
What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021
Robert John
 
TinyML at DevFestLagos21
TinyML at DevFestLagos21TinyML at DevFestLagos21
TinyML at DevFestLagos21
Robert John
 
TinyML: Machine Learning for Microcontrollers
TinyML: Machine Learning for MicrocontrollersTinyML: Machine Learning for Microcontrollers
TinyML: Machine Learning for Microcontrollers
Robert John
 

More from Robert John (7)

DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
DevFest 2022 Nairobi - Considerations for Deploying ML Models on Edge Devices...
 
DevFest 2022 - Nairobi ML Keynote.pptx
DevFest 2022 - Nairobi ML Keynote.pptxDevFest 2022 - Nairobi ML Keynote.pptx
DevFest 2022 - Nairobi ML Keynote.pptx
 
Arduino Certification
Arduino CertificationArduino Certification
Arduino Certification
 
Fundamentals of cloud computing
Fundamentals of cloud computingFundamentals of cloud computing
Fundamentals of cloud computing
 
What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021What is Google Cloud Good For at DevFestInspire 2021
What is Google Cloud Good For at DevFestInspire 2021
 
TinyML at DevFestLagos21
TinyML at DevFestLagos21TinyML at DevFestLagos21
TinyML at DevFestLagos21
 
TinyML: Machine Learning for Microcontrollers
TinyML: Machine Learning for MicrocontrollersTinyML: Machine Learning for Microcontrollers
TinyML: Machine Learning for Microcontrollers
 

Recently uploaded

Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_Crimes
StarCompliance.io
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
Opendatabay
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
ewymefz
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
Oppotus
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
MaleehaSheikh2
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
ewymefz
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 

Recently uploaded (20)

Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Investigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_CrimesInvestigate & Recover / StarCompliance.io / Crypto_Crimes
Investigate & Recover / StarCompliance.io / Crypto_Crimes
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Opendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptxOpendatabay - Open Data Marketplace.pptx
Opendatabay - Open Data Marketplace.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
 
一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单一比一原版(BU毕业证)波士顿大学毕业证成绩单
一比一原版(BU毕业证)波士顿大学毕业证成绩单
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 

What is TensorFlow and why do we use it

  • 1. Robert John GDE (GCP, ML) @robert_thas TensorFlow What is TensorFlow and why do we use it?
  • 2. TensorFlow is a numerical computation library. It lets us perform mathematical and statistical operations on our data.
  • 3. Example Predict the selling price of a house given the number of rooms
  • 4.
  • 5.
  • 6.
  • 7. ● Medv => y ● Rooms => x ● Constant => b ● Gradients => w Formulate a Hypothesis This hypothesis is called a model
  • 9. import pandas as pd import numpy as np train_df = pd.read_csv('/content/gdrive/My Drive/boston/train.csv', index_col='ID') train_df.head()
  • 10.
  • 12. y = train_df['medv'].values train_df['constant'] = 1 columns = ['constant', 'rm'] x = train_df[columns].values w = np.zeros((x.shape[1], 1)) y_pred = np.dot(x, w)
  • 13. error = y - y_pred print(error.shape) squared_error = np.power(error, 2) root_mean_squared_error = sqrt(squared_error.sum()) / y_pred.shape[0] print(root_mean_squared_error)
  • 15. costs = [] w_0_s = [] w_1_s = [] learning_rate = 1e-3 steps = 20
  • 16. for a in range(steps): w_0 = w[0][0] w_1 = w[1][0] # make prediction y_pred = np.dot(x, w) error = y - y_pred error_squared = np.power(error, 2)
  • 17. # cost function is Least Mean Squares LMS = error_squared.sum() / (2 * y.shape[0]) costs.append(LMS) w_0_s.append(w_0) w_1_s.append(w_1) # update w_0 = w_0 + learning_rate/y.shape[0] * error.sum() w_1 = w_1 + learning_rate/y.shape[0] * (error * x[1]).sum() w[0][0] = w_0 w[1][0] = w_1
  • 18. cost_df = pd.DataFrame({'cost': pd.Series(costs), 'w_0': pd.Series(w_0_s), 'w_1': pd.Series(w_1_s)}) cost_df['cost'].plot()
  • 19. How good are the predictions?
  • 20. _w = [w_0, w_1] _w = np.asarray(_w) _x = train_df[['constant', 'rm']].values y_pred = np.dot(_x, _w) _p = pd.DataFrame(dict(actual=train_df['medv'].values, predicted=y_pred.reshape(-1))) _p.head()
  • 21.
  • 22. How is TensorFlow different?
  • 23. class Model(object): def __init__(self): self.W = None self.b = None def __call__(self, x): if self.W == None: self.W = tf.Variable(tf.random.normal(shape=(1, x.shape[1]))) if self.b == None: self.b = tf.Variable(tf.random.normal(shape=(x.shape[0], 1))) return tf.matmul(x, self.W, transpose_b=True) + self.b
  • 24. model = Model() output = model(tf.constant([3.0, 3.1, 1.9, 2.0, 2.5, 2.9], shape=(3,2))) print(output)
  • 25. @tf.function def loss(y_pred, y): return tf.reduce_mean(tf.square(y-y_pred))
  • 26. def train(model, x, y, alpha): x = tf.convert_to_tensor(x, np.float32) y = tf.convert_to_tensor(y, np.float32) with tf.GradientTape() as t: t.watch(x) current_loss = loss(model(x), y) #print(current_loss) dW, db = t.gradient(current_loss, [model.W, model.b]) #print(dW, db) model.W.assign_sub(alpha * dW) model.b.assign_sub(alpha * db)
  • 27. train_df = df.sample(frac=0.8,random_state=0) test_df = df.drop(train_df.index) columns = ['nox', 'rm', 'chas', 'dis', 'ptratio', 'lstat', 'rad'] X_train = train_df[columns].values X_test = test_df[columns].values y_train = train_df[['medv']].values y_test = test_df[['medv']].values
  • 28. epochs = 10 model = Model() for i in range(epochs): train(model, X_train, y_train, alpha=0.1) print(model.W)
  • 29. ● Vectors & Matrices ● Matrix Dot Products ● Differentiation What was all that? We got introduced to ● Learning Rates ● Gradient Descent ● Training Epochs
  • 30. All of that was Linear Regression. How about Neural Networks?
  • 31. import tensorflow as tf from tensorflow import keras model = keras.Sequential([ keras.layers.Dense(50, input_shape=(7,), activation='relu'), keras.layers.Dense(50, activation='relu'), keras.layers.Dense(50, activation='relu'), keras.layers.Dropout(0.5), keras.layers.Dense(1) ]) print(model.summary())
  • 32.
  • 33. adam = keras.optimizers.Adam(0.001) model.compile(optimizer=adam, loss='mse') model.fit(X_train, y_train, epochs=2000, validation_split=0.1)
  • 34. ● Optimized operations ● Hardware acceleration ● Multiple languages/platforms Benefits of using TensorFlow ● Layers ● Optimizers ● Loss Functions ● Feature Engineering ● Hyperparameter Tuning ● Model Optimization ● Transfer Learning
  • 35. ● Keras Preprocessing Layers ● Recommendations ● New features in tf.data ● Experimental Numpy support What’s New in TensorFlow
  • 36. ● API Types (Keras, Estimators, etc) ● Originally graph-based vs. “pythonic” Differences Between TensorFlow and Others
  • 37. Learn More Neural Networks and Deep Learning http://neuralnetworksanddeeplearning.com/ Machine Learning Crash Course https://developers.google.com/machine-learning/crash-course TensorFlow https://www.tensorflow.org/
  • 38. Robert John GDE (GCP, ML) @robert_thas Thank You!