MACHINE LEARNINGW I T H T E N S O R F L O W
I lead the technology team at
DysonSphere
Hello!
I Am VATSAL
You can contact me at
vatsalm@dysonspherelab.com
THE
BUZZ-
WORDS
DEEP LEARNING
MACHINE LEARNING
ARTIFICIAL INTELLIGENCE
Breaking down the buzzwords to explain
What each of these terms really mean.
How to get started in ML using Tensorflow
Machine Learning
BASICS OF MACHINE LEARNING
1. Loss Reduction/ Gradient Descent
2. Dataset
3. Training Sets and Test Sets
4. Validation Sets
5. Feature Engineering
6. Good vs Bad Features
7. Data Cleaning
BASICS OF MACHINE LEARNING
Loss Reduction/ Gradient Descent
Finding the right values of learning rate and batch size
to reduce the Root Mean Square(RMS) value of the function.
Descent on the loss curve to find the local minima is Gradient
descent.
BASICS OF MACHINE LEARNING
Dataset
The large volume set of data containing the structured or
unstructured information to be used in feature modeling.
BASICS OF MACHINE LEARNING
Training Set & Test Set
The entire data is divided into two sets with unequal
proportions and the algorithm is first trained using training
set
After finding the best RMS value the same model is run
using test set to check the accuracy of the outcomes..
BASICS OF MACHINE LEARNING
Validation Set
A new partition is introduced to prevent the overfitting
problem of the ML model. This helps model to stay unaware
of the too many things.
BASICS OF MACHINE LEARNING
Feature Engineering
The data columns or properties are converted into ML
model consumable features
BASICS OF MACHINE LEARNING
Good vs Bad Features
The features must follow certain rules to simplify the
process of ML training thus reducing the cost and time to
train the model and easier to debug and verify the
predictions.
house_type: victorian
unique_house_id: 8SK982ZZ1242Z
house_age_years:
27
house_age: 851472000
quality_rating: -
1
BASICS OF MACHINE LEARNING
Data Cleaning
The dataset most often doesn’t come to ML engineers in the
most suitable way. It contains many impurities and
sometimes even false information stored within the system
due to human errors, etc..
TENSORFLOW
Tensorflow
Tensorflow is a computational framework for building
machine learning models. TensorFlow provides a variety of
different toolkits that allow you to construct models at your
preferred level of abstraction. You can use lower-level APIs
to build models by defining a series of mathematical
operations. Alternatively, you can use higher-level APIs
(like tf.estimator) to specify predefined architectures, such
as linear regressors or neural networks.
TENSORFLOW
Pseudo Code
import tensorflow as tf
# Set up a linear classifier.
classifier = tf.estimator.LinearClassifier(feature_columns)
# Train the model on some example data.
classifier.train(input_fn=train_input_fn, steps=2000)
# Use it to predict.
predictions = classifier.predict(input_fn=predict_input_fn)
TENSORFLOW
Full Code
from __future__ import print_function
import math
from IPython import display
import numpy as np
import pandas as pd
from sklearn import metrics
import tensorflow as tf
from tensorflow.python.data import Dataset
tf.logging.set_verbosity(tf.logging.ERROR)
pd.options.display.max_rows = 10
pd.options.display.float_format = '{:.1f}'.format
california_housing_dataframe = pd.read_csv("https://download.mlcc.google.com/mledu-
datasets/california_housing_train.csv", sep=",")
california_housing_dataframe = california_housing_dataframe.reindex(
np.random.permutation(california_housing_dataframe.index))
california_housing_dataframe["median_house_value"] /= 1000.0
california_housing_dataframe
# Define the input feature: total_rooms.
my_feature = california_housing_dataframe[["total_rooms"]]
# Configure a numeric feature column for total_rooms.
feature_columns = [tf.feature_column.numeric_column("total_rooms")]
# Define the label.
targets = california_housing_dataframe["median_house_value"]
# Use gradient descent as the optimizer for training the model.
my_optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.0000001)
my_optimizer = tf.contrib.estimator.clip_gradients_by_norm(my_optimizer, 5.0)
# Configure the linear regression model with our feature columns and optimizer.
# Set a learning rate of 0.0000001 for Gradient Descent.
linear_regressor = tf.estimator.LinearRegressor(
feature_columns=feature_columns,
optimizer=my_optimizer
)
def my_input_fn(features, targets, batch_size=1, shuffle=True, num_epochs=None):
"""Trains a linear regression model of one feature.
"""
# Convert pandas data into a dict of np arrays.
features = {key:np.array(value) for key,value in dict(features).items()}
# Construct a dataset, and configure batching/repeating.
ds = Dataset.from_tensor_slices((features,targets)) # warning: 2GB limit
ds = ds.batch(batch_size).repeat(num_epochs)
# Shuffle the data, if specified.
if shuffle:
ds = ds.shuffle(buffer_size=10000)
# Return the next batch of data.
features, labels = ds.make_one_shot_iterator().get_next()
return features, labels
_ = linear_regressor.train(
input_fn = lambda:my_input_fn(my_feature,
targets),
steps=100
)
Thanks!
You can find me at: vatsalm@dysonspherelab.com
Any questions?

