This PHP-based Trip Recommendation System suggests new trips to users based on the tags of trips they have previously visited. The system filters out trips with tags not associated with the user’s known preferences and avoids recommending trips that the user has already visited.
- Tag-Based Recommendations: Recommends trips based on tags from trips the user has visited.
- Excludes Visited Trips: Avoids recommending trips the user has already visited.
- Customizable: Easily modify the list of trips and user data.
- PHP 7.0 or higher
- Basic knowledge of PHP
-
Clone the Repository
git clone https://github.com/dmunasingha/Trip-Recommendation-Algorithm cd Trip-Recommendation-Algorithm
-
Set Up Your Environment
Ensure PHP is installed and configured on your system. No additional packages are required beyond PHP.
-
Define Your Trips
Edit the
$trips
array inrecommendation.php
to include your trips data. Each trip should have anid
and a list oftags
.$trips = [ ['id' => 1, 'tags' => ['beautiful', 'hot', 'sunny']], ['id' => 2, 'tags' => ['cold', 'beautiful']], ['id' => 3, 'tags' => ['sunny', 'hot']], ['id' => 4, 'tags' => ['cold', 'snowy']], ];
-
Set User Visits
Update the
$userVisitedTrips
array with the IDs of trips the user has visited.$userVisitedTrips = [1, 3];
-
Run the Script
Execute the PHP script from the command line:
php recommendation.php
-
View Recommendations
The script will output recommended trip IDs and details based on the tags of trips the user has previously visited.
calculateTagSimilarity($tags1, $tags2)
: Computes similarity between two sets of tags.filterTripsByUserTags($trips, $userTags, $visitedTrips)
: Filters trips based on user tags and excludes visited trips.recommendTrips($trips, $userTags, $visitedTrips)
: Generates recommendations by calculating tag similarity and excluding visited trips.
Array
(
[0] => 2
[1] => 4
)
Array
(
[id] => 2
[tags] => Array
(
[0] => cold
[1] => beautiful
)
)
Array
(
[id] => 4
[tags] => Array
(
[0] => cold
[1] => snowy
)
)
Feel free to contribute to this project by submitting issues or pull requests. Please ensure to follow the code of conduct and contribution guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
For any inquiries, please contact dunix00@gmail.com.