Coder Social home page Coder Social logo

nearest-neighbors-lab's Introduction

This lesson is no longer in use in the curriculum. It is now archived

Nearest Neighbors Lab

Introduction

In this lab, you apply nearest neighbors technique to help a taxi company predict the length of their rides. Imagine that we are hired to consult for LiftOff, a limo and taxi service that is just opening up in NYC. Liftoff wants it's taxi drivers to target longer rides, as the longer the ride the more money it makes. LiftOff has the following theory:

  • The pickup location of a taxi ride can help predict the length of the ride.

LiftOff asks us to do some analysis to write a function that will allow it to predict the length of a taxi ride for any given location.

Our technique will be the following:

  • Collect Obtain the data containing all of the taxi information, and only select the attributes of taxi trips that we need
  • Explore Examine the attributes of our data, and plot some of our data on a map
  • Train Write our nearest neighbors formula, and change the number of nearby trips to predict the length of a new trip
  • Predict Use our function to predict trip lengths of new locations

Collect and Explore the data

Collect the Data

Luckily for us, NYC Open Data collects information about NYC taxi trips and provides this data on its website.

For your reading pleasure, the data has already been downloaded into the trips.json file in this lab which you can find here. We'll use Python's json library to take the data from the trips.json file and store it as a variable in our notebook.

import json
# First, read the file
trips_file = open('trips.json')
# Then, convert contents to list of dictionaries 
trips = json.load(trips_file)

Press shift + enter

Explore the data

The next step is to explore the data. First, let's see how many trips we have.

len(trips)

Not bad at all. Now let's see what each individual trip looks like. Each trip is a dictionary, so we can see the attributes of each trip with the keys function.

trips[0].keys()

Limit our data

Ok, now that we have explored some of our data, let's begin to think through what data is relevant for our task.

Remember that our task is to use the trip location to predict the length of a trip. So let's select the pickup_latitude, pickup_longitude, and trip_distance from each trip. That will give us the trip location and related trip_distance for each trip. Then based on these actual trip distances we can use nearest neighbors to predict an expected trip distance for a trip, provided an actual location.

Add in about trip distance

Write a function called parse_trips(trips) that returns a list of the trips with only the following attributes:

  • trip_distance
  • pickup_latitude
  • pickup_longitude
def parse_trips(trips):
    pass
parsed_trips = parse_trips(trips)
parsed_trips and parsed_trips[0]

# {'trip_distance': '18.379999999999999',
# 'pickup_latitude': '40.64499',
# 'pickup_longitude': '-73.781149999999997'}

Now, there's just one change to make. If you look at one of the trips, all of the values are strings. Let's change them to be floats.

def float_values(trips):    
    pass
cleaned_trips = float_values(parsed_trips)
cleaned_trips[0]

# {'trip_distance': 18.38,
# 'pickup_latitude': 40.64499,
# 'pickup_longitude': -73.78115}

Exploring the Data

Now that we have paired down our data, let's get a sense of our trip data. We can use the folium Python library to plot a map of Manhattan, and our data. First we must import folium, and then use the Map function to pass through a location, and zoom_start. If a map isn't showing up below, copy and paste the command pip install folium into your terminal to install folium then try again.

import folium
manhattan_map = folium.Map(location=[40.7589, -73.9851], zoom_start=11)
manhattan_map

Ok, now let's see how we could add a dot to mark a specific location. We'll start with Times Square.

marker = folium.CircleMarker(location = [40.7589, -73.9851], radius=10)
marker.add_to(manhattan_map)

Above, we first create a marker. Then we add that circle marker to the manhattan_map we created earlier.

manhattan_map

Do you see that blue dot near Time's Square? That is our marker.

So now that we can plot one marker on a map, we should have a sense of how we can plot many markers on a map to display our taxi ride data. We simply plot a map, and then we add a marker for each location of a taxi trip.

Now let's write some functions to allow us to plot maps and add markers a little more easily.

Writing some map plotting functions

As a first step towards this, note that the functions to create both a marker and map each take in a location as two element list, representing the latitude and longitude values. Take another look:

