- Provide Boiler Plate code
- tf.estimator - High level API for production ready models
- Python API treats tensorflow as numeric processing library
- Quick Model
- Checkpointing
- Distributed Training
- Train / Eval / Monitor
- Out of memory datasets
- Hyper parameter tuning
- tf.estimator.Estimator
- Linear (LinearRegressor)
- Dense Neural Networks (DNNRegressor, DNNLinearCombinedRegressor)
- LinearClassifier, DNNClassifier, DNNLinearCombinedClassifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Happy Learning!!!
No comments:
Post a Comment