2017-09-04 106 views
1

我使用jupyter筆記本來編寫深度神經網絡代碼。嘗試創建DNNClassifier時遇到此問題。tensorflow.contrib.learn.DNNclassifier缺少1個必需的位置參數:'feature_columns'

import tensorflow.contrib.learn as learn 
classifier = learn.DNNClassifier(hidden_units=[10, 20, 10], n_classes=2) 

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-30-0273d6847e2b> in <module>() 
----> 1 classifier = learn.DNNClassifier(hidden_units=[10, 20, 10], n_classes=2) 

TypeError: __init__() missing 1 required positional argument: 'feature_columns' 

回答

1

你需要傳遞正確的參數tf.contrib.learn.DNNClassifier,在這裏你沒有通過feature_columns說法。

例如,你可以使用real_valued_column作爲features_columns

feature_columns = [tf.contrib.layers.real_valued_column("", dimension=1)] 
classifier = learn.DNNClassifier(feature_columns=feature_columns, hidden_units=[10, 20, 10], n_classes=2) 
相關問題