marker = folium.CircleMarker(location = [40.7589, -73.9851])
manhattan_map = folium.Map(location=[40.7589, -73.9851])

So let's write a function to create this two element list from a trip. Write a function called location that takes in a trip as an argument and returns a list where the first element is the latitude and the second is the longitude. Remember that a location looks like the following:

first_trip = {'pickup_latitude': 40.64499, 'pickup_longitude': -73.78115,  'trip_distance': 18.38}
first_trip
def location(trip):
    pass
first_location = location(first_trip) # [40.64499, -73.78115]
first_location # [40.64499, -73.78115]

Ok, now that we can turn a trip into a location, let's turn a location into a marker. Write a function called to_marker that takes in a location (in the form of a list) as an argument, and returns a folium circleMarker for that location. The radius of the marker should always equal 6.

def to_marker(location):
    pass
import json
times_square_marker = to_marker([40.7589, -73.9851])

times_square_marker and times_square_marker.location # [40.7589, -73.9851]
times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

Ok, now that we know how to produce a single marker, let's write a function to produce lots. We can write a function called markers_from_trips that takes in a list of trips, and returns a marker object for each trip.

def markers_from_trips(trips):
    pass
trip_markers = markers_from_trips(cleaned_trips)
cleaned_trips[0:4]
trip_markers and len(trip_markers) # 1000
list(map(lambda marker: marker.location, trip_markers[0:4]))
# [[40.64499, -73.78115],
#  [40.766931, -73.982098],
#  [40.77773, -73.951902],
#  [40.795678, -73.971049]]

Ok, now that we have a function that creates locations, and a function that creates markers, it is time to write a function to plot a map.

Write a function called map_from that, provided the first argument of a list location and second argument an integer representing the zoom_start, returns a folium map the corresponding location and zoom_start attributes.

Hint: The following is how to write a map with folium:

folium.Map(location=location, zoom_start=zoom_amount)
def map_from(location, zoom_amount):
    pass
times_square_map = map_from([40.7589, -73.9851], 15)
times_square_map and times_square_map.location # [40.7589, -73.9851]
times_square_marker and times_square_marker.add_to(times_square_map)
times_square_map

Now that we have a marker and a map, now let's write a function that adds a lot of markers to a map. This function should add each marker in the list to the map object then return the updated map object.

manhattan_map = map_from([40.7589, -73.9851], 13)
def add_markers(markers, map_obj):
    pass
map_with_markers = add_markers(trip_markers, manhattan_map)
map_with_markers

Using Nearest Neighbors

Ok, let's write a function that given a latitude and longitude will predict the distance for us. We'll do this by first finding the nearest trips given a latitude and longitude.

Here we once again apply the nearest neighbors formula. As a first step, write a function named distance_location that calculates the distance in pickup location between two trips.

import math

def distance_location(selected_trip, neighbor_trip):
    pass
first_trip = {'pickup_latitude': 40.64499, 'pickup_longitude': -73.78115, 'trip_distance': 18.38}
second_trip = {'pickup_latitude': 40.766931, 'pickup_longitude': -73.982098, 'trip_distance': 1.3}
distance_first_and_second = distance_location(first_trip, second_trip)

distance_first_and_second and round(distance_first_and_second, 3) # 0.235

Ok, next write a function called distance_between_neighbors that adds a new key-value pair, called distance_from_selected, that indicates the distance of the neighbor_trip from the selected_trip.

def distance_between_neighbors(selected_trip, neighbor_trip):
    pass
distance_between_neighbors(first_trip, second_trip)

# {'pickup_latitude': 40.766931,
# 'pickup_longitude': -73.982098,
# 'trip_distance': 1.3,
# 'distance_from_selected': 0.23505256047318146}

Ok, now our neighbor_trip has another attribute called distance_from_selected, that indicates the distance from the neighbor_trip's pickup location from the selected_trip.

Understand the data: Our dictionary now has a few attributes, two of which say distance. Let's make sure we understand the difference.

  • distance_from_selected: This is our calculation of the distance of the neighbor's pickup location from the selected trip.
  • trip_distance: This is the attribute we were provided initially. It tells us the length of the neighbor's taxi trip from pickup to drop-off.