Machine Learning with Tensorflow

  • 1.
    MACHINE LEARNINGW IT H T E N S O R F L O W
  • 2.
    I lead thetechnology team at DysonSphere Hello! I Am VATSAL You can contact me at vatsalm@dysonspherelab.com
  • 3.
    THE BUZZ- WORDS DEEP LEARNING MACHINE LEARNING ARTIFICIALINTELLIGENCE Breaking down the buzzwords to explain What each of these terms really mean.
  • 4.
    How to getstarted in ML using Tensorflow Machine Learning
  • 5.
    BASICS OF MACHINELEARNING 1. Loss Reduction/ Gradient Descent 2. Dataset 3. Training Sets and Test Sets 4. Validation Sets 5. Feature Engineering 6. Good vs Bad Features 7. Data Cleaning
  • 6.
    BASICS OF MACHINELEARNING Loss Reduction/ Gradient Descent Finding the right values of learning rate and batch size to reduce the Root Mean Square(RMS) value of the function. Descent on the loss curve to find the local minima is Gradient descent.
  • 7.
    BASICS OF MACHINELEARNING Dataset The large volume set of data containing the structured or unstructured information to be used in feature modeling.
  • 8.
    BASICS OF MACHINELEARNING Training Set & Test Set The entire data is divided into two sets with unequal proportions and the algorithm is first trained using training set After finding the best RMS value the same model is run using test set to check the accuracy of the outcomes..
  • 9.
    BASICS OF MACHINELEARNING Validation Set A new partition is introduced to prevent the overfitting problem of the ML model. This helps model to stay unaware of the too many things.
  • 10.
    BASICS OF MACHINELEARNING Feature Engineering The data columns or properties are converted into ML model consumable features
  • 11.
    BASICS OF MACHINELEARNING Good vs Bad Features The features must follow certain rules to simplify the process of ML training thus reducing the cost and time to train the model and easier to debug and verify the predictions. house_type: victorian unique_house_id: 8SK982ZZ1242Z house_age_years: 27 house_age: 851472000 quality_rating: - 1
  • 12.
    BASICS OF MACHINELEARNING Data Cleaning The dataset most often doesn’t come to ML engineers in the most suitable way. It contains many impurities and sometimes even false information stored within the system due to human errors, etc..
  • 13.
    TENSORFLOW Tensorflow Tensorflow is acomputational framework for building machine learning models. TensorFlow provides a variety of different toolkits that allow you to construct models at your preferred level of abstraction. You can use lower-level APIs to build models by defining a series of mathematical operations. Alternatively, you can use higher-level APIs (like tf.estimator) to specify predefined architectures, such as linear regressors or neural networks.
  • 14.
    TENSORFLOW Pseudo Code import tensorflowas tf # Set up a linear classifier. classifier = tf.estimator.LinearClassifier(feature_columns) # Train the model on some example data. classifier.train(input_fn=train_input_fn, steps=2000) # Use it to predict. predictions = classifier.predict(input_fn=predict_input_fn)
  • 15.
    TENSORFLOW Full Code from __future__import print_function import math from IPython import display import numpy as np import pandas as pd from sklearn import metrics import tensorflow as tf from tensorflow.python.data import Dataset tf.logging.set_verbosity(tf.logging.ERROR) pd.options.display.max_rows = 10 pd.options.display.float_format = '{:.1f}'.format california_housing_dataframe = pd.read_csv("https://download.mlcc.google.com/mledu- datasets/california_housing_train.csv", sep=",") california_housing_dataframe = california_housing_dataframe.reindex( np.random.permutation(california_housing_dataframe.index)) california_housing_dataframe["median_house_value"] /= 1000.0 california_housing_dataframe # Define the input feature: total_rooms. my_feature = california_housing_dataframe[["total_rooms"]] # Configure a numeric feature column for total_rooms. feature_columns = [tf.feature_column.numeric_column("total_rooms")] # Define the label. targets = california_housing_dataframe["median_house_value"] # Use gradient descent as the optimizer for training the model. my_optimizer=tf.train.GradientDescentOptimizer(learning_rate=0.0000001) my_optimizer = tf.contrib.estimator.clip_gradients_by_norm(my_optimizer, 5.0) # Configure the linear regression model with our feature columns and optimizer. # Set a learning rate of 0.0000001 for Gradient Descent. linear_regressor = tf.estimator.LinearRegressor( feature_columns=feature_columns, optimizer=my_optimizer ) def my_input_fn(features, targets, batch_size=1, shuffle=True, num_epochs=None): """Trains a linear regression model of one feature. """ # Convert pandas data into a dict of np arrays. features = {key:np.array(value) for key,value in dict(features).items()} # Construct a dataset, and configure batching/repeating. ds = Dataset.from_tensor_slices((features,targets)) # warning: 2GB limit ds = ds.batch(batch_size).repeat(num_epochs) # Shuffle the data, if specified. if shuffle: ds = ds.shuffle(buffer_size=10000) # Return the next batch of data. features, labels = ds.make_one_shot_iterator().get_next() return features, labels _ = linear_regressor.train( input_fn = lambda:my_input_fn(my_feature, targets), steps=100 )
  • 16.
    Thanks! You can findme at: vatsalm@dysonspherelab.com Any questions?