Reader small image

You're reading from  Mobile Artificial Intelligence Projects

Product typeBook
Published inMar 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789344073
Edition1st Edition
Languages
Right arrow
Authors (3):
Karthikeyan NG
Karthikeyan NG
author image
Karthikeyan NG

Karthikeyan NG is the Head of Engineering and Technology at the Indian lifestyle and fashion retail brand. He served as a software engineer at Symantec Corporation and has worked with 2 US-based startups as an early employee and has built various products. He has 9+ years of experience in various scalable products using Web, Mobile, ML, AR, and VR technologies. He is an aspiring entrepreneur and technology evangelist. His interests lie in exploring new technologies and innovative ideas to resolve a problem. He has also bagged prizes from more than 15 hackathons, is a TEDx speaker and a speaker at technology conferences and meetups as well as guest lecturer at a Bengaluru University. When not at work, he is found trekking.
Read more about Karthikeyan NG

Arun Padmanabhan
Arun Padmanabhan
author image
Arun Padmanabhan

Arun Padmanabhan is a Machine Learning consultant with over 8 years of experience building end-to-end machine learning solutions and applications. Currently working with a couple of start-ups in the Financial and Insurance industries, he specializes in automating manual workflows using AI and creating Machine Vision and NLP applications. In past, he has led the data science team of a Singapore based product startup in the restaurant domain. He also has built stand-alone and integrated Machine Learning solutions in the Manufacturing, Shipping and e-commerce domains over the years. His interests are in research, development and applications of Artificial Intelligence and Deep Architectures.
Read more about Arun Padmanabhan

Matt Cole
Matt Cole
author image
Matt Cole

Matt R. Cole is a developer and author with 30 years' experience. Matt is the owner of Evolved AI Solutions, a provider of advanced Machine Learning/Bio-AI, Microservice and Swarm technologies. Matt is recognized as a leader in Microservice and Artificial Intelligence development and design. As an early pioneer of VOIP, Matt developed the VOIP system for NASA for the International Space Station and Space Shuttle. Matt also developed the first Bio Artificial Intelligence framework which completely integrates mirror and canonical neurons. In his spare time Matt authors books, and continues his education taking every available course in advanced mathematics, AI/ML/DL, Quantum Mechanics/Physics, String Theory and Computational Neuroscience.
Read more about Matt Cole

View More author details
Right arrow

Creating a Real-Estate Price Prediction Mobile App

In the previous chapter, we covered the theoretical fundamentals; this chapter, on the other hand, will cover the setup of all the tools and libraries.

First, we are going to set up our environment to build a Keras model to predict house prices with real estate data. Then we are going to serve this model using a RESTful API built using Flask. Next, we will set up our environment for Android and create an app that will consume this RESTful API to predict the house price based on features of real estate. Finally, we will repeat the same exercise for iOS.

The focus of this chapter is on the setup, tools, libraries, and exercising the concepts learned in Chapter 1, Artificial Intelligence Concepts and Fundamentals. The use case is designed to be simple, yet adaptable enough to accommodate similar use-cases. By the end of the chapter...

Setting up the artificial intelligence environment

The first thing to do is install Python. We are going to use Python throughout this book for all our artificial intelligence (AI) tasks. There are two ways to install Python, either through the downloadable executable file provided from https://www.python.org/downloads/ or via Anaconda. Our approach will be the latter, that is, using Anaconda.

Downloading and installing Anaconda

Building an ANN model for prediction using Keras and TensorFlow

Now that we have our libraries installed, let's create a folder called aibook and within that create another folder called chapter2. Move all the code for this chapter into the chapter2 folder. Make sure that the conda environment is still active (the prompt will start with the environment name):

Once within the chapter2 folder, type jupyter notebook. This will open an interactive Python editor on the browser.

Use the New dropdown in the top-right corner to create a new Python 3 notebook:

We are now ready to build our first ANN using Keras and TensorFlow, to predict real estate prices:

  1. Import all the libraries that we need for this exercise. Use the first cell to import all the libraries and run it. Here are the four main libraries we will use:
    • pandas: We use this to read the data and store it in a dataframe...

Serving the model as an API

