Chee logo
lyChee Codes
fullstack development

Building a fullstack web app for AirBnB-style campsite reservation with machine learning algo

Building a fullstack web app for AirBnB-style campsite reservation with machine learning algo
0 views
4 min read
#fullstack development

According to the 2023 North American Camping & Outdoor Hospitality Report, there has been year-on-year growth in the number of active camping households domestically (Kampgrounds of America Inc, 2024) [1]. However, the online reservation industry has been experiencing an undersupply of reservation platforms that cater to private campsite reservations.

Image

In terms of camping location, there are 2 primary types – government run, such as state and national parks, and privately operated, often adjacent to state and federal lands (Parfitt, D., 2017) [2]. There is reportedly 429 national parks and more than 12,000 private campgrounds across the United States (US) (National Park Service, 2024). While campers go through the national park system’s platform for reservation of national camping sites, they rely on disparate sources of reservation websites to navigate and compare different private campsites to book an ideal place. Moreover, there is a limited availability of these websites, unlike in the hotel or private accommodation industry.

Supply & demand data (2023)Hotels/private guest accommodations in USPrivate campgrounds in US
No. of property listings107, 902 (IBISWorld, 2024)15,466 (IBISWorld, 2024)
No. of est. annual active users153.86 million58.5 million
Number of third-party reservation platforms4,264 (IBISWorld, 2024)100
Estimated market size of reservation business in 2024$47.1billion$23.3billion

Architecture

Architecture diagram

Image

Conceptual class diagram

Image

Demo

video

Recommendation system

ML KNN algorithm

The campground controller’s giveRecommendations function generates campground recommendations for users based on various factors such as their reservation history, favorite campgrounds, and the rating ranking of campgrounds. For users not signed in, it generates recommendations based on rating ranking. Here, it uses the sort algorithm to sort campgrounds based on average rating of each campground, callable by an instance method, getRating in the schema. For signed-in users, it uses the K-nearest neighbors (KNN) algorithm. First, it learns from data formatted from existing campgrounds’s weighted average score based on amenities and rating. Each amenity is scored 1. Available amenities are ‘yurk’, ‘stargazing tour’, ‘zipline, kitchen’, ‘hiking tour’, ‘foodtruck’, ‘breakfast’, ‘fishing tour’, ‘premium yurt’, ‘live music’, and ‘yoga class’.

$$weighted average score= ((ratingrating weight)+∑▒〖(Amenity scoreamenity weight)〗)\div(total weight)$$

Currently, the rating weight and the total amenities' relative weight are equal, each accounting for half of the overall weight. Depending on the future market situation, weights would be adjusted. Next, it predicts the campground IDs for new data points which are derived from user data, which are existing favorites array of campgrounds and reservation history. Finally, it returns the recommended campgrounds based on these data. If there are no unique recommendation campground IDs, the function which fall back to the ranking data as recommendation. The algorithm can be adjusted based on selection of the ‘k’ number, which controls the trade-off between model complexity and generalization performance.

Implementation:

Image
campgrounds.js

const knn = require('knear');
  function recommendCampgrounds(campgrounddata) {
    const machine = new knn.kNear(10); // Adjust k value as needed
    for (let data of formattedData) {
      machine.learn(data.features, data.label);
    }
    const recommendations = new Set();
    for (let data of campgrounddata) {

      let prediction = machine.classify(data.features); // Use relevant feature(s) from favorites
      console.log('prediction: ', prediction)
      recommendations.add(prediction)
    }
    // Convert Set to array and remove already favorited campgrounds
    console.log('recommendations', recommendations)
    const uniqueRecommendations = [...recommendations].filter(campgroundId =>
      !campgrounddata.some(data => data.label.equals(campgroundId))
    );
    //const prediction=machine.classify([1,9])
    console.log('uniqueRecommendations', uniqueRecommendations)
    return uniqueRecommendations;
    //return prediction
  }
this file contains javascript codes

References

[1] Kampgrounds of America Inc, 2024, 2023 North American Camping & Outdoor Hospitality Report, United States, viewed February 1 2024, http://koa.uberflip.com/i/1497941-2023-north-american-camping-outdoor-hospitality-report/

[2] Parfitt, D., Jun 13 2017, U.S. National Park Campgrounds Tip: Public vs. Private, viewed Mar 1 2024, https://www.huffpost.com/entry/us-national-park-campgrounds-tip-public-vs-private_b_593fdc85e4b0b65670e56dca

[3] Repo: https://github.com/YeeCheeYong/campbnb