Blogging Fusion Blog Directory the #1 blog directory and oldest directory online.

Applying AI to solve problems

Home Applying AI to solve problems

Applying AI to solve problems

Rated: 1.50 / 5 | 466 listing views Applying AI to solve problems Blogging Fusion Blog Directory

India

 

General Audience

  • Asutosh Panda
  • June 10, 2019 04:43:29 PM
SHARE THIS PAGE ON:

A Little About Us

Applying AI to solve real life problems and writing blog posts for the same.

Listing Details

Listing Statistics

Add ReviewMe Button

Review Applying AI to solve problems at Blogging Fusion Blog Directory

Add SEO Score Button

My Blogging Fusion Score

Google Adsense™ Share Program

Alexa Web Ranking: N/A

Alexa Ranking - Applying AI to solve problems

Example Ad for Applying AI to solve problems

This what your Applying AI to solve problems Blog Ad will look like to visitors! Of course you will want to use keywords and ad targeting to get the most out of your ad campaign! So purchase an ad space today before there all gone!

https://www.bloggingfusion.com

.

notice: Total Ad Spaces Available: (2) ad spaces remaining of (2)

Advertise Here?

  • Blog specific ad placement
  • Customize the title link
  • Place a detailed description
  • It appears here within the content
  • Approved within 24 hours!
  • 100% Satisfaction
  • Or 3 months absolutely free;
  • No questions asked!

Subscribe to Applying AI to solve problems

Predict the best time to commute to office by avoiding traffic jams – Machine Learning application by using PyTorch regression

Traffic jams are a big problem worldwide and this article explains how you can reduce the time spent in traffic jams which is yet another Machine Learning application. I used to spend a lot of time in traffic jams on my way to office every morning. I thought of ways to reduce the time. Backed… Read More The post Predict the best time to commute to office by avoiding traffic jams – Machine Learning application by using PyTorch regression appeared first on Simple...

Traffic jams are a big problem worldwide and this article explains how you can reduce the time spent in traffic jams which is yet another Machine Learning application.

I used to spend a lot of time in traffic jams on my way to office every morning. I thought of ways to reduce the time.

Backed by data and logic, I wanted to know the best time between 8 AM to 10.30 AM, so that I reach office the fastest. I collected data from my Ola/Uber rides and tracked time manually when I took any two wheeler.

The problem

Given the data of one month for time taken to reach office, time of start from home, indication of if any road is blocked in between and mode of transport. Need to predict the best time to start from home to reach office fastest.

The solution

I designed a Feedforward neural network using Pytorch where I feed the data and get the best time on a particular day to start for office. This can also serve as a template for PyTorch regression problems.

This is a non-linear regression problem where I have 4 variables for training (day of the week, start time from home, if any road blocked in between, mode of transport) and one output (minutes taken for the commute).

1. This is my dataset – https://drive.google.com/file/d/1Eboo0hfh2D01AJ3J8s20Q2PldYHYI3uM/view?usp=sharing

2. And this is my Neural Network code in Python using PyTorch.

#import the libraries
import pandas as pd
import numpy as np
import torch as torch  
from sklearn.cross_validation import train_test_split
from torch import nn, optim
import torch.nn.functional as F
import matplotlib.pyplot as plt

LOCATION_OF_DATA_FOR_TRAINING = 'time_taken_home_to_office - data.csv'

X = pd.read_csv(LOCATION_OF_DATA_FOR_TRAINING, header=0, usecols=['day','start_time', 'is_any_road_blocked_in_between', 'mode_of_transport'])

# transform all coloumns in X to numerical data and one-hot encode
# We don't need feature scaling as the code below takes care of it as well
X = pd.get_dummies(X, columns=['day','start_time', 'is_any_road_blocked_in_between', 'mode_of_transport']).values

Y = pd.read_csv(LOCATION_OF_DATA_FOR_TRAINING, header=0, usecols=['time_taken']).values

# Splitting the dataset into the Training set and Test set
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.25, random_state = 0)

# get number of columns in training data
# which means how many variables you have for training
n_cols = X_train.shape[1]