Now that we have created a model for prediction, the next thing is to serve this model via a RESTful API. To achieve this, we will use lightweight Python framework called Flask: http://flask.pocoo.org/.

Let's start by installing the Flask library in our conda environment if it does not already exist:

pip install Flask

Building a simple API to add two numbers

Now we will build a very simple API to get a grip on the Flask library and framework. This API will accept a JSON object with two numbers and return the sum of the numbers as a response.

Open a new notebook from your Jupyter home page:

  1. Import all the libraries we need and create an app instance:
from flask import Flask, request 
app =...

Creating an Android app to predict house prices

In this section, we are going to consume the model through the RESTful API via an Android app. The purpose of this section is to demonstrate how a model can be consumed and used by an Android app. Here, we have assumed that you are familiar with the basics of Java programming. The same approach can be used for any similar use case, even on web apps. The following steps are covered in this section:

  • Downloading and installing Android Studio
  • Creating a new Android project with a single screen
  • Designing the layout of the screen
  • Adding a functionality to accept input
  • Adding a functionality to consume the RESTful API that serves the model
  • Additional notes

Downloading and installing Android Studio

...

Creating an iOS app to predict house prices

In this section, we are going to consume the model through the RESTful API via an iOS app. The purpose of this section is to demonstrate how a model can be consumed and used by an iOS app. Here, we have assumed that you are familiar with Swift programming. The same approach can be used for any similar use case. These are the following steps covered in this section:

  • Downloading and installing Xcode
  • Creating a new iOS project with a single screen
  • Designing the layout of the screen
  • Adding a functionality to accept input
  • Adding a functionality to consume the RESTful API that serves the model
  • Additional notes

Downloading and installing Xcode

You need a Mac (macOS 10.11.5 or later) to...

Summary

In this chapter, we explored the basic sequential network and consumed it on mobile devices. In the next chapter, we will take a look at a special kind of network called Convolutional Neural Networks (CNN). CNNs are the most common networks used with Machine Vision. Our goal in the next chapter is to get comfortable with machine vision and to build our own custom-purpose CNNs.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mobile Artificial Intelligence Projects
Published in: Mar 2019Publisher: PacktISBN-13: 9781789344073
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Karthikeyan NG

Karthikeyan NG is the Head of Engineering and Technology at the Indian lifestyle and fashion retail brand. He served as a software engineer at Symantec Corporation and has worked with 2 US-based startups as an early employee and has built various products. He has 9+ years of experience in various scalable products using Web, Mobile, ML, AR, and VR technologies. He is an aspiring entrepreneur and technology evangelist. His interests lie in exploring new technologies and innovative ideas to resolve a problem. He has also bagged prizes from more than 15 hackathons, is a TEDx speaker and a speaker at technology conferences and meetups as well as guest lecturer at a Bengaluru University. When not at work, he is found trekking.
Read more about Karthikeyan NG

author image
Arun Padmanabhan

Arun Padmanabhan is a Machine Learning consultant with over 8 years of experience building end-to-end machine learning solutions and applications. Currently working with a couple of start-ups in the Financial and Insurance industries, he specializes in automating manual workflows using AI and creating Machine Vision and NLP applications. In past, he has led the data science team of a Singapore based product startup in the restaurant domain. He also has built stand-alone and integrated Machine Learning solutions in the Manufacturing, Shipping and e-commerce domains over the years. His interests are in research, development and applications of Artificial Intelligence and Deep Architectures.
Read more about Arun Padmanabhan

author image
Matt Cole

Matt R. Cole is a developer and author with 30 years' experience. Matt is the owner of Evolved AI Solutions, a provider of advanced Machine Learning/Bio-AI, Microservice and Swarm technologies. Matt is recognized as a leader in Microservice and Artificial Intelligence development and design. As an early pioneer of VOIP, Matt developed the VOIP system for NASA for the International Space Station and Space Shuttle. Matt also developed the first Bio Artificial Intelligence framework which completely integrates mirror and canonical neurons. In his spare time Matt authors books, and continues his education taking every available course in advanced mathematics, AI/ML/DL, Quantum Mechanics/Physics, String Theory and Computational Neuroscience.
Read more about Matt Cole