输出结果
核心代码
tf_lr = skflow.TensorFlowLinearRegressor(steps=10000, learning_rate=0.01, batch_size=50)
tf_lr.fit(X_train, y_train)
tf_lr_y_predict = tf_lr.predict(X_test)
tf_dnn_regressor = skflow.TensorFlowDNNRegressor(hidden_units=[100, 40],
steps=10000, learning_rate=0.01, batch_size=50)
tf_dnn_regressor.fit(X_train, y_train)
tf_dnn_regressor_y_predict = tf_dnn_regressor.predict(X_test)
rfr = RandomForestRegressor()
rfr.fit(X_train, y_train)
rfr_y_predict = rfr.predict(X_test)
class TensorFlowLinearRegressor(TensorFlowEstimator, RegressorMixin):
"""TensorFlow Linear Regression model."""
def __init__(self, n_classes=0, tf_master="", batch_size=32, steps=200, optimizer="SGD",
learning_rate=0.1, tf_random_seed=42, continue_training=False,
num_cores=4, verbose=1, early_stopping_rounds=None,
max_to_keep=5, keep_checkpoint_every_n_hours=10000):
super(TensorFlowLinearRegressor, self).__init__(model_fn=models.linear_regression,
n_classes=n_classes, tf_master=tf_master, batch_size=batch_size, steps=steps,
optimizer=optimizer, learning_rate=learning_rate, tf_random_seed=tf_random_seed,
continue_training=continue_training, num_cores=num_cores, verbose=verbose,
early_stopping_rounds=early_stopping_rounds, max_to_keep=max_to_keep,
keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours)
@property
def weights_(self):
"""Returns weights of the linear regression."""
return self.get_tensor_value('linear_regression/weights:0')
@property
def bias_(self):
"""Returns bias of the linear regression."""
return self.get_tensor_value('linear_regression/bias:0')