# -----------------------------------------------------------------------------
# Class for making the Neural Network

# Make a regressor with three hidden layers
class Regressor(nn.Module):
    def __init__(self):
        super(Regressor, self).__init__()
        self.fc1 = nn.Linear(n_cols, 10)
        self.fc2 = nn.Linear(10, 10)
        self.fc3 = nn.Linear(10, 10)
        self.fc4 = nn.Linear(10, 1)

        #self.dropout = nn.Dropout(p=0.1)

    def forward(self, x):
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = F.relu(self.fc3(x))
        x = F.relu(self.fc4(x))

        return x
 
    
# -----------------------------------------------------------------------------
# Let's train the model
    
train_batch = np.array_split(X_train, 10)
label_batch = np.array_split(y_train, 10)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

for i in range(len(train_batch)):
    train_batch[i] = torch.from_numpy(train_batch[i]).float()
for i in range(len(label_batch)):
    label_batch[i] = torch.from_numpy(label_batch[i]).float().view(-1, 1)

X_test = torch.from_numpy(X_test).float()
y_test = torch.from_numpy(y_test).float().view(-1, 1)

model = Regressor()
criterion = nn.MSELoss()
optimizer = optim.SGD(model.parameters(), lr=.01)
epochs = 300

train_losses, test_losses = [], []
for epoch in range(epochs):
    model.train()
    train_loss = 0
    for i in range(len(train_batch)):
        optimizer.zero_grad()
        output = model(train_batch[i])
        loss = torch.sqrt(criterion(torch.log(output), torch.log(label_batch[i])))
        loss.backward()
        optimizer.step()
        
        train_loss += loss.item()
        
    else:
        test_loss = 0
        accuracy = 0
        
        with torch.no_grad():
            model.eval()
            predictions = model(X_test)
            test_loss += torch.sqrt(criterion(torch.log(predictions), torch.log(y_test)))
                
        train_losses.append(train_loss/len(train_batch))
        test_losses.append(test_loss)

        print("Epoch: {}/{}.. ".format(epoch+1, epochs),
              "Training Loss: {:.3f}.. ".format(train_loss/len(train_batch)),
              "Model Accuracy: {:.3f}.. ".format((1-test_loss)*100))
        
        
# Plot the loss on graph       
plt.plot(train_losses, label='Training loss')
plt.plot(test_losses, label='Validation loss')
plt.legend(frameon=False)   


#------------------------------------------------------------------------------    
# let's do the prediction

# input for if time is 8.30 AM on Monday
inpt1 = np.array([[1,0,0,0,0,1,0,0,0,0,0,0,1,0]])
# input for if time is 9.00 AM on Monday
inpt2 = np.array([[1,0,0,0,0,0,1,0,0,0,0,0,1,0]])
# input for if time is 9.30 AM on Monday
inpt3 = np.array([[1,0,0,0,0,0,0,1,0,0,0,0,1,0]])
# input for if time is 10.00 AM on Monday
inpt4 = np.array([[1,0,0,0,0,0,0,0,1,0,0,0,1,0]])
# input for if time is 10.30 AM on Monday
inpt5 = np.array([[1,0,0,0,0,0,0,0,0,1,0,0,1,0]])

#Convert numpy array to tensor because PyTorch works on Tensors
tensor1 = torch.Tensor(inpt1)
y_pred1 = model(tensor1)

tensor2 = torch.Tensor(inpt2)
y_pred2 = model(tensor2)

tensor3 = torch.Tensor(inpt3)
y_pred3 = model(tensor3)

tensor4 = torch.Tensor(inpt4)
y_pred4 = model(tensor4)

tensor5 = torch.Tensor(inpt5)
y_pred5 = model(tensor5)

best_time = min(y_pred1,y_pred2,y_pred3,y_pred4, y_pred5)

if y_pred1 is best_time:
    print "Best time to start for office on Monday is 8.30 AM, it takes ", best_time[0].item() , ' minutes'

elif y_pred2 is best_time:
    print 'Best time to start for office on Monday is 9.00 AM, it takes ', best_time[0].item() , ' minutes'
    
