class tf.contrib.learn.DNNClassifier
A classifier for TensorFlow DNN models.
Example:
education = sparse_column_with_hash_bucket(column_name="education",
hash_bucket_size=1000)
occupation = sparse_column_with_hash_bucket(column_name="occupation",
hash_bucket_size=1000)
education_emb = embedding_column(sparse_id_column=education, dimension=16,
combiner="sum")
occupation_emb = embedding_column(sparse_id_column=occupation, dimension=16,
combiner="sum")
estimator = DNNClassifier(
feature_columns=[education_emb, occupation_emb],
hidden_units=[1024, 512, 256])
# Or estimator using the ProximalAdagradOptimizer optimizer with
# regularization.
estimator = DNNClassifier(
feature_columns=[education_emb, occupation_emb],
hidden_units=[1024, 512, 256],
optimizer=tf.train.ProximalAdagradOptimizer(
learning_rate=0.1,
l1_regularization_strength=0.001
))
# Input builders
def input_fn_train: # returns x, Y
pass
estimator.fit(input_fn=input_fn_train)
def input_fn_eval: # returns x, Y
pass
estimator.evaluate(input_fn=input_fn_eval)
estimator.predict(x=x)
Input of fit and evaluate should have following features, otherwise there will be a KeyError:
- if
weight_column_nameis notNone, a feature withkey=weight_column_namewhose value is aTensor. - for each
columninfeature_columns:- if
columnis aSparseColumn, a feature withkey=column.namewhosevalueis aSparseTensor. - if
columnis aWeightedSparseColumn, two features: the first withkeythe id column name, the second withkeythe weight column name. Both features'valuemust be aSparseTensor. - if
columnis aRealValuedColumn, a feature withkey=column.namewhosevalueis aTensor. - - -
- if
Please login to continue.