Download the PHP package wellingtonbarbosa/knn without Composer
On this page you can find all versions of the php package wellingtonbarbosa/knn. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wellingtonbarbosa/knn
More information about wellingtonbarbosa/knn
Files in wellingtonbarbosa/knn
Package knn
Short Description Recommendation library of categorized items for php using Euclidean distance calculation
License MIT
Informations about the package knn
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.
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:
The algorithm will use these percentages to perform the calculation
To understand how the euclidian calculation does work, please visit this link
Getting Started
1 - Install on your project via composer
2 - Use the class in your php file
3 - Create some items to test
In our example, $defaultItem is the movie the user has just watched, and the $itemsToCompare are movies drawn from the database. Let's see which of these is more like what our user just watched? So let's go!
! Note that all items have 4 indexes. All items must have the same number of indexes, or it will not work
4 - Instantiate the class in a variable
The last parameter passed is the number of indexes that ALL items have.
5 - Performs Euclidean distance calculation for each item
6 - Finally, we will get index (or indexes) of the items to recommend to our user
Note that in addition to the calculated results, there is a second parameter in the recommendation method.
This is because there may be equal results in the calculation. If you pass TRUE, the method will return the index
all results repeated. If you pass FALSE, the first one found will be returned
7 - Now, just look for the item that we will recommend
You can view this complete file by clicking here
Contributing
You can contribute to this package by forking the repository and developing new features and increments and sending the pull request!
Author
Wellington Barbosa
|
---|
License
This package is under the MIT License.
Any issue, tell me on github! I will help you.