elif y_pred3 is best_time:
    print 'Best time to start for office on Monday is 9.30 AM, it takes ', best_time[0].item() , ' minutes'

elif y_pred4 is best_time:
    print 'Best time to start for office on Monday is 10.00 AM, it takes ', best_time[0].item() , ' minutes'
    
elif y_pred5 is best_time:
    print 'Best time to start for office on Monday is 10.30 AM, it takes ' , best_time[0].item() , ' minutes'

 

The output looks like this –

(‘Epoch: 300/300.. ‘, ‘Training Loss: 0.156.. ‘, ‘Model Accuracy: 83.765.. ‘)
Best time to start for office on Monday is 10.30 AM, it takes 26.2651309967 minutes

 

Conclusion

Machine Learning can be used to solve many daily life problems. Here my data set is very small (taken for one month only), yet it produces satisfying result. If the data set were bigger, the results would have been even more accurate.

So as per the program output, I should start at 10.30 AM for office on Monday to reach office fastest.

If you want to learn Machine Learning, check my post here for best online course to take –  http://simpleconcepts.org/best-courses-to-start-machine-learning-with-no-previous-experience-in-the-field/`

 

Download the source code from here – https://github.com/simpleconcepts-code/PyTorch-regression-project-to-decrease-time-spent-in-traffic

The post Predict the best time to commute to office by avoiding traffic jams – Machine Learning application by using PyTorch regression appeared first on Simple Concepts.


Will AI take our jobs – yes or no?

Will AI or Artificial Intelligence take all our jobs or not, to understand this, first, we need to understand what AI is actually. I have explained this in very simple language in my post here. Next comes the answer to our question which needs to be understood. As of now, AI is capable of things… Read More The post Will AI take our jobs – yes or no? appeared first on Simple...

Will AI or Artificial Intelligence take all our jobs or not, to understand this, first, we need to understand what AI is actually. I have explained this in very simple language in my post here.

Next comes the answer to our question which needs to be understood.

As of now, AI is capable of things like these –

  1. If you give an AI algorithm, data for training, like a lot of photos of Apple and Oranges, it can eventually identify an Orange and an Apple.
  2. It can perform complex mathematical calculations like if you feed a lot of traffic data about your city, it can eventually tell you how much traffic you will get at any time or day of a year in any particular route.
  3. It can make new things like paintings (which you might or might not understand or like), simple music having one instrument (might not be melodious).
  4. It can tell you an approximate time for you to reach your destination when you take an Uber or an Ola based on training on past data.
  5. It can identify spam emails based on previous training on a huge amount of data (may fail sometimes).
  6. If you are shopping online, based on your search for items, an AI algorithm can suggest a new product you make like to buy which might or might not interest you.
  7. Complex AI algorithms can drive your car when trained on a lot of routes and situations but sometimes it might need a human.
  8. AI can detect online financial frauds but not with a hundred percent accuracy.
  9. On an iPhone, it can detect your face.

So AI systems can operate alone where we have got a lot of past data to train the AI and we don’t need human skills like ‘taking a decision for a new unexpected thing’ or it can operate alone in systems where the work pattern is the same or repetitive every time.

Conclusion and the answer

Some repetitive jobs are being taken up by AI recently like – customer support chats of online shopping websites, accounting works, industrial automation works, self-driving, medical diagnostics by seeing reports and x-rays to some extent, detecting spam in emails or hiding abusive content on the Internet, data entry works, financial works to some extent, etc.

But there are humans behind the AI in most of the cases for supervision.

So yes, to not to lose our jobs, we should learn something AI cannot do like thinking of new ways to improve a process, taking complicated or unexpected decisions, or take up works where the task is dynamic and doesn’t follow a single pattern, etc.

Photo credit – https://pixabay.com/photos/robot-technology-modern-white-2587571/

The post Will AI take our jobs – yes or no? appeared first on Simple Concepts.


Installing complete machine learning stack on Ubuntu with GPU: the simplest and fastest way

I wanted to install TensorFlow, Theano, Keras, Scikit-Learn and Pytorch on Ubuntu 18.04 (with NVIDIA GPU) to get started with Machine Learning/Deep Learning. It turned out to be very time consuming and frustrating because there are a lot of tools of the correct or supported version that need to be installed including the NVIDIA graphics driver… Read More The post Installing complete machine learning stack on Ubuntu with GPU: the simplest and fastest way appeared first on Simple...

I wanted to install TensorFlow, Theano, Keras, Scikit-Learn and Pytorch on Ubuntu 18.04 (with NVIDIA GPU) to get started with Machine Learning/Deep Learning.

It turned out to be very time consuming and frustrating because there are a lot of tools of the correct or supported version that need to be installed including the NVIDIA graphics driver software, CUDA, and CUDNN.

But there is an easy way that saved me a lot of time and effort.

1 – Open your Terminal on Ubuntu and go root

sudo -s

2 – Copy paste this fully

LAMBDA_REPO=$(mktemp) && \
wget -O${LAMBDA_REPO} https://lambdalabs.com/static/misc/lambda-stack-repo.deb && \
sudo dpkg -i ${LAMBDA_REPO} && rm -f ${LAMBDA_REPO} && \
sudo apt-get update && sudo apt-get install -y lambda-stack-cuda

3 – Agree on the License agreement for NVIDIA software that comes in the terminal (if any).

4 – Restart your system when its done.

What will be installed with the above code?

It will install Lambda stack, that takes care of all the dependencies for Deep Learning, NVIDIA driver software, CUDA, and CUDNN automatically. It takes around 1-3 hrs to get installed, depending on your internet speed.

It installs TensorFlow, Keras, PyTorch, Caffe, Caffe 2, Theano, CUDA, cuDNN, and NVIDIA GPU drivers. So if you need to to switch between different machine learning frameworks, that has been taken care of already.

Tip: If the lambda stack installation breaks in between, do sudo apt-get update in Terminal, restart the system. Now copy past the lamda stack installation script again in Terminal with root access.

The Lambda stack works for both Ubuntu 16.04 and18.04.

Anyways, if you want to learn Machine/Deep Learning, checkout my guide here.

The post Installing complete machine learning stack on Ubuntu with GPU: the simplest and fastest way appeared first on Simple Concepts.


Best courses to start Machine Learning with no previous experience in the field

In this post, I will point out three effective and easy to understand online courses to learn Machine Learning concepts and start making your own programs afterwards. If you don’t know what is Machine Learning, see my previous post. There I have explained what is Artificial Intelligence, Machine Learning, and Deep Learning and how they are… Read More The post Best courses to start Machine Learning with no previous experience in the field appeared first on Simple...

In this post, I will point out three effective and easy to understand online courses to learn Machine Learning concepts and start making your own programs afterwards.

If you don’t know what is Machine Learning, see my previous post. There I have explained what is Artificial Intelligence, Machine Learning, and Deep Learning and how they are related to each other.

1.  Deep Learning and Computer Vision using Pytorch (Paid) – Link

Pytorch is a newer Machine Learning framework that is gaining popularity for its power and yet being simple python like in syntax. This course teaches you basics of Deep Learning using Pytorch.

The author takes a simple way of explaining the concepts and if you don’t know Python, this course comes with a free Python for beginners module as well. You don’t need any Machine Learning experience to take this course.

You will get source code for free to download for whatever was taught in the course.

2. Machine learning course from Super Data Science team (Paid) – Link

Although this is a paid course as well but its ideal for a beginners. The instructors teach by giving enough examples. They make you understand the math and logic behind, whenever required.

You don’t need any prior experience in this field at all. Even someone new to coding can understand their video lectures thoroughly.

And they give you code templates that you can download for free. All you need to do is change some lines in their code template and your code is ready for execution.

3. Machine Learning course by Andrew Ng (Free) – Link

This course is free and is on Coursera. Its taught by Andrew Ng who is a co-founder of Google Brain team and is a world-renowned contributor in the field of Artificial Intelligence.

This course takes you to much more details of the algorithms used. You will see the math and the logic behind everything you are taught. You will see some real world use cases and how they are built. It builds a strong foundation and you can pick up any other framework faster.

