<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Route Option
Motivation
Step1:  Let's look at the data
Step2:  Let's look at what percentage of the drivers are using the map?
Step3:  47% of the drivers are following the map.
Let's see the groupings by the country
Step4:  Approximately 45-48% ofthe drivers are using the map in each country and approximately half of the entries are made in metro cities. Let's plot this values to get batter understanding ofthe data
Step5:  1 signifies that it is a metro
Let's visualize the data based on the rating of the drivers
Step6:  Most of the drivers are between the range of 1-2
Let's check for missing values by doing a count on each of the columns
Step7:  There are no missing values. However if there are missing values we can deal with them in the following way
Step8:  What we are basically doing here is processing the data to produce numeric labels for the string data
Let's look at the data again
Step9:  X contains all the values besides whether the map was used or not and y contains the answer
Step10:  decision tree
Step11:  neural Network
<ASSISTANT_TASK:>
Python Code:
import matplotlib.pyplot as plt
%matplotlib inline
import random
import numpy as np
import pandas as pd
from sklearn import datasets, svm, cross_validation, tree, preprocessing, metrics
import sklearn.ensemble as ske
import tensorflow as tf
from tensorflow.contrib import learn as skflow
route_df = pd.read_excel('route.xls', index_col=None, na_values=['NA'])
Explanation: Route Option
Motivation:
This module focuses on leveraging human knowledge to get the best route. At a  given time due to certain circumstances (like rush hour) it is possible that a certain route may be faster than a route shown on the map. People who travel at those times or people who are residents of those areas have more knowledge about which route should be taken at what time. If every person entered which path to be taken based on their experience we could create a database that will help us to predict which path should be taken.
Dataset:
The format of the dataset is as follows:
uid: the unique id of the the person making the entry.
rating: the rating of the person adds weightage to the validity of the claim (this follows a rating system similar to that of cab companies) and it ranges from 0-5.
metro: 0 indicates the area is a metro and 1 indicates it isn't a metro city.
country: determines in which country the route is. Currently there are 3 countries Germany, England and Russia. 
startTime: the begining of the time frame when the particular route should be used.
endTime: the ending of the time frame when the particular route should be used.
oldRoute: the old route given by the map.
newRoute: the new route that should be taken.
mapUsed: 1 indicates that the map is used whereas 0 indicates that the map is not used
Importing all the required packages
End of explanation
route_df.head()
Explanation: Let's look at the data
End of explanation
route_df['mapUsed'].mean()
Explanation: Let's look at what percentage of the drivers are using the map?
End of explanation
route_df.groupby('country').mean()
Explanation: 47% of the drivers are following the map.
Let's see the groupings by the country
End of explanation
country_metro_grouping = route_df.groupby(['country','metro']).mean()
country_metro_grouping
country_metro_grouping['mapUsed'].plot.bar()
Explanation: Approximately 45-48% ofthe drivers are using the map in each country and approximately half of the entries are made in metro cities. Let's plot this values to get batter understanding ofthe data
End of explanation
group_by_age = pd.cut(route_df["rating"], np.arange(0, 6, 1))
rating_grouping = route_df.groupby(group_by_age).mean()
rating_grouping['mapUsed'].plot.bar()
Explanation: 1 signifies that it is a metro
Let's visualize the data based on the rating of the drivers
End of explanation
route_df.count()
Explanation: Most of the drivers are between the range of 1-2
Let's check for missing values by doing a count on each of the columns
End of explanation
def preprocess_route_df(df):
    processed_df = df.copy()
    le = preprocessing.LabelEncoder()
    processed_df.country = le.fit_transform(processed_df.country)
    processed_df.oldRoute = le.fit_transform(processed_df.oldRoute)
    processed_df.newRoute = le.fit_transform(processed_df.newRoute)
    processed_df = processed_df.drop(['name','uid'],axis=1)
    return processed_df
Explanation: There are no missing values. However if there are missing values we can deal with them in the following way:
If the column (col1) from which the values are missing is an important factor, we need to drop the rows containing those values.
python
 route_df["col1"] = route_df["col1"].fillna("NA") #first fill the columns with value NA
 route_df = route_df.dropna() #drop the rows with missing values
If the column(col2,col3) is not an important factor, we can drop the column
python
route_df = route_df.drop(['col2','col3'], axis=1) #drop the columns
Now for the preprocessing
End of explanation
processed_df = preprocess_route_df(route_df)
processed_df
Explanation: What we are basically doing here is processing the data to produce numeric labels for the string data
Let's look at the data again
End of explanation
X = processed_df.drop(['mapUsed'], axis=1).values
y = processed_df['mapUsed'].values
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X,y,test_size=0.2)
Explanation: X contains all the values besides whether the map was used or not and y contains the answer
End of explanation
clf_dt = tree.DecisionTreeClassifier(max_depth=10)
clf_dt.fit (X_train, y_train)
clf_dt.score (X_test, y_test)
shuffle_validator = cross_validation.ShuffleSplit(len(X), n_iter=20, test_size=0.2, random_state=0)
def test_classifier(clf):
    scores = cross_validation.cross_val_score(clf, X, y, cv=shuffle_validator)
    print("Accuracy: %0.4f (+/- %0.2f)" % (scores.mean(), scores.std()))
test_classifier(clf_dt)
clf_rf = ske.RandomForestClassifier(n_estimators=50)
test_classifier(clf_rf)
clf_gb = ske.GradientBoostingClassifier(n_estimators=50)
test_classifier(clf_gb)
eclf = ske.VotingClassifier([('dt', clf_dt), ('rf', clf_rf), ('gb', clf_gb)])
test_classifier(eclf)
Explanation: decision tree
End of explanation
#tf_clf_dnn = skflow.TensorFlowDNNClassifier(hidden_units=[20, 40, 20], n_classes=2, batch_size=256, steps=1000, learning_rate=0.05)
feature_columns = [tf.contrib.layers.real_valued_column("")]
tf_clf_dnn = skflow.DNNClassifier(feature_columns=feature_columns, hidden_units=[20, 40, 20], n_classes=2, model_dir="/tmp")
#tf_clf_dnn.evaluate(batch_size=256, steps=1000)
tf_clf_dnn.fit(X_train, y_train, steps=1000)
accuracy_score = tf_clf_dnn.evaluate(X_test, y_test,steps=1000)["accuracy"]
print("\nTest Accuracy: {0:f}\n".format(accuracy_score))
Explanation: neural Network
End of explanation
<END_TASK>