PHPackages                             wellingtonbarbosa/knn - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wellingtonbarbosa/knn

ActivePackage[Utility &amp; Helpers](/categories/utility)

wellingtonbarbosa/knn
=====================

A package to calculate Euclidean distance in a simple way, in addition to comparing results for recommendation quickly and symptomatically, without ifs.

1.0.0(5y ago)632MITPHPPHP &gt;=7.2

Since Nov 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/WellingtonCarneiroBarbosa/knn-in-php)[ Packagist](https://packagist.org/packages/wellingtonbarbosa/knn)[ RSS](/packages/wellingtonbarbosa-knn/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

k-Nearest Neighbors in PHP
==========================

[](#k-nearest-neighbors-in-php)

### **A package to calculate Euclidean distance in a simple way, in addition to comparing results for recommendation quickly and symptomatically, without ifs.**

[](#a-package-to-calculate-euclidean-distance-in-a-simple-way-in-addition-to-comparing-results-for-recommendation-quickly-and-symptomatically-without-ifs)

[![](https://camo.githubusercontent.com/b01557d54f0b1bb186b802e1f123515d225077930a2c2f63d0849156e3dd8b2a/68747470733a2f2f736378312e622d63646e2e6e65742f63737a2f6e6577732f3830302f323031392f686f77746f6f766572636f6d2e6a7067)](https://camo.githubusercontent.com/b01557d54f0b1bb186b802e1f123515d225077930a2c2f63d0849156e3dd8b2a/68747470733a2f2f736378312e622d63646e2e6e65742f63737a2f6e6577732f3830302f323031392f686f77746f6f766572636f6d2e6a7067)

How does it work?
-----------------

[](#how-does-it-work)

Imagine that you are building a movie application, such as Netflix.

You want to recommend a movie to the user when the movie ends, but it needs to be a movie that looks like the one he just watched.

Your films in the database must have a percentage of each category, for example: romance, action, adventure, fiction, etc.

For each film, you enter the percentage of each category

A silly example:

```
[
    "title" => "Robin Hood",
    "categories" => [
        "adventure" => "1" // 100%,
        "romance" => "0.2" // 20%,
        "action" => "0.6", // 60%,
        ...
    ]
]

```

The algorithm will use these percentages to perform the calculation

To understand how the euclidian calculation does work, please visit [this link](https://en.wikipedia.org/wiki/Euclidean_distance)

Getting Started
---------------

[](#getting-started)

1 - Install on your project via composer

```
composer require wellingtonbarbosa/knn

```

2 - Use the class in your php file

```