You can get a course completion certificate from Coursera which is more recognized.

 

Moreover, if you are finding ML uninteresting because of so much of maths and logic involved, you can have a look at Siraj Raval’s Youtube channel. He makes Machine Learning interesting and fun to deal with in his videos.

The post Best courses to start Machine Learning with no previous experience in the field appeared first on Simple Concepts.


Artificial Intelligence, Machine Learning, and Deep Learning explained

Nowadays many people talk about Artificial Intelligence and Machine Learning. People start thinking about automated killer robots and many fancy things when told these terms. But what actually are these technologies in reality? This post explains you about Artificial Intelligence, Machine Learning, and Deep Learning in the simplest way with examples. 1. What is Artificial… Read More The post Artificial Intelligence, Machine Learning, and Deep Learning explained appeared first on Simple...

Nowadays many people talk about Artificial Intelligence and Machine Learning. People start thinking about automated killer robots and many fancy things when told these terms. But what actually are these technologies in reality?

This post explains you about Artificial Intelligence, Machine Learning, and Deep Learning in the simplest way with examples.

1. What is Artificial Intelligence?

Artificial Intelligence is a branch of Computer Engineering. It has different ways and techniques to develop software that makes decisions like humans. It also helps in doing predictions based on past data.

For example, you have a self-driving car. The artificial intelligence software here decides which way to turn the steering. Amazon, Flipkart, and other websites use artificial intelligence technology to filter out offensive comments given by users.

2. What is Machine Learning?

The way to achieve artificial intelligence has improved over the decades.

Machine learning is just an approach. Its a way of achieving artificial intelligence through software. It comprises of collecting data and fitting those data to a computer algorithm. The algorithm learns from the data and does its own predictions.

For example, you save salaries of 1000 people with varied years of experience in a text file. You feed this data to an algorithm. The algorithm can now tell how much salary should be offered to a new candidate.

There can be one more example of machine learning. You collect 1000 Facebook status comments and label those as good or offensive in a CSV or text file. You feed these data to an algorithm. Once you input a custom comment of your own, the algorithm can tell you if it is a good or offensive comment.

In Machine Learning, the algorithms used are mathematical formulae.

Many people use the term machine learning and artificial intelligence interchangeably these days.

3. What is Deep Learning?

Deep learning is a subset of machine learning. Its a newer way of achieving artificial intelligence. Here also you collect data and feed it to an algorithm. And the algorithm learns or restructures itself to make predictions.

But there is a difference between deep learning and the traditional machine learning approach. It’s in the way the algorithms are designed. Traditional machine learning approach uses mathematical formulae as their algorithm as discussed above. But deep learning algorithms are modeled as per the human brain. And that makes deep learning more useful and accurate.

For example, you feed 1,00,000 photos of apples and oranges to a deep learning algorithm. The algorithm learns or restructures itself and gets to know how an apple or an orange roughly looks like. Deep learning techniques require more data to be fed. And they also need more computation power.

4. Real world examples

  • The software in Google’s self-driving cars uses deep learning algorithms. It gives instructions to the hardware and mechanical components to drive.
  • Robots use traditional machine learning or deep learning to detect obstacles and move accordingly.
  • NASA uses deep learning to find new Earth-like planets.
  • When you book an Uber, they use deep learning to predict how much time the driver needs to reach your place.
  • Facebook uses some kind of machine learning to identify offensive or violent posts.

5. Other useful links to explore more

https://en.wikipedia.org/wiki/Machine_learning

https://en.wikipedia.org/wiki/Deep_learning

 

I hope these things are clear to you. If you have any doubts, please put in the comments section below or contact me.

 

 

The post Artificial Intelligence, Machine Learning, and Deep Learning explained appeared first on Simple Concepts.


Link to Category: Programming Blogs

Or if you prefer use one of our linkware images? Click here

Social Bookmarks


Available Upgrade

If you are the owner of Applying AI to solve problems, or someone who enjoys this blog why not upgrade it to a Featured Listing or Permanent Listing?


The number #1 Blog Directory Online Trusted by 13,000+ Bloggers