Next, write a function called distance_all that provided a list of neighbors, returns each of those neighbors with their respective distance_from_selected numbers.

def distance_all(selected_individual, neighbors):
    pass
cleaned_trips and distance_all(first_trip, cleaned_trips[0:4])

Now write the nearest neighbors formula to calculate the distance of the selected_trip from all of the cleaned_trips in our dataset. If no number is provided, it should return the top 3 neighbors.

def nearest_neighbors(selected_trip, trips, number = 3):
    pass
new_trip = {'pickup_latitude': 40.64499,
'pickup_longitude': -73.78115,
'trip_distance': 18.38}

nearest_three_neighbors = nearest_neighbors(new_trip, cleaned_trips or [], number = 3)
nearest_three_neighbors
# [{'trip_distance': 7.78,
#  'pickup_latitude': 40.64483,
#  'pickup_longitude': -73.781578,
#  'distance_from_selected': 0.0004569288784918792},
# {'trip_distance': 12.7,
#  'pickup_latitude': 40.644657,
#  'pickup_longitude': -73.782229,
#  'distance_from_selected': 0.0011292165425673159},
# {'trip_distance': 17.3,
#  'pickup_latitude': 40.648509,
#  'pickup_longitude': -73.783508,
#  'distance_from_selected': 0.0042359798158141185}]

Ok great! Now that we can provide a new trip location, and find the distances of the three nearest trips, we can take calculate an estimate of the trip distance for that new trip location.

We do so simply by calculating the average of it's nearest neighbors.

import statistics
def mean_distance(neighbors):
    nearest_distances = list(map(lambda neighbor: neighbor['trip_distance'], neighbors))
    return round(statistics.mean(nearest_distances), 3)

nearest_three_neighbors = nearest_neighbors(new_trip, cleaned_trips or [], number = 3)
distance_estimate_of_selected_trip = mean_distance(nearest_three_neighbors) # 12.7
distance_estimate_of_selected_trip

Choosing the correct number of neighbors

Now, as we know from the last lesson, one tricky element is to determine how many neighbors to choose, our $k$ value, before calculating the average. We want to choose our value of $k$ such that it properly matches actual data, and so that it applies to new data. There are fancy formulas to ensure that we train our algorithm so that our formula is optimized for all data, but here let's see different $k$ values manually. This is the gist of choosing our $k$ value:

  • If we choose a $k$ value too low, our formula will be too heavily influenced by a single neighbor, whereas if our $k$ value is too high, we will be choosing so many neighbors that our nearest neighbors formula will not be adjust enough according to locations.

Ok, let's experiment with this.

First, let's choose a midtown location, to see what the trip distance would be. A Google search reveals the coordinates of 51st and 7th avenue to be the following.

midtown_trip = dict(pickup_latitude=40.761710, pickup_longitude=-73.982760)
seven_closest = nearest_neighbors(midtown_trip, cleaned_trips, number = 7)
seven_closest
# [{'trip_distance': 0.58,
#   'pickup_latitude': 40.761372,
#   'pickup_longitude': -73.982602,
#   'distance_from_selected': 0.00037310588309379025},
#  {'trip_distance': 0.8,
#   'pickup_latitude': 40.762444,
#   'pickup_longitude': -73.98244,
#   'distance_from_selected': 0.00080072217404248},
#  {'trip_distance': 1.4,
#   'pickup_latitude': 40.762767,
#   'pickup_longitude': -73.982293,
#   'distance_from_selected': 0.0011555682584735844},
#  {'trip_distance': 8.3,
#   'pickup_latitude': 40.762868,
#   'pickup_longitude': -73.983233,
#   'distance_from_selected': 0.0012508768924205918},
#  {'trip_distance': 1.26,
#   'pickup_latitude': 40.760057,
#   'pickup_longitude': -73.983502,
#   'distance_from_selected': 0.0018118976240381972},
#  {'trip_distance': 0.0,
#   'pickup_latitude': 40.760644,
#   'pickup_longitude': -73.984531,
#   'distance_from_selected': 0.002067074502774709},
#  {'trip_distance': 1.72,
#   'pickup_latitude': 40.762107,
#   'pickup_longitude': -73.98479,
#   'distance_from_selected': 0.0020684557041472677}]

