- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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 to predict the fuel efficiency with Auto MPG dataset −

import matplotlib.pyplot as plt import numpy as np import pandas as pd import seaborn as sns np.set_printoptions(precision=3, suppress=True) import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras.layers.experimental import preprocessing print("The version of tensorflow is ") print(tf.__version__) url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data' column_names = ['MPG', 'Cylinders', 'Displacement', 'Horsepower', 'Weight', 'Acceleration', 'Model Year', 'Origin'] print("The data is being loaded") print("The column names have been defined") raw_dataset = pd.read_csv(url, names=column_names, na_values='?', comment='\t', sep=' ', skipinitialspace=True) dataset = raw_dataset.copy() print("A sample of the dataset") dataset.head(2)

Code credit − https://www.tensorflow.org/tutorials/keras/regression

The version of tensorflow is 2.4.0 The data is being loaded The column names have been defined A sample of the dataset

sl. | MPG | Cylinders | Displacement | horsepower | weight | Acceleration | Model Year | Origin |
---|---|---|---|---|---|---|---|---|

0 | 18.0 | 8 | 307.0 | 130.0 | 3504.0 | 12.0 | 70 | 1 |

1 | 15.0 | 8 | 350.0 | 165.0 | 3693.0 | 11.5 | 70 | 1 |

The required packages are imported and aliased.

The data is loaded, and column names are defined for it.

A sample of the dataset is displayed on the console.

- Related Questions & Answers
- How can data be normalized to predict the fuel efficiency with Auto MPG dataset using TensorFlow?
- How can data be cleaned to predict the fuel efficiency with Auto MPG dataset using TensorFlow?
- How can data be split and inspected to predict the fuel efficiency with Auto MPG dataset using TensorFlow?
- How can predictions be made about the fuel efficiency with Auto MPG dataset using TensorFlow?
- How can model be fit to data with Auto MPG dataset using TensorFlow?
- How can predictions be made on Auto MPG dataset using TensorFlow?
- How can a DNN (deep neural network) model be used to predict MPG values on Auto MPG dataset using TensorFlow?
- How can a sequential model be built on Auto MPG dataset using TensorFlow?
- How can a DNN (deep neural network) model be built on Auto MPG dataset using TensorFlow?
- How can model be evaluated based on Auto MPG using TensorFlow?
- How can a sequential model be built on Auto MPG using TensorFlow?
- How can Tensorflow and Estimators be used to predict the output of the titanic dataset?
- How can Tensorflow be used with Estimator to predict the output using Python?
- How can Logistic Regression be implemented using TensorFlow?
- How can Linear Regression be implemented using TensorFlow?

Advertisements