parameters: (csv_file_name=_DATA_FILE, training_steps=200)
return_statement: return times, observed, all_times, predicted_mean
docstring: Train and predict using a custom time series model.
docstring_summary: Train and predict using a custom time series model.
docstring_tokens: Train and predict using a custom time series model .
function: def train_and_predict(csv_file_name=_DATA_FILE, training_steps=200):
    """Train and predict using a custom time series model."""
    # Construct an Estimator from our LSTM model.
    estimator = ts_estimators._TimeSeriesRegressor(
        model=_LSTMModel(num_features=5, num_units=128),
        optimizer=tf.train.AdamOptimizer(0.001))
    reader = tf.contrib.timeseries.CSVReader(
        csv_file_name,
        column_names=((tf.contrib.timeseries.TrainEvalFeatures.TIMES,)
                      + (tf.contrib.timeseries.TrainEvalFeatures.VALUES,) * 5))
    train_input_fn = tf.contrib.timeseries.RandomWindowInputFn(
        reader, batch_size=4, window_size=32)
    estimator.train(input_fn=train_input_fn, steps=training_steps)
    evaluation_input_fn = tf.contrib.timeseries.WholeDatasetInputFn(reader)
    evaluation = estimator.evaluate(input_fn=evaluation_input_fn, steps=1)
    # Predict starting after the evaluation
    (predictions,) = tuple(estimator.predict(
        input_fn=tf.contrib.timeseries.predict_continuation_input_fn(
            evaluation, steps=100)))
    times = evaluation["times"][0]
    observed = evaluation["observed"][0, :, :]
    predicted_mean = numpy.squeeze(numpy.concatenate(
        [evaluation["mean"][0], predictions["mean"]], axis=0))
    all_times = numpy.concatenate([times, predictions["times"]], axis=0)
    return times, observed, all_times, predicted_mean
function_tokens: def train_and_predict ( csv_file_name = _DATA_FILE , training_steps = 200 ) : # Construct an Estimator from our LSTM model. estimator = ts_estimators . _TimeSeriesRegressor ( model = _LSTMModel ( num_features = 5 , num_units = 128 ) , optimizer = tf . train . AdamOptimizer ( 0.001 ) ) reader = tf . contrib . timeseries . CSVReader ( csv_file_name , column_names = ( ( tf . contrib . timeseries . TrainEvalFeatures . TIMES , ) + ( tf . contrib . timeseries . TrainEvalFeatures . VALUES , ) * 5 ) ) train_input_fn = tf . contrib . timeseries . RandomWindowInputFn ( reader , batch_size = 4 , window_size = 32 ) estimator . train ( input_fn = train_input_fn , steps = training_steps ) evaluation_input_fn = tf . contrib . timeseries . WholeDatasetInputFn ( reader ) evaluation = estimator . evaluate ( input_fn = evaluation_input_fn , steps = 1 ) # Predict starting after the evaluation ( predictions , ) = tuple ( estimator . predict ( input_fn = tf . contrib . timeseries . predict_continuation_input_fn ( evaluation , steps = 100 ) ) ) times = evaluation [ "times" ] [ 0 ] observed = evaluation [ "observed" ] [ 0 , : , : ] predicted_mean = numpy . squeeze ( numpy . concatenate ( [ evaluation [ "mean" ] [ 0 ] , predictions [ "mean" ] ] , axis = 0 ) ) all_times = numpy . concatenate ( [ times , predictions [ "times" ] ] , axis = 0 ) return times , observed , all_times , predicted_mean