Looking at the distance_from_selected it appears that our our trips are still fairly close to our selected trip. Notice that most of the data is within a distance of .002 away, so going to the top 7 nearest neighbors didn't seem to give us neighbors too far from each other, which is a good sign.

Still, it's hard to know what distance in latitude and longitude really look like, so let's map the data.

midtown_location = location(midtown_trip) # [40.76171, -73.98276]
midtown_map = map_from(midtown_location, 16)
closest_markers = markers_from_trips(seven_closest)

add_markers(closest_markers, midtown_map)

Ok. These locations stay fairly close to our estimated location of 51st street and 7th Avenue. So they could be a good estimate of a trip distance.

mean_distance(seven_closest) # 1.26

Ok, now let's try a different location

charging_bull_closest = nearest_neighbors({'pickup_latitude': 40.7049, 'pickup_longitude': -74.0137}, cleaned_trips, number = 12)
mean_distance(charging_bull_closest) # 3.515

Ok, so there appears to be a significant difference between choosing a location near Times Square versus choosing a location at Wall Street.

Summary

In this lab, we used the nearest neighbors function to predict the length of a taxi ride. To do so, we selected a location, then found a number of taxi rides closest to that location, and finally took the average trip lengths of the nearest taxi rides to find an estimate of the new ride's trip length. You can see that even with just a little bit of math and programming we can begin to make meaningful predictions with data.

nearest-neighbors-lab's People

Contributors

cheffrey2000 avatar cutterbuck avatar jayascript avatar jeffkatzy avatar mike-kane avatar tkoar avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nearest-neighbors-lab's Issues

TypeError for JSON and AttributeError for Folium, despite running code found in solution?

I got stuck on a portion of this lab where no matter what I tried, outputting the below code would produce the following TypeError from JSON:

import json
times_square_marker = to_marker([40.7589, -73.9851])

times_square_marker and times_square_marker.location # [40.7589, -73.9851]
times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

TypeErrorTraceback (most recent call last)
in
3
4 times_square_marker and times_square_marker.location # [40.7589, -73.9851]
----> 5 times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

/opt/conda/envs/learn-env/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.class.name))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350

TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

Followed by an AttributeError for Folium after executing the below code:

times_square_map = map_from([40.7589, -73.9851], 15)
times_square_map and times_square_map.location # [40.7589, -73.9851]
times_square_map and times_square_map.zoom_start # 15

AttributeErrorTraceback (most recent call last)
in
1 times_square_map = map_from([40.7589, -73.9851], 15)
2 times_square_map and times_square_map.location # [40.7589, -73.9851]
----> 3 times_square_map and times_square_map.zoom_start # 15

AttributeError: 'Map' object has no attribute 'zoom_start'

These results were in spite of the fact that I was able to utilize my functions well elsewhere in the worksheet, but convinced me I had been missing something in my code. That is, until I found the solution index.ipynb file and tried copy and pasting the solution code in to a reloaded notebook of the worksheet, from all cells starting from the beginning until where I was returning the errors. I found that outputting the solution code was resulting in the same problem, TypeError for JSON and AttributeError for Folium.

At this point I'm not sure if this is a problem on my end, or some sort of bug in the worksheet or notebook regarding JSON and Folium, but I would desperately like to know if this problem is specific to me, and if so, where I might be able to find how to resolve it.

Module Not Found - folium

As per the FAQ, I did the !pip install folium workaround, but figured the issue should be logged.

Important Typo in Instructions

I just discovered that my issues with installing Folium in the Nearest Neighbors Lab was because of a missing '!'. The instructions don't say anything about putting the command in as "!pip install folium". Instead it just says to enter "pip install folium". The instructions also direct you to input these commands in a terminal. That doesn't work either.....or rather it doesn't work without the "!". Maybe others with more experience with Python automatically know to include that "!" for all pip commands, but for those of us who are new to the language, this issue can take a while to figure out.

nearest neighbor lab

AttributeErrorTraceback (most recent call last)
in
1 times_square_map = map_from([40.7589, -73.9851], 15)
2 times_square_map and times_square_map.location # [40.7589, -73.9851]
----> 3 times_square_map and times_square_map.zoom_start # 15

AttributeError: 'Map' object has no attribute 'zoom_start'

Incorrect it's

LiftOff asks us to do some analysis. Lucky for us, information about NYC taxi trips is available on it's website.

Should be its b/c it's possessive

function add_markers isn't working

AttributeErrorTraceback (most recent call last)
in
----> 1 map_with_markers = add_markers(trip_markers, manhattan_map)

in add_markers(markers, map_obj)
1 def add_markers(markers, map_obj):
2 for marker in markers:
----> 3 marker.add_to(map_obj)
4 return map_obj

AttributeError: 'tuple' object has no attribute 'add_to'

type(marker)
folium.vector_layers.CircleMarker

associted should be associated

Now, plotting the data feeds into the following function.

gmap.plot(latitudes, longitudes, 'cornflowerblue', edge_width=10)

So we'll need an array of latitudes, each element representing the latitude of a trip, and an array of longitudes, each representing the longitudes associted with a trip. Write a function called trip_latitudes that given a list of trips returns a list of latitudes, and trip_longitudes that given a list of trips, returns a list of longitudes accordingly. Run the file nearest-neighbor-lab-tests.py to get feedback.

Typeerror

times_square_marker and json.loads(times_square_marker.options)['radius'] # 6
should be
times_square_marker and json.loads(str(times_square_marker.options['radius'])) # 6

otherwise there is a typeerror:
TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

Cannot install folium

I seem to be having trouble installing folium with the provided line of code:

pip install -r requirements.txt

Float Values and Parsed_Trips Section

Once you are asked to define the new function float_values and then apply it to the cleaned_trips variable, there seems to be a problem. It is producing a KEY ERROR: trip_distance

My code seems to be correct when comparing it to the solutions guide

Nearest Neighbors Issue

Cannot find solutions after subheading "Using Nearest Neighbors"

I am having trouble working with some of the code after the subheading "Using Nearest Neighbors" and I wanted to check what I had against the solutions. The current solutions readme does not have those solutions in there, and most of the page is clogged up by code related to the map displays.

type error returned for json radius check

when this command line is run (using the lab solution as input):
times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

this error is returned:
TypeErrorTraceback (most recent call last)
in
----> 1 times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

/opt/conda/envs/learn-env/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.class.name))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350

TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

keep getting error in Nearest Neighbor Lab

TypeErrorTraceback (most recent call last)
in
5 times_square_marker and times_square_marker.location # [40.7589, -73.9851]
6
----> 7 times_square_marker and json.loads(times_square_marker.options)

/opt/conda/envs/learn-env/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.class.name))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350

TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

json type error

https://learn.co/tracks/data-science-bootcamp-prep/graphs-with-python/building-graphs-with-python/nearest-neighbors-lab

import json
times_square_marker = to_marker([40.7589, -73.9851])

times_square_marker and times_square_marker.location # [40.7589, -73.9851]
times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

TypeErrorTraceback (most recent call last)
in
3
4 times_square_marker and times_square_marker.location # [40.7589, -73.9851]
----> 5 times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

/opt/conda/envs/learn-env/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 if not isinstance(s, (bytes, bytearray)):
347 raise TypeError('the JSON object must be str, bytes or bytearray, '
--> 348 'not {!r}'.format(s.class.name))
349 s = s.decode(detect_encoding(s), 'surrogatepass')
350

TypeError: the JSON object must be str, bytes or bytearray, not 'dict'

foilum error

when i run the Lists with Maps exercise . i got this error message . 'AttributeError: 'Marker' object has no attribute 'repr_html''. i checked the documentation , but i couldn't find the issue resolution .any idea please ?

distance_location

What are the units for the distance between pickup points for the "distance_location" function? The code suggests that the answer is ~0.235. The answer I come out with by implementing the haversine formula is 21.7 km. Using external calculators on the input lat/longs, my implementation appears to be correct. I do not know where 0.235 comes from - it is not in miles. Has something got muddled?

Mismatched Solution

