- 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. 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 −

print("Separating the label from features") train_features = train_dataset.copy() test_features = test_dataset.copy() train_labels = train_features.pop('MPG') test_labels = test_features.pop('MPG') print("The mean and standard deviation of the training dataset : ") train_dataset.describe().transpose()[['mean', 'std']] print("Normalize the features since they use different scales") print("Creating the normalization layer") normalizer = preprocessing.Normalization() normalizer.adapt(np.array(train_features)) print(normalizer.mean.numpy()) first = np.array(train_features[3:4]) print("Every feature has been individually normalized") with np.printoptions(precision=2, suppress=True): print('First example is :', first) print() print('Normalized data :', normalizer(first).numpy())

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

Separating the label from features The mean and standard deviation of the training dataset : Normalize the features since they use different scales Creating the normalization layer [ 5.467 193.847 104.135 2976.88 15.591 75.934 0.168 0.197 0.635] Every feature has been individually normalized First example is : [[ 4. 105. 63. 2125. 14.7 82. 0. 0. 1. ]] Normalized data : [[−0.87 −0.87 −1.11 −1.03 −0.33 1.65 −0.45 −0.5 0.76]]

The target value (label) is separated from the features.

The label is the value that needs to be trained for the predictions to occur.

The features are normalized so that the training is stable.

The ‘Normalization’ function in Tensorflow preprocesses the data.

A first layer is created, and the mean and variances are stored in this layer.

When this layer is called, it returns the input data where every feature has been normalized.

- Related Questions & Answers
- How can data be cleaned to predict the fuel efficiency with Auto MPG dataset using TensorFlow?
- How can data be imported to predict the fuel efficiency with Auto MPG dataset (basic regression) 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 Tensorflow be used to predict values on the new data for the augmented data?
- How can Tensorflow be used to predict a score for stackoverflow question dataset on every label using Python?

Advertisements