# How can model be fit to data with Auto MPG dataset using TensorFlow?

PythonServer Side ProgrammingProgramming

Tensorflow is a machine learning framework that is provided by Google. It is an open−source framework used in conjunction with Python to implement algorithms, deep learning applications and much more. It is used in research and for production purposes.

The ‘tensorflow’ package can be installed on Windows using the below line of code −

pip install tensorflow

Tensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but multidimensional array or a list.

The aim behind a regression problem is to predict the output of a continuous or discrete variable, such as a price, probability, whether it would rain or not and so on.

The dataset we use is called the ‘Auto MPG’ dataset. It contains fuel efficiency of 1970s and 1980s automobiles. It includes attributes like weight, horsepower, displacement, and so on. With this, we need to predict the fuel efficiency of specific vehicles.

We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook. Following is the code snippet −

## Example

print("The training data is being fit to the model ")
history = hrspwr_model.fit(
train_features['Horsepower'], train_labels,
epochs=150,
verbose=0,
validation_split = 0.3)

hist = pd.DataFrame(history.history)
hist['epoch'] = history.epoch
hist.tail()

## Output ## Explanation

• The data is fit to the model using the ‘fit’ function.

• The number of steps is set using the ‘epochs’ attribute.

• The ‘history’ object stores the progress of the statistics associated with the input data.

• It is converted into a dataframe.

• A sample of the data is displayed on the console.

• The data is also visualized.
{"ft_lang_label":"__label__en","ft_lang_prob":0.86939895,"math_prob":0.7600593,"size":1924,"snap":"2021-43-2021-49","text_gpt3_token_len":414,"char_repetition_ratio":0.1,"word_repetition_ratio":0.0,"special_character_ratio":0.21101871,"punctuation_ratio":0.11898017,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9852258,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-24T22:05:21Z\",\"WARC-Record-ID\":\"<urn:uuid:839e6d84-21fd-4b40-a72f-cda9a4f55083>\",\"Content-Length\":\"33339\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f26b6c4d-dcf4-49b6-b903-77266f2f4fcb>\",\"WARC-Concurrent-To\":\"<urn:uuid:338dc514-a29b-424f-90fb-2064314bed92>\",\"WARC-IP-Address\":\"72.21.91.42\",\"WARC-Target-URI\":\"https://www.tutorialspoint.com/how-can-model-be-fit-to-data-with-auto-mpg-dataset-using-tensorflow\",\"WARC-Payload-Digest\":\"sha1:6RX2GSP4HREJ2YAV7UF44N6AIDUZL6YM\",\"WARC-Block-Digest\":\"sha1:DHTFV3IXDPHIWFSIRSTFN4ZJIIEMNF3E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587606.8_warc_CC-MAIN-20211024204628-20211024234628-00260.warc.gz\"}"}