Ecommerce Product Recommendation System Final Draft
Ecommerce Product Recommendation System Final Draft
SYNOPSIS
The rapid expansion of e-commerce platforms has transformed the way consumers shop by
providing access to a vast range of products across multiple categories. While this growth
offers greater choice to customers, it also introduces the challenge of information overload,
where users struggle to identify products that align with their preferences and needs.
Conventional search mechanisms and category-based browsing techniques are no longer
sufficient to deliver a personalized and engaging shopping experience. As a result, intelligent
recommendation systems have become a critical component of modern e-commerce
applications.
The proposed system collects user interaction data such as product views, ratings, search
history, and purchase records. This data is processed to build user profiles and product
representations, which are then used by the recommendation engine to generate relevant
suggestions. Collaborative filtering techniques identify similarities between users or products,
while content-based methods analyze product attributes and user preferences. A hybrid
approach integrates both methods to provide more reliable and diverse recommendations. The
system is implemented using Python for machine learning logic, Django or Flask as the
backend framework, and MySQL as the relational database for efficient data storage and
retrieval.
The architecture of the system follows a three-tier model consisting of a presentation layer,
application layer, and data layer. This modular design ensures scalability, maintainability,
and seamless integration with existing e-commerce platforms. The recommendation engine
operates in real time, enabling dynamic adaptation to changing user behavior and preferences.
The system also includes administrative and analytical components to manage product data,
monitor user activity, and evaluate recommendation performance.
The Chennai Chapter plays an important role in providing learning opportunities for students
through internships, training programs, workshops, and awareness initiatives. These
programs are designed to help students understand real-world Internet challenges related to
online safety, cybersecurity, digital trust, and Internet governance. By participating in chapter
activities, students gain practical exposure beyond academic coursework.
One of the key objectives of the Internet Society Chennai Chapter is to encourage student
participation in Internet development and policy discussions. The chapter collaborates with
educational institutions to organize technical sessions, hands-on training, and mentorship
programs. These initiatives help students develop technical skills, critical thinking abilities,
and a strong understanding of ethical and responsible Internet practices.
The Chennai Chapter also supports community-oriented projects that aim to improve digital
literacy and Internet accessibility. Students involved in internships are encouraged to
contribute to research, awareness campaigns, and technology-driven solutions that address
issues such as online trust and safety, secure Internet usage, and digital inclusion.
Through its internship programs, the Internet Society Chennai Chapter provides students with
an opportunity to work on meaningful projects, interact with industry experts, and understand
the importance of Internet standards and policies. The internship experience enhances
students’ professional skills, teamwork, and problem-solving abilities, preparing them for
future careers in technology and related fields.
In conclusion, the Internet Society Chennai Chapter offers a valuable platform for students to
gain practical knowledge and hands-on experience in Internet-related domains. By combining
technical learning with community engagement, the chapter helps students become
responsible digital citizens and future contributors to a secure and inclusive Internet
ecosystem.
PROBLEM DEFINITION
PROBLEM IDENTIFICATION
The exponential growth of e-commerce platforms over the past decade has significantly
changed consumer purchasing behavior. Online shopping portals now host millions of
products across various categories, brands, and price ranges. While this vast availability of
products provides customers with more choices, it simultaneously introduces the problem of
information overload. Users often find it difficult to discover products that are relevant to
their interests, preferences, and needs within a limited amount of time. This challenge directly
affects user satisfaction, engagement, and retention.
One of the primary issues in existing e-commerce systems is the lack of effective
personalization. Many platforms still rely heavily on traditional keyword-based search and
category-based navigation. These methods require users to explicitly know what they are
looking for and do not proactively assist them in discovering relevant or complementary
products. As a result, users may miss suitable products or abandon the platform due to
frustration, leading to reduced conversion rates and lost revenue for businesses.
Data sparsity is another critical issue, as most users interact with only a small subset of
available products. This leads to sparse user-item interaction matrices, making it challenging
to accurately infer preferences using traditional recommendation techniques. Additionally,
existing systems often fail to consider real-time changes in user behavior, such as evolving
interests, seasonal trends, or recent browsing activities.
PROBLEM DEFINITION
The problem addressed in this project is the design and development of an intelligent E-
Commerce Product Recommendation System that can effectively analyze user behavior
and product information to generate personalized and relevant product recommendations. The
system must overcome the limitations of traditional search and static recommendation
methods by leveraging machine learning and data mining techniques.
Specifically, the system is required to collect and process various types of user interaction
data, including product views, ratings, search history, and purchase transactions. This data
should be used to build comprehensive user profiles that accurately reflect individual
preferences and interests. At the same time, the system must analyze product attributes such
as category, brand, price, and description to understand product similarities and relationships.
The recommendation system should employ suitable machine learning algorithms such as
collaborative filtering, content-based filtering, or a hybrid approach to predict user
preferences and recommend products that users are most likely to be interested in. The
system must be capable of generating recommendations even in situations where limited data
is available, thereby addressing cold-start and data sparsity problems.
Another critical requirement is scalability. The system should efficiently handle large datasets
containing thousands of users and products while maintaining acceptable response times. The
architecture must support real-time recommendation generation so that users receive updated
suggestions as their behavior changes. This necessitates an optimized backend design and
efficient database management.
The problem also involves ensuring system adaptability and accuracy. User preferences are
dynamic and may change over time; therefore, the system should continuously update user
profiles and recommendation models based on recent interactions. Additionally, the system
should provide diverse recommendations to avoid over-specialization, ensuring users are
exposed to a variety of relevant products.
From a technical perspective, the system must integrate seamlessly with a web-based e-
commerce platform. It should provide a user-friendly interface for customers and
administrative tools for managing users, products, and system performance. Security, data
integrity, and privacy considerations must also be addressed while storing and processing
user data.
One of the most widely studied approaches is Collaborative Filtering (CF). Collaborative
filtering methods generate recommendations based on the assumption that users with similar
preferences in the past are likely to have similar interests in the future. User-based
collaborative filtering identifies similar users using similarity measures such as cosine
similarity or Pearson correlation and recommends items liked by those users (Resnick et al.,
1994). Item-based collaborative filtering, proposed by Sarwar et al. (2001), focuses on
finding similarities between items rather than users and has proven to be more scalable for
large datasets.
Despite their effectiveness, collaborative filtering techniques suffer from several limitations.
Cold-start problems occur when new users or new items lack sufficient interaction data,
making it difficult to generate accurate recommendations. Additionally, data sparsity is a
common challenge, as users typically interact with only a small fraction of available items.
These issues can significantly degrade recommendation accuracy in real-world applications
(Schafer et al., 2007).
However, content-based filtering also has drawbacks. It tends to recommend items that are
very similar to those already consumed by the user, leading to over-specialization and
limited diversity in recommendations. Furthermore, the quality of recommendations heavily
depends on the availability and accuracy of item feature descriptions (Lops et al., 2011).
Recent research trends focus on integrating deep learning and neural networks into
recommendation systems. Deep learning models can capture complex, non-linear
relationships in user behavior and product features, enabling more accurate and context-
aware recommendations (Zhang et al., 2019). Additionally, real-time recommendation
systems that adapt dynamically to user behavior have gained importance, especially in fast-
changing e-commerce environments.
In the context of this project, the reviewed literature highlights the importance of using a
hybrid recommendation approach supported by machine learning algorithms to address
personalization, scalability, and cold-start challenges. The proposed E-Commerce Product
Recommendation System aligns with existing research by combining collaborative and
content-based techniques using Python-based machine learning frameworks and a scalable
web architecture. This approach ensures accurate, efficient, and adaptive recommendations
suitable for modern e-commerce platforms.
TECHNOLOGY SURVEY
HARDWARE REQUIREMENTS
SOFTWARE REQUIREMENTS
Windows 10 serves as the primary operating system for the development and execution of the
project. It provides a stable, user-friendly, and widely supported environment suitable for
software development and testing. Windows 10 supports a wide range of development tools,
libraries, and frameworks required for Python-based web applications and machine learning
systems. Its compatibility with popular IDEs, web servers, and database management systems
makes it an ideal choice for developing the proposed system.
The frontend of the system is developed using standard web technologies to provide an
interactive and user-friendly interface.
HTML (HyperText Markup Language) is used to structure the web pages and define the
layout of content such as product listings, recommendation sections, login forms, and
dashboards.
CSS (Cascading Style Sheets) is responsible for styling the application. It enhances the
visual appearance of the web pages by controlling colors, fonts, layouts, and responsiveness.
JavaScript adds interactivity to the frontend. It is used to handle dynamic elements such as
form validation, asynchronous requests, and user interactions without reloading the page.
Bootstrap is a frontend framework that simplifies responsive web design. It ensures that the
application interface adapts seamlessly across different screen sizes and devices, improving
accessibility and usability.
Python is the core backend programming language used in this project. It is a high-level,
interpreted language known for its simplicity, readability, and extensive library support.
Python is particularly suitable for machine learning and data analysis, making it an excellent
choice for implementing recommendation algorithms.
Python enables efficient handling of backend logic such as user authentication, product
management, data processing, and interaction with the database. Its strong community
support and rich ecosystem significantly reduce development time and complexity.
Framework: Flask
Flask is a lightweight Python web framework used to build the backend of the application. It
follows a minimalistic approach, providing flexibility and control over application design.
Flask is used to:
Handle HTTP requests and responses
Develop RESTful APIs
Connect frontend components with backend logic
Integrate machine learning models into the web application
Its modular structure allows developers to add only the required extensions, making the
system efficient and scalable. Flask is well-suited for small to medium-sized applications
such as the proposed recommendation system.
Database: MySQL
MySQL is a relational database management system used for storing and managing
application data. It is reliable, efficient, and widely used in web-based applications.
In this project, MySQL stores:
User details
Product information
User–product interactions
Ratings and transaction history
MySQL ensures data integrity through constraints and relationships and supports efficient
querying for real-time recommendation generation. It integrates seamlessly with Python
using database connectors, enabling smooth data exchange between the application and the
database.
Pandas is used for data manipulation and preprocessing. It allows efficient handling of
structured data such as user ratings and product details, enabling data cleaning,
transformation, and analysis.
Scikit-learn is a powerful machine learning library that provides algorithms for collaborative
filtering, similarity computation, clustering, and model evaluation. It is used to implement
recommendation algorithms such as k-Nearest Neighbors and similarity-based filtering.
Apache is used as the web server to deploy the application. It is a robust, open-source server
that handles incoming client requests and delivers web pages efficiently. Apache ensures
reliable communication between the client browser and the Flask backend application. Its
stability and security features make it suitable for hosting web applications.
The selected software tools collectively provide a robust and efficient environment for
developing the E-Commerce Product Recommendation System. The integration of
Python, Flask, MySQL, and machine learning libraries ensures accurate recommendation
generation, while frontend technologies and deployment tools enhance usability and
performance. This software stack supports scalability, maintainability, and future
enhancements of the system.
DETAILED SYSTEM DESIGN
SYSTEM ARCHITECTURE
MODULE DESIGN
Handles user registration, login, authentication, and profile management. Stores user
preferences and interaction history.
Manages product details such as categories, prices, descriptions, and ratings. Provides
structured product data for recommendations.
Tracks user activities like product views, searches, clicks, and purchases to build user
profiles.
Allows users to search and filter products based on categories, price range, and relevance.
6. Admin Module
FLOW DIAGRAM
DATASET
This dataset contains user product ratings & reviews useful for building collaborative &
hybrid recommenders.
🔗 Download Link:
[Link]
When extracting results and building machine learning models, the following features are
most relevant:
1. userId
Uniquely identifies a customer. Helpful for building user profiles and tracking preferences.
2. productId
3. rating
Serves as the implicit/explicit feedback for the recommender (higher value means stronger
preference).
4. timestamp
5. reviewText
Algorithm Used
K-Nearest Neighbors (KNN)
Cosine Similarity / Pearson Correlation
How the Algorithm Works
Collaborative filtering recommends products by analyzing user–item interaction patterns
(ratings, purchases, clicks).
User-based filtering:
Finds users with similar preferences and recommends products liked by similar users.
Item-based filtering:
Finds products similar to the ones a user has interacted with and recommends them.
Similarity is computed using metrics like:
Cosine Similarity
Pearson Correlation
How It Is Used in This Project
Input data: user_id, product_id, rating
A user-product matrix is created.
Similar users or items are identified.
Products not yet interacted with by the user are recommended.
Outputs Generated
List of top-N recommended products
Similar users or similar products
Recommendation scores (similarity values)
CODING AND IMPLEMENTATION
SAMPLE CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>E-Commerce Product Recommendation System</title>
<link rel="stylesheet"
href="[Link]
</head>
<body class="bg-light">
<script>
function getRecommendations() {
const userId = [Link]("userId").value;
fetch(`[Link]
.then(response => [Link]())
.then(data => {
let list = [Link]("recommendations");
[Link] = "";
for (let product in data) {
[Link] += `<li>Product ${product} - Score: $
{data[product].toFixed(2)}</li>`;
}
});
}
function getSimilarProducts() {
const productId = [Link]("productId").value;
fetch(`[Link]
.then(response => [Link]())
.then(data => {
let list = [Link]("similarProducts");
[Link] = "";
for (let product in data) {
[Link] += `<li>Product ${product} - Similarity: $
{data[product].toFixed(2)}</li>`;
}
});
}
function getUserProfile() {
const userId = [Link]("profileUserId").value;
fetch(`[Link]
.then(response => [Link]())
.then(data => {
[Link]("userProfile").textContent =
[Link](data, null, 2);
});
}
</script>
</body>
</html>
IMPLEMENTATION PLAN
Initially, the dataset containing user–product interactions such as ratings and purchase history
was collected and preprocessed. Data preprocessing involved handling missing values,
removing inconsistencies, and transforming raw data into a structured format suitable for
machine learning. A user–item interaction matrix was created using the cleaned dataset,
which served as the foundation for collaborative filtering. Missing ratings were handled by
assigning zero values to maintain matrix consistency.
The recommendation logic was implemented using collaborative filtering techniques with
cosine similarity. User similarity and item similarity matrices were computed to identify
users with similar preferences and products with similar interaction patterns. Based on these
similarity scores, predicted ratings for unrated products were calculated. The system then
generated top-N product recommendations for each user, similar product lists for selected
products, and user preference profiles summarizing user behavior.
The backend of the system was developed using the Flask framework. Flask REST APIs
were created to expose recommendation functionalities such as retrieving personalized
recommendations, similar products, and user profiles. These APIs acted as an interface
between the frontend and the machine learning engine. JSON was used as the data exchange
format to ensure smooth communication between components.
The frontend was implemented using HTML, CSS, JavaScript, and Bootstrap to provide a
user-friendly and responsive interface. Users could input their User ID or Product ID through
the interface, and the frontend dynamically displayed recommendations received from the
Flask APIs. This real-time interaction enhanced usability and demonstrated the practical
application of the recommendation system.
The system was tested using different user inputs to validate the accuracy of
recommendations. Performance evaluation was conducted using metrics such as RMSE and
MAE to measure prediction accuracy.
Testing
Unit Testing
Unit testing was performed on individual modules of the system to verify their correctness.
The data preprocessing module was tested to ensure proper handling of missing values,
normalization of ratings, and creation of the user–item interaction matrix. The collaborative
filtering module was tested by validating similarity calculations using cosine similarity and
checking predicted rating outputs for different users. Flask API endpoints were also unit
tested to ensure they returned valid JSON responses for various input values.
Integration Testing
Integration testing focused on verifying the interaction between different system components.
The integration between the machine learning recommendation engine and the Flask backend
was tested to ensure that API calls correctly triggered the recommendation logic. The
frontend was tested to confirm that user inputs were properly sent to the backend and that
responses were displayed accurately on the user interface. Database connectivity between
Flask and MySQL was validated to ensure seamless data retrieval and storage.
System Testing
System testing was conducted to evaluate the complete functionality of the application in a
real-world scenario. Various test cases were executed using different User IDs and Product
IDs to validate top-N recommendations, similar product listings, and user preference profiles.
Edge cases such as new users, users with limited interaction history, and products with fewer
ratings were also tested. The system was verified to handle invalid inputs gracefully by
providing appropriate error messages.
The frontend interface was tested for usability, responsiveness, and browser compatibility.
The system was tested on Google Chrome to ensure proper rendering of HTML elements,
buttons, and dynamic content. User interactions such as form inputs, button clicks, and data
display were verified to provide a smooth and intuitive experience.
Deployment
Deployment involves making the system available for real-world use after successful testing.
The E-Commerce Product Recommendation System was deployed in a controlled
environment using standard deployment practices to ensure reliability, scalability, and ease of
access.
Local Deployment
Initially, the system was deployed locally for development and testing purposes. The Flask
application was executed using the built-in development server. MySQL was configured
locally to store user, product, and rating data. This setup allowed developers to test new
features, debug issues, and validate system performance before production deployment.
For production-level deployment, the application was configured to run on the Apache web
server. Apache was used to handle incoming HTTP requests and forward them to the Flask
application using appropriate configurations. This setup improved system stability and
performance compared to the development server. Environment variables were configured to
securely manage database credentials and application settings.
Database Deployment
The MySQL database was deployed with proper schema design and indexing to support
efficient querying. Backup mechanisms were configured to prevent data loss. Access control
policies were implemented to ensure database security and restrict unauthorized access.
Basic security measures were implemented during deployment, including input validation,
secure database connections, and restricted access to administrative functions. The system
was designed to support future maintenance and upgrades, such as incorporating advanced
recommendation algorithms, scaling the database, and enhancing frontend features.
The deployment architecture allows for future enhancements such as cloud-based hosting,
load balancing, and containerization using Docker. The modular nature of the system enables
easy integration with existing e-commerce platforms and supports scalability as the number
of users and products increases.
RESULT ANALYSIS & PERFORMANCE EVALUATION
The Root Mean Square Error (RMSE) graph represents the variation in prediction error
across different model iterations. From the graph, it is observed that the RMSE values show a
gradual decreasing trend as the model improves. This indicates that the difference between
predicted ratings and actual user ratings reduces over time.
Lower RMSE values signify that the recommendation model is able to predict user
preferences more accurately. The reduction in RMSE demonstrates the effectiveness of
collaborative filtering in capturing similarities among users and products. The stable RMSE
values across later iterations also indicate that the model has converged and is not overfitting
the data.
Inference:
The decreasing RMSE confirms that the recommendation system produces accurate
predictions and improves as more interaction data becomes available.
The Mean Absolute Error (MAE) graph illustrates the average absolute difference between
predicted and actual ratings. Compared to RMSE, MAE provides a more interpretable
measure of error by treating all deviations equally.
From the MAE graph, it is observed that MAE values consistently decrease across iterations,
indicating enhanced prediction accuracy. The relatively low MAE values show that the
system maintains consistent performance across users and products.
Inference:
The low MAE values indicate reliable prediction accuracy and confirm that the
recommendation engine performs well across diverse user interactions.
Both RMSE and MAE graphs demonstrate a similar trend of decreasing error values. RMSE
penalizes larger errors more heavily, while MAE provides an average error measure. The
consistency between both metrics indicates balanced model performance and robustness.
Inference:
The combined analysis of RMSE and MAE confirms that the collaborative filtering algorithm
is stable, accurate, and suitable for real-world e-commerce recommendation scenarios.
The bar chart showing Top Recommended Products represents the frequency with which
specific products are recommended to users. Certain products appear more frequently,
indicating higher popularity or stronger relevance across multiple user profiles.
This outcome reflects the system’s ability to identify trending and highly preferred products
based on collective user behavior. The variation in recommendation counts demonstrates
personalization, as not all products are recommended uniformly.
Inference:
The system effectively captures product popularity and user interest patterns, leading to
meaningful and diverse recommendations.
The system successfully generates a ranked list of products for each user based on predicted
ratings. These recommendations help users discover products aligned with their preferences,
thereby reducing search effort.
Predicted Ratings
Predicted ratings provide insight into how much a user is likely to prefer a product. Higher
predicted scores indicate strong relevance, enabling accurate ranking of recommendations.
User profiles summarize interaction behavior, average ratings, and preferred products. This
helps in understanding user interests and enhances personalization.
Overall System Performance
The result analysis confirms that the E-Commerce Product Recommendation System
performs effectively in terms of accuracy, relevance, and scalability. The graphical evaluation
metrics validate the prediction capability of the collaborative filtering model, while
recommendation outputs demonstrate practical usability.
Conclusion
The system integrates data preprocessing, recommendation logic, backend APIs, and a user-
friendly frontend into a cohesive web-based application. The use of Python and Flask enables
efficient backend processing, while MySQL ensures reliable data storage and retrieval.
Machine learning libraries such as Scikit-learn, NumPy, and Pandas support accurate
computation of similarity measures and predicted ratings.
Performance evaluation using metrics such as RMSE and MAE confirms that the
recommendation model provides accurate predictions with minimal error. Graphical analysis
further validates the effectiveness of the system in identifying popular products and
delivering personalized recommendations. The frontend interface allows users to easily
interact with the system and obtain real-time recommendations, enhancing overall usability.
In conclusion, the project achieves its objectives of reducing information overload, improving
user engagement, and providing personalized shopping experiences. The modular design and
scalable architecture make the system suitable for real-world e-commerce applications and
future enhancements.
Future Scope
Although the current system performs effectively, there is significant scope for future
improvement and expansion:
1. Hybrid Recommendation System
The system can be enhanced by combining collaborative filtering with content-based
filtering to overcome cold-start problems and improve recommendation diversity.
2. Deep Learning Integration
Advanced models such as neural networks and deep learning-based recommenders
can be incorporated to capture complex user behavior patterns and improve prediction
accuracy.
3. Real-Time Recommendation Updates
Implementing streaming data processing would allow recommendations to adapt
instantly to user actions such as clicks and purchases.
4. Scalability and Cloud Deployment
The application can be deployed on cloud platforms with load balancing and
distributed databases to support large-scale users and product catalogs.
5. Enhanced User Profiling
Additional features such as demographic data, browsing duration, and session analysis
can be included to build richer user profiles.
6. Mobile Application Integration
The system can be extended to mobile platforms to provide recommendations through
Android or iOS applications.
7. Business Analytics Dashboard
Admin dashboards with advanced analytics can be developed to monitor user
behavior, product performance, and recommendation effectiveness.
BIBLIOGRAPHY
Adomavicius, G., & Tuzhilin, A. (2005). Toward the next generation of recommender
systems: A survey of the state-of-the-art and possible extensions. IEEE Transactions on
Knowledge and Data Engineering, 17(6), 734–749.
Burke, R. (2002). Hybrid recommender systems: Survey and experiments. User Modeling
and User-Adapted Interaction, 12(4), 331–370.
Koren, Y., Bell, R., & Volinsky, C. (2009). Matrix factorization techniques for recommender
systems. IEEE Computer, 42(8), 30–37.
Lops, P., De Gemmis, M., & Semeraro, G. (2011). Content-based recommender systems:
State of the art and trends. Recommender Systems Handbook, 73–105.
Pazzani, M. J., & Billsus, D. (2007). Content-based recommendation systems. The Adaptive
Web, 325–341.
Resnick, P., Iacovou, N., Suchak, M., Bergstrom, P., & Riedl, J. (1994). GroupLens: An open
architecture for collaborative filtering of netnews. Proceedings of the ACM Conference on
Computer Supported Cooperative Work, 175–186.
Ricci, F., Rokach, L., & Shapira, B. (2011). Introduction to recommender systems handbook.
Springer.
Sarwar, B., Karypis, G., Konstan, J., & Riedl, J. (2001). Item-based collaborative filtering
recommendation algorithms. Proceedings of the 10th International World Wide Web
Conference, 285–295.
Schafer, J. B., Frankowski, D., Herlocker, J., & Sen, S. (2007). Collaborative filtering
recommender systems. The Adaptive Web, 291–324.
Zhang, S., Yao, L., Sun, A., & Tay, Y. (2019). Deep learning based recommender system: A
survey and new perspectives. ACM Computing Surveys, 52(1), 1–38.
APPENDIX
SAMPLE CODE
import pandas as pd
import numpy as np
# Load dataset
data = pd.read_csv("[Link]")
print([Link]())
user_item_matrix = data.pivot_table(
index='user_id',
columns='product_id',
values='rating'
)
print(user_item_matrix_filled.head())
user_similarity = cosine_similarity(user_item_matrix_filled)
user_similarity_df = [Link](
user_similarity,
index=user_item_matrix_filled.index,
columns=user_item_matrix_filled.index
)
print(user_similarity_df.head())
def predict_ratings(user_item_matrix, similarity_matrix):
return similarity_matrix.dot(user_item_matrix) / \
[Link]([[Link](similarity_matrix).sum(axis=1)]).T
predicted_ratings = predict_ratings(
user_item_matrix_filled.values,
user_similarity
)
predicted_ratings_df = [Link](
predicted_ratings,
index=user_item_matrix_filled.index,
columns=user_item_matrix_filled.columns
)
print(predicted_ratings_df.head())
def get_top_n_recommendations(user_id, n=5):
user_predictions = predicted_ratings_df.loc[user_id]
user_actual = user_item_matrix.loc[user_id]
# Example
print("Top-N Recommendations for User 1:")
print(get_top_n_recommendations(user_id=1, n=5))
item_similarity = cosine_similarity(user_item_matrix_filled.T)
item_similarity_df = [Link](
item_similarity,
index=user_item_matrix_filled.columns,
columns=user_item_matrix_filled.columns
)
# Example
print("Products similar to Product 101:")
print(get_similar_products(product_id=101))
def user_profile(user_id):
user_data = data[data['user_id'] == user_id]
avg_rating = user_data['rating'].mean()
total_ratings = user_data.shape[0]
profile = {
"User ID": user_id,
"Average Rating": avg_rating,
"Total Interactions": total_ratings,
"Top Rated Products": user_data.sort_values(
by='rating', ascending=False
).head(3)['product_id'].tolist()
}
return profile
# Example
print("User Preference Profile:")
print(user_profile(user_id=1))
train_data, test_data = train_test_split(data, test_size=0.2, random_state=42)
train_matrix = train_data.pivot_table(
index='user_id',
columns='product_id',
values='rating'
).fillna(0)
test_matrix = test_data.pivot_table(
index='user_id',
columns='product_id',
values='rating'
).fillna(0)
def calculate_metrics(actual, predicted):
actual = [Link]()
predicted = [Link]()
print("RMSE:", rmse)
print("MAE:", mae)