Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Create a project to use TensorFlow for an application. Define and implement your project. (100 points) Submit one paragraph project description by Nov 27 in class.

1 answer below »

Create a project to use TensorFlow for an application.
Define and implement your project. (100 points)
Submit one paragraph project description by Nov 27 in class.
Answered Same Day Dec 18, 2021

Solution

Ximi answered on Dec 18 2021
139 Votes
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Copy of first_steps_with_tensor_flow.ipynb",
"provenance": [],
"collapsed_sections": [
"JndnmDMp66FL",
"ajVM7rkoYXeL",
"ci1ISxxrZ7v0"
]
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "4f3CKqFUqL2-",
"colab_type": "text"
},
"source": [
"# First Steps with TensorFlow"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Bd2Zkk1LE2Zr",
"colab_type": "text"
},
"source": [
"**Learning Objectives:**\n",
" * Learn fundamental TensorFlow concepts\n",
" * Use the `LinearRegressor` class in TensorFlow to predict median housing price, at the granularity of city blocks, based on one input feature\n",
" * Evaluate the accuracy of a model's predictions using Root Mean Squared E
or (RMSE)\n",
" * Improve the accuracy of a model by tuning its hyperparameters"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "MxiIKhP4E2Zr",
"colab_type": "text"
},
"source": [
"The [data](https:
developers.google.com/machine-learning/crash-course/california-housing-data-description) is based on 1990 census data from California."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6TjLjL9IU80G",
"colab_type": "text"
},
"source": [
"## Setup\n",
"In this first cell, we'll load the necessary li
aries."
]
},
{
"cell_type": "code",
"metadata": {
"id": "rVFf5asKE2Zt",
"colab_type": "code",
"colab": {}
},
"source": [
"from __future__ import print_function\n",
"\n",
"import math\n",
"\n",
"from IPython import display\n",
"from matplotlib import cm\n",
"from matplotlib import gridspec\n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn import metrics\n",
"%tensorflow_version 1.x\n",
"import tensorflow as tf\n",
"from tensorflow.python.data import Dataset\n",
"\n",
"tf.logging.set_ve
osity(tf.logging.ERROR)\n",
"pd.options.display.max_rows = 10\n",
"pd.options.display.float_format = '{:.1f}'.format"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "ipRyUHjhU80Q",
"colab_type": "text"
},
"source": [
"Next, we'll load our data set."
]
},
{
"cell_type": "code",
"metadata": {
"id": "9ivCDWnwE2Zx",
"colab_type": "code",
"colab": {}
},
"source": [
"california_housing_dataframe = pd.read_csv(\"https:
download.mlcc.google.com/mledu-datasets/california_housing_train.csv\", sep=\",\")"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "vVk_qlG6U80j",
"colab_type": "text"
},
"source": [
"We'll randomize the data, just to be sure not to get any pathological ordering effects that might harm the performance of Stochastic Gradient Descent. Additionally, we'll scale `median_house_value` to be in units of thousands, so it can be learned a little more easily with learning rates in a range that we usually use."
]
},
{
"cell_type": "code",
"metadata": {
"id": "r0eVyguIU80m",
"colab_type": "code",
"colab": {}
},
"source": [
"california_housing_dataframe = california_housing_dataframe.reindex(\n",
" np.random.permutation(california_housing_dataframe.index))\n",
"california_housing_dataframe[\"median_house_value\"] /= 1000.0\n",
"california_housing_dataframe"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "HzzlSs3PtTmt",
"colab_type": "text"
},
"source": [
"## Examine the Data\n",
"\n",
"It's a good idea to get to know our data a little bit before we work with it.\n",
"\n",
"We'll print out a quick summary of a few useful statistics on each column: count of examples, mean, standard deviation, max, min, and various quantiles."
]
},
{
"cell_type": "code",
"metadata": {
"id": "gzb10yoVrydW",
"colab_type": "code",
"cellView": "both",
"colab": {
"test": {
"output": "ignore",
"timeout": 600
}
}
},
"source": [
"california_housing_dataframe.describe()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "Lr6wYl2bt2Ep",
"colab_type": "text"
},
"source": [
"## Build the First Model\n",
"\n",
"In this exercise, we'll try to predict `median_house_value`, which will be our label (sometimes also called a target). We'll use `total_rooms` as our input feature.\n",
"\n",
"**NOTE:** Our data is at the city block level, so this feature represents the total number of rooms in that block.\n",
"\n",
"To train our model, we'll use the [LinearRegressor](https:
www.tensorflow.org/api_docs/python/tf/estimato
LinearRegressor) interface provided by the TensorFlow [Estimator](https:
www.tensorflow.org/get_started/estimator) API. This API takes care of a lot of the low-level model plumbing, and exposes convenient methods for performing model training, evaluation, and inference."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0cpcsieFhsNI",
"colab_type": "text"
},
"source": [
"### Step 1: Define Features and Configure Feature Columns"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "EL8-9d4ZJNR7",
"colab_type": "text"
},
"source": [
"In order to import our training data into TensorFlow, we need to specify what type of data each feature contains. There are two main types of data we'll use in this and future exercises:\n",
"\n",
"* **Categorical Data**: Data that is textual. In this exercise, our housing data set does not contain any categorical features, but examples we might see would be the home style, the words in a real-estate ad.\n",
"\n",
"* **Numerical Data**: Data that is a number (integer or float) and that we want to treat as a number. As we will discuss more later sometimes we might want to...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here