"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

August 24, 2018

Day #121 - Tensorflow Notes

Estimators
  • Provide Boiler Plate code
  • tf.estimator - High level API for production ready models
  • Python API treats tensorflow as numeric processing library
Estimator API
  • Quick Model
  • Checkpointing
  • Distributed Training
  • Train / Eval / Monitor
  • Out of memory datasets
  • Hyper parameter tuning
Base class
  • tf.estimator.Estimator
  • Linear (LinearRegressor)
  • Dense Neural Networks (DNNRegressor, DNNLinearCombinedRegressor)
  • LinearClassifier, DNNClassifier, DNNLinearCombinedClassifier

import tensorflow as tf
categorical_column = tf.feature_column.categorical_column_with_vocabulary_list(key="type", vocabulary_list=["house","apt"])
featcols = [
tf.feature_column.numeric_column("sq_footage"),
tf.feature_column.indicator_column(categorical_column)
]
initializer=tf.zeros_initializer()
#featcols = [
#tf.feature_column.numeric_column("sq_footage"),
#tf.feature_column.categorical_column_with_vocabulary_list("type",["house","apt"])
#]
#model = tf.estimator.LinearRegressor(featcols)
#instantiate linear regressor based on feilds
#3 and 2 Neurons
model = tf.estimator.DNNRegressor(feature_columns=featcols,hidden_units=[3,2])
#model = tf.estimator.DNNRegressor(feature_columns=featcols, hidden_units=[3,2],dropout=0.2,optimizer="Adam")
#LinearRegressor - computes weighted sum of all input elements
#Many more options
#tf.feature_column.bucketized_column
#tf.feature_column.embedding_column
#tf.feature_column.crossed_column
#tf.feature_column.categorical_column_with_hash_bucket
# 3 houses, 3 apartments
def train_input_fn():
features = {"sq_footage":[1000,2000,3000,1000,2000,3000],"type":["house","house","house","apt","apt","apt"]}
labels = [500,1000,1500,700,1300,1900]
return features, labels
#trains on this batch
#train for 100 steps
model.train(train_input_fn,steps=100)
def predict_input_fn():
features = {"sq_footage":[1500,1800], "type":["house","apt"]}
return features
predictions = model.predict(predict_input_fn)
#to print values
print(next(predictions))
view raw tensor2.py hosted with ❤ by GitHub

Happy Learning!!!

No comments: