Table of Contents#### Download Safari Books Online apps: Apple iOS | Android | BlackBerry

# Weighted Neighbors

Entire Site

Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

One way to compensate for the fact that the algorithm may be using neighbors that are too far away is to weight them according to their distance. This is similar to the method used in Chapter 2, where people’s preferences were weighted according to how similar they were to the preferences of a person seeking a recommendation.

The more similar the items are, the smaller the distance between them, so you’ll need a way of converting distances to weights. There are a few different ways of doing this, each with advantages and drawbacks. This section will look at three functions that you can use.

The function you used in Chapter 4 to convert distances to weights was an inverse function. Figure 8-3 shows what this looks like if you plot weight on one axis and price on the other.