<jupyter_start><jupyter_text>[View in Colaboratory](https://colab.research.google.com/github/AmoDinho/Machine-Learning-Crash-Course-with-TF/blob/master/examples/NYC_Taxis_I.ipynb)  NYC Taxi Trip Data for 2016The goal of this study is to try and predict the the total trip amount. We will use Tensorflow to do this. But most importantly we will use linear regression. Learning Objectives* Use the LinearRefressor class in TF tp predict the number the shares based on the number of words in the content.  Setup<jupyter_code>import math

from IPython import display
from matplotlib import cm
from matplotlib import gridspec
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
from sklearn import metrics
import tensorflow as tf
from tensorflow.python.data import Dataset

tf.logging.set_verbosity(tf.logging.ERROR)
pd.options.display.max_rows = 10
pd.options.display.float_format = '{:.1f}'.format<jupyter_output><empty_output><jupyter_text>Lets load our dataset<jupyter_code>df_taxi = pd.read_csv("https://storage.googleapis.com/machinelearning_datasets/tlc_yellow_trips_2016.csv", sep=",")
df_taxi.info()
df_taxi.describe()<jupyter_output><empty_output><jupyter_text>Preprocess Features<jupyter_code>def preprocess_features(df_taxi):
  """
  Prepares input features from df_taxi data set.

  Args:
    df_taxi: A Pandas DataFrame expected to contain data
      from the NYC Taxi data set.
  Returns:
    A DataFrame that contains the features to be used for the model, including
    synthetic features.
  """
  
  selected_features = df_taxi[
      ["vendor_id",          
       "passenger_count",
       "trip_distance",
       "fare_amount",   
       "extra",          
        "mta_tax",
       "tip_amount",       
       "tolls_amount",  
       "imp_surcharge",
       "total_amount"]]
  
  processed_features = selected_features.copy()
  return processed_features


def preprocess_targets(df_taxi):
  """
  Prepares target features (i.e., labels) from df_taxi data set.

  Args:
    df_taxi: A Pandas DataFrame expected to contain data
      from the California housing data set.
  Returns:
    A DataFrame that contains the target feature.
  """
  
  output_targets = pd.DataFrame()
  output_targets["total_amount"] = df_taxi["total_amount"]
  return output_targets
#Determine number of training examples
training_examples = preprocess_features(df_taxi.head(1600))
training_targets = preprocess_targets(df_taxi.head(1600))

#Determine number of validation examples

validation_examples = preprocess_features(df_taxi.tail(400))
validation_targets = preprocess_targets(df_taxi.tail(400))


# Double-check that we've done the right thing.
print ("Training examples summary:")
display.display(training_examples.describe())
print ("Validation examples summary:")
display.display(validation_examples.describe())

print ("Training targets summary:")
display.display(training_targets.describe())
print ("Validation targets summary:")
display.display(validation_targets.describe())<jupyter_output>Training examples summary:<jupyter_text>Lets make a goood feature setwe will use a correlation matrix<jupyter_code>corr_df = training_examples.copy()
corr_df["target"] = training_targets["total_amount"]
corr_df.corr()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08751529987760098, 'fraction_numerical': 0.007649938800489596, 'mean_word_length': 4.9653284671532845, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '151351', 'license': 'MIT', 'n_tokens_mistral': 1052, 'n_tokens_neox': 978, 'n_words': 270, 'path': 'examples/NYC_Taxis_I.ipynb', 'repo_name': 'AmoDinho/Machine-Learning-Crash-with-TF', 'size': '3268'}