- 26th Jun 2024
- 18:22 pm
In this assignment we will teach you how to implement search algorithms and apply them to two real-world datasets. Our Python expert will guide you with both the problems without using any python scientific packages including sklearn, scipy etc. In this assignment you can only use pandas or numpy for reading the data or for matrix operations. Additionally, how to install the geopy and sacrebleu packages.
1 NYC Taxi Data
Details The task is to perform Uniform Cost Search and A∗ search. The dataset contains a list of the taxi trips made in NYC in the January 2015. You will only use the following columns:
- pickup longitude
- pickup latitude
- dropoff longitude
- dropoff latitude
- trip distance
Part 1. Represent the data as a graph. For the sake of simplicity, you can assume that edges are only between locations which had a valid taxi trip between them. You can either do it as an adjacency matrix or as an adjacency list. Each node in the graph will be represented by the lat/long values. Output the graph as two csv files.
- nodes.csv: Containing a list of lat/long and the corresponding node ID. The file should have the following columns: nodeid, lat, long.
- edges.csv: Containing tuple of node IDs which have an edges between them. The file should have the following columns: nodeid1, nodeid2
Part 2. Implement the Uniform Cost search where you can use the trip distances as the edge costs. The program should input two node ids from the user and output the path as well as the cost between them. You should also report the time taken to run the search algorithm.
Part 3. Implement A∗ search using a heuristic. One idea of a heuristic value is to use straight line distance between 2 points. This can be computed using the geopy package. The program should input two node ids from the user and output the path as well as the cost between them. You should also report the time taken to run the search algorithm.
Note:
- You can install geopy using the command pip install geopy
- All the distance and speed values are in miles
- Neural Machine Translation
Details The task is to implement beam search for Neural Machine Translation (NMT). This NMT model is already trained on the French to English translation task and a sample file is provided to run for few examples. The data files have already been pre-processed including tokenization and normalization. The following files already been provided:
- models/encoder & models/decoder: trained model files
- data-bin/fra.data & data-bin/eng.data: vocabulary files created using the training data
- data/test.fra & data/test.eng: normalized and tokenized test files
- data utils.py & rnn.py: supporting files for data processing and model initialization
- beam search.py: Main file to translate input sentences
Artificial Intelligence - CS-541 - Get Best Assignment Solution
Please note that this is a sample Artificial Intelligence assignment solved by our Python Programmers. These solutions are intended to be used for research and reference purposes only. If you can learn any concepts by going through the reports and code, then our Python Tutors would be very happy.
- Option 1 - To download the complete solution along with Code, Report and screenshots - Please visit our Python Assignment Sample Solution page
- Option 2 - Reach out to our Python Tutors to get online tutoring related to this assignment and get your doubts cleared
- Option 3 - You can check the partial solution for this assignment in this blog below
Artificial Intelligence Assignment Solution
# -*- coding: utf-8 -*-
"""Nyc_taxi.ipynb
import pandas as pd #data processing
import numpy as np #linear algebra
# Commented out IPython magic to ensure Python compatibility.
#data visualisation
import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
# %matplotlib inline
import datetime as dt
import warnings; warnings.simplefilter('ignore')
"""Importing the Dataset"""
data=pd.read_csv("/content/nyc_taxi_data.csv")
data.shape
data.columns
data.dtypes
data.head()
data.isnull().sum()
data.nunique()
data.describe()
data['pickup_datetime']=pd.to_datetime(data['pickup_datetime'])
data['dropoff_datetime']=pd.to_datetime(data['dropoff_datetime'])
data['pickup_day']=data['pickup_datetime'].dt.day_name()
data['dropoff_day']=data['dropoff_datetime'].dt.day_name()
data['pickup_day_no']=data['pickup_datetime'].dt.weekday
data['dropoff_day_no']=data['dropoff_datetime'].dt.weekday
data['pickup_hour']=data['pickup_datetime'].dt.hour
data['dropoff_hour']=data['dropoff_datetime'].dt.hour
data['pickup_month']=data['pickup_datetime'].dt.month
data['dropoff_month']=data['dropoff_datetime'].dt.month
def time_of_day(x):
if x in range(6,12):
return 'Morning'
elif x in range(12,16):
return 'Afternoon'
elif x in range(16,22):
return 'Evening'
else:
return 'Late night'
data[‘pickup_timeofday’]=data[‘pickup_hour’].apply(time_of_day)
data[‘dropoff_timeofday’]=data[‘dropoff_hour’].apply(time_of_day)
from geopy.distance import great_circle
def cal_distance(pickup_lat,pickup_long,dropoff_lat,dropoff_long):
start_coordinates=(pickup_lat,pickup_long)
stop_coordinates=(dropoff_lat,dropoff_long)
return great_circle(start_coordinates,stop_coordinates).km
data[‘distance’] = data.apply(lambda x: cal_distance(x[‘pickup_latitude’],x[‘pickup_longitude’],x[‘dropoff_latitude’],x[‘dropoff_longitude’] ), axis=1)
sns.histplot(data['trip_duration'],kde=False,bins=20)
sns.boxplot(data[‘trip_duration’])
data['trip_duration'].sort_values(ascending=False)
data.drop(data[data['trip_duration'] == 1939736].index, inplace = True)
sns.countplot(x='vendor_id',data=data)
data.passenger_count.value_counts()
sns.countplot(x='passenger_count',data=data)
data=data[data['passenger_count']!=0]
data=data[data['passenger_count']<=6]
"""Store and Forward Flag"""
data['store_and_fwd_flag'].value_counts(normalize=True)
data['distance'].value_counts()
"""Trips per Day"""
figure,(ax1,ax2)=plt.subplots(ncols=2,figsize=(20,5))
ax1.set_title('Pickup Days')
ax=sns.countplot(x="pickup_day",data=data,ax=ax1)
ax2.set_title('Dropoff Days')
ax=sns.countplot(x="dropoff_day",data=data,ax=ax2)
figure,(ax9,ax10)=plt.subplots(ncols=2,figsize=(20,5))
ax9.set_title('Pickup Days')
ax=sns.countplot(x="pickup_hour",data=data,ax=ax9)
ax10.set_title('Dropoff Days')
ax=sns.countplot(x="dropoff_hour",data=data,ax=ax10)
"""Trips per Time of Day"""
figure,(ax3,ax4)=plt.subplots(ncols=2,figsize=(20,5))
ax3.set_title('Pickup Time of Day')
ax=sns.countplot(x="pickup_timeofday",data=data,ax=ax3)
ax4.set_title('Dropoff Time of Day')
ax=sns.countplot(x="dropoff_timeofday",data=data,ax=ax4)
"""Trips per month"""
figure,(ax11,ax12)=plt.subplots(ncols=2,figsize=(20,5))
ax11.set_title('Pickup Month')
ax=sns.countplot(x="pickup_month",data=data,ax=ax11)
ax12.set_title('Dropoff Month')
ax=sns.countplot(x="dropoff_month",data=data,ax=ax12)
"""Bivariate Analysis
Trip Duration per Vendor
"""
sns.barplot(y='trip_duration',x='vendor_id',data=data,estimator=np.mean)
sns.catplot(y=’trip_duration’,x=’store_and_fwd_flag’,data=data,kind=”strip”)
sns.catplot(y=’trip_duration’,x=’passenger_count’,data=data,kind=”strip”)
sns.lineplot(x=’pickup_hour’,y=’trip_duration’,data=data)
sns.lineplot(x=’pickup_timeofday’,y=’trip_duration’,data=data)
sns.lineplot(x=’pickup_day_no’,y=’trip_duration’,data=data)
"""Trip Duration per month"""
sns.lineplot(x=’pickup_month’,y=’trip_duration’,data=data)
sns.barplot(y='distance',x='vendor_id',data=data,estimator=np.mean)
sns.catplot(y=’distance’,x=’store_and_fwd_flag’,data=data,kind=”strip”)
sns.catplot(y=’distance’,x=’passenger_count’,data=data,kind=”strip”)
sns.lineplot(x='pickup_day_no',y='distance',data=data)
sns.lineplot(x='pickup_hour',y='distance',data=data)
sns.lineplot(x='pickup_timeofday',y='distance',data=data)
sns.lineplot(x='pickup_month',y='distance',data=data)
sns.barplot(y='passenger_count',x='vendor_id',data=data)
sns.relplot(y=data.distance,x='trip_duration',data=data)
Get the best Artificial Intelligence assignment help and tutoring services from our experts now!
About The Author - Rexa Sussane
Rexa Sussane, a Python expert with a Master's in Artificial Intelligence, excels in solving complex AI assignments. With in-depth knowledge of search algorithms and machine translation, Rexa can guide students through implementing Uniform Cost Search and A* search on NYC Taxi Data, and beam search for Neural Machine Translation, ensuring comprehensive understanding and successful completion.