Hello! Going through and struggling with the Nearest Neighbors lab, specifically the box that starts with " trip_markers and len(trip_markers) # 1000 ". While I often check the solutions to see what parts I am missing in order to continue progressing through the labs, the solution does match the box provided in the lab and also produces errors (" AttributeError: 'NoneType' object has no attribute 'location' "). Have played around with it, tried to match arguments to what I've written up to that point, but so far no luck and it means I can't finish out this lab at all unfortunately. I'll keep trying though.
I'll also bring up the issues I've had when I do my technical interview (y'all forgot to introduce lambda completely so I've been struggling with functions using lambda) but wanted to flag it here too!

No module named 'folium'

In terminal, i enter: !pip install folium, and the response I get is this:
-bash: !pip: event not found

I've entered this into the terminal (pip install -r requirements.txt), and I get this:
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'

suspected error in pre-written portion of function

In the section under "def to marker(location)" --

times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

appears to be missing a 'str' —— if I was supposed to notice and correct this, that was not clear and I don't believe I've learned the necessary folium syntax to identify that. More likely it seems an error, and should instead be:

times_square_marker and json.loads(str(times_square_marker.options['radius'])) # 6

But if I am wrong I would love to know and why…

need to install folium

need to have !pip install folium somewhere before importing folium or python gets mad at you.

mean_distance might be incorrect for the second two uses

mean_distance(seven_closest) and mean_distance(charging_bull_closest) seem to be incorrect. I got the first mean_distance used to match by using a filter to remove the original location from the list of neighbors. Using this newly filtered function, I wasn't able to match up my answer with the commented one for the latter two uses. I'm not sure if the data set has changed or something funky is going on.

Confusing wording

"Ok, next write a function called distance_between_neighbors that adds a new key-value pair, called distance_from_selected, that calculates the distance of the neighbor_trip from the selected_trip."

I think you mean "indicates" rather than "calculates" here? This makes it sound like this function should do the same thing as the distance_location function. I found the instructions here VERY confusing. The only way I was able to figure out what the functions were supposed to do, was to look at the answers.

The solution file stops at map_with_markers

there are no solutions to this exercise for anything coming from
"Using Nearest Neighbors" onwards. Thank you for fixing this, seems a rather important section and complicated - unfortunately. So could do with a bit of help.

Cannot read answers

It looks like the bottom 75% of the page is completely unreadable. After this section:

"Now that we have a marker and a map, now let's write a function that adds a lot of markers to a map. This function should add each marker in the list to the map object then return the updated map object."

there is then a few boxes of example code followed by:

"<iframe src="data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0b...."

which trails off into huge blocks of random characters.

Maybe it's my browser, but all the other solution pages have worked fine so far.

Doesn't work

The last line of this code doesn't work:

import json
times_square_marker = to_marker([40.7589, -73.9851])

times_square_marker and times_square_marker.location # [40.7589, -73.9851]
times_square_marker and json.loads(times_square_marker.options)['radius'] # 6

In the solution, you have the correct code but not in the lab

installing folium

I'd change the language to say to past 'pip install -r requirements.txt' into jupyter instead of 'your terminal' (my interpretation was to actually install it on my computer) and also, the installation code is missing the ! so, should be !pip install -r requirements.txt.

naming of "distance_from_selected"

In the commented sample it is listed as "distance_from_individual"
in the instructions the key is "distance_from_selected"

distance_between_neighbors(first_trip, second_trip)


{'distance_from_individual': 0.23505256047318146,
'pickup_latitude': 40.766931,
'pickup_longitude': -73.982098,
'trip_distance': 1.3}

Ok, now our neighbor_trip has another attribute called distance_from_selected, that indicates the distance from the neighbor_trip's pickup location from the selected_trip.

TypeError: 'NoneType' object is not subscriptable

Within nearest-neighbors-lab
Error message returned when using sample/teaching code in lab:

TypeError: 'NoneType' object is not subscriptable

Google Search: "This error is caused because a function and an iterable have the same name.
This can be solved by renaming the function."

If possible, please update lesson's sample/teaching code with a resolution: rename function & update the lesson's code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.