当前位置: 首页>>代码示例>>Python>>正文


Python learn.infer_real_valued_columns_from_input方法代码示例

本文整理汇总了Python中tensorflow.contrib.learn.infer_real_valued_columns_from_input方法的典型用法代码示例。如果您正苦于以下问题:Python learn.infer_real_valued_columns_from_input方法的具体用法?Python learn.infer_real_valued_columns_from_input怎么用?Python learn.infer_real_valued_columns_from_input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.contrib.learn的用法示例。


在下文中一共展示了learn.infer_real_valued_columns_from_input方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from tensorflow.contrib import learn [as 别名]
# 或者: from tensorflow.contrib.learn import infer_real_valued_columns_from_input [as 别名]
def main(unused_argv):
  iris = load_iris()
  x_train, x_test, y_train, y_test = cross_validation.train_test_split(
      iris.data, iris.target, test_size=0.2, random_state=42)

  # It's useful to scale to ensure Stochastic Gradient Descent
  # will do the right thing.
  scaler = StandardScaler()

  # DNN classifier.
  classifier = learn.DNNClassifier(
      feature_columns=learn.infer_real_valued_columns_from_input(x_train),
      hidden_units=[10, 20, 10], n_classes=3)

  pipeline = Pipeline([('scaler', scaler),
                       ('DNNclassifier', classifier)])

  pipeline.fit(x_train, y_train, DNNclassifier__steps=200)

  score = accuracy_score(y_test, list(pipeline.predict(x_test)))
  print('Accuracy: {0:f}'.format(score)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:iris_with_pipeline.py

示例2: main

# 需要导入模块: from tensorflow.contrib import learn [as 别名]
# 或者: from tensorflow.contrib.learn import infer_real_valued_columns_from_input [as 别名]
def main(unused_argv):
  # Load dataset.
  iris = learn.datasets.load_dataset('iris')
  x_train, x_test, y_train, y_test = cross_validation.train_test_split(
      iris.data, iris.target, test_size=0.2, random_state=42)

  # Build 3 layer DNN with 10, 20, 10 units respectively.
  feature_columns = learn.infer_real_valued_columns_from_input(x_train)
  classifier = learn.DNNClassifier(
      feature_columns=feature_columns, hidden_units=[10, 20, 10], n_classes=3)

  # Fit and predict.
  classifier.fit(x_train, y_train, steps=200)
  predictions = list(classifier.predict(x_test, as_iterable=True))
  score = metrics.accuracy_score(y_test, predictions)
  print('Accuracy: {0:f}'.format(score)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:iris.py

示例3: main

# 需要导入模块: from tensorflow.contrib import learn [as 别名]
# 或者: from tensorflow.contrib.learn import infer_real_valued_columns_from_input [as 别名]
def main(unused_argv):
  # Load dataset
  boston = learn.datasets.load_dataset('boston')
  x, y = boston.data, boston.target

  # Split dataset into train / test
  x_train, x_test, y_train, y_test = cross_validation.train_test_split(
      x, y, test_size=0.2, random_state=42)

  # Scale data (training set) to 0 mean and unit standard deviation.
  scaler = preprocessing.StandardScaler()
  x_train = scaler.fit_transform(x_train)

  # Build 2 layer fully connected DNN with 10, 10 units respectively.
  feature_columns = learn.infer_real_valued_columns_from_input(x_train)
  regressor = learn.DNNRegressor(
      feature_columns=feature_columns, hidden_units=[10, 10])

  # Fit
  regressor.fit(x_train, y_train, steps=5000, batch_size=1)

  # Predict and score
  y_predicted = list(
      regressor.predict(scaler.transform(x_test), as_iterable=True))
  score = metrics.mean_squared_error(y_predicted, y_test)

  print('MSE: {0:f}'.format(score)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:29,代码来源:boston.py

示例4: main

# 需要导入模块: from tensorflow.contrib import learn [as 别名]
# 或者: from tensorflow.contrib.learn import infer_real_valued_columns_from_input [as 别名]
def main(unused_argv):
  iris = datasets.load_iris()
  x_train, x_test, y_train, y_test = train_test_split(
      iris.data, iris.target, test_size=0.2, random_state=42)

  x_train, x_val, y_train, y_val = train_test_split(
      x_train, y_train, test_size=0.2, random_state=42)
  val_monitor = learn.monitors.ValidationMonitor(
      x_val, y_val, early_stopping_rounds=200)

  model_dir = '/tmp/iris_model'
  clean_folder(model_dir)

  # classifier with early stopping on training data
  classifier1 = learn.DNNClassifier(
      feature_columns=learn.infer_real_valued_columns_from_input(x_train),
      hidden_units=[10, 20, 10], n_classes=3, model_dir=model_dir)
  classifier1.fit(x=x_train, y=y_train, steps=2000)
  predictions1 = list(classifier1.predict(x_test, as_iterable=True))
  score1 = metrics.accuracy_score(y_test, predictions1)

  model_dir = '/tmp/iris_model_val'
  clean_folder(model_dir)

  # classifier with early stopping on validation data, save frequently for
  # monitor to pick up new checkpoints.
  classifier2 = learn.DNNClassifier(
      feature_columns=learn.infer_real_valued_columns_from_input(x_train),
      hidden_units=[10, 20, 10], n_classes=3, model_dir=model_dir,
      config=tf.contrib.learn.RunConfig(save_checkpoints_secs=1))
  classifier2.fit(x=x_train, y=y_train, steps=2000, monitors=[val_monitor])
  predictions2 = list(classifier2.predict(x_test, as_iterable=True))
  score2 = metrics.accuracy_score(y_test, predictions2)

  # In many applications, the score is improved by using early stopping
  print('score1: ', score1)
  print('score2: ', score2)
  print('score2 > score1: ', score2 > score1) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:40,代码来源:iris_val_based_early_stopping.py

示例5: main

# 需要导入模块: from tensorflow.contrib import learn [as 别名]
# 或者: from tensorflow.contrib.learn import infer_real_valued_columns_from_input [as 别名]
def main(unused_argv):
  # Load dataset.
  iris = learn.datasets.load_dataset('iris')
  x_train, x_test, y_train, y_test = cross_validation.train_test_split(
      iris.data, iris.target, test_size=0.2, random_state=42)

  # Note that we are saving and load iris data as h5 format as a simple
  # demonstration here.
  h5f = h5py.File('/tmp/test_hdf5.h5', 'w')
  h5f.create_dataset('X_train', data=x_train)
  h5f.create_dataset('X_test', data=x_test)
  h5f.create_dataset('y_train', data=y_train)
  h5f.create_dataset('y_test', data=y_test)
  h5f.close()

  h5f = h5py.File('/tmp/test_hdf5.h5', 'r')
  x_train = np.array(h5f['X_train'])
  x_test = np.array(h5f['X_test'])
  y_train = np.array(h5f['y_train'])
  y_test = np.array(h5f['y_test'])

  # Build 3 layer DNN with 10, 20, 10 units respectively.
  feature_columns = learn.infer_real_valued_columns_from_input(x_train)
  classifier = learn.DNNClassifier(
      feature_columns=feature_columns, hidden_units=[10, 20, 10], n_classes=3)

  # Fit and predict.
  classifier.fit(x_train, y_train, steps=200)
  score = metrics.accuracy_score(y_test, classifier.predict(x_test))
  print('Accuracy: {0:f}'.format(score)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:32,代码来源:hdf5_classification.py


注:本文中的tensorflow.contrib.learn.infer_real_valued_columns_from_input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。