0% found this document useful (0 votes)
8 views11 pages

Capstone

Uploaded by

Hari Priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Capstone

Uploaded by

Hari Priya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CAPSTONE PROJECTS- PREDICTIVE ROUTE OPTIMIZATION

program:
FRONTEND:(HTML,CSS)
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Personalized Movie Recommendations</title>

<script src="https://cdn.tailwindcss.com"></script>

</head>

<body class="bg-gray-100">

<!-- Container -->

<div class="max-w-4xl mx-auto p-6 bg-white shadow-lg rounded-lg mt-10">

<!-- Header Section -->

<header class="text-center mb-8">

<h1 class="text-3xl font-bold text-blue-600">Personalized Movie Recommendations</h1>

<p class="text-lg text-gray-600">Get personalized movie suggestions based on your


preferences!</p>

</header>

<!-- Input Form Section -->

<section class="mb-6">

<h2 class="text-xl font-semibold text-gray-800 mb-4">Enter Your Preferences</h2>

<form id="userForm" class="space-y-4">

<!-- User ID -->

<div>

<label for="userId" class="block text-gray-700 font-semibold">User ID</label>

<input type="text" id="userId" name="userId" class="w-full p-3 border border-gray-300


rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter User ID"
required>

</div>
<!-- Movie Genre -->

<div>

<label for="genre" class="block text-gray-700 font-semibold">Movie Genre</label>

<select id="genre" name="genre" class="w-full p-3 border border-gray-300 rounded-lg


focus:outline-none focus:ring-2 focus:ring-blue-500" required>

<option value="action">Action</option>

<option value="comedy">Comedy</option>

<option value="drama">Drama</option>

<option value="horror">Horror</option>

<option value="romance">Romance</option>

</select>

</div>

<!-- Submit Button -->

<div>

<button type="submit" class="w-full p-3 bg-blue-600 text-white font-semibold rounded-lg


hover:bg-blue-700 transition duration-300">Get Recommendations</button>

</div>

</form>

</section>

<!-- Recommendations Section -->

<section id="recommendations">

<h2 class="text-xl font-semibold text-gray-800 mb-4">Recommended Movies</h2>

<div id="loadingSpinner" class="hidden text-center text-blue-600 mb-4">

<span class="text-lg font-semibold">Loading recommendations...</span>

</div>

<ul id="recList" class="space-y-4">

<!-- Recommendations will appear here -->

</ul>

<div id="errorMessage" class="hidden text-red-600 text-center mt-4">

<span class="text-lg font-semibold">Sorry, something went wrong. Please try again.</span>

</div>

</section>
</div>

<!-- JavaScript for handling form submission and displaying results -->

<script>

document.getElementById('userForm').addEventListener('submit', function (event) {

event.preventDefault();

const userId = document.getElementById('userId').value;

const genre = document.getElementById('genre').value;

// Show loading spinner while fetching recommendations

document.getElementById('loadingSpinner').classList.remove('hidden');

document.getElementById('recList').innerHTML = ''; // Clear previous recommendations

document.getElementById('errorMessage').classList.add('hidden');

// Simulate fetching recommendations (use a real backend in production)

setTimeout(() => {

// Hardcoded sample movie data based on genre

const recommendations = {

action: ["Die Hard", "Mad Max: Fury Road", "The Dark Knight", "John Wick"],

comedy: ["The Hangover", "Superbad", "Step Brothers", "Dumb and Dumber"],

drama: ["The Shawshank Redemption", "Forrest Gump", "The Godfather", "A Beautiful
Mind"],

horror: ["The Conjuring", "Get Out", "A Quiet Place", "Hereditary"],

romance: ["The Notebook", "Pride and Prejudice", "La La Land", "Titanic"]

};

const recList = document.getElementById('recList');

if (recommendations[genre]) {

recommendations[genre].forEach(movie => {

const li = document.createElement('li');

li.classList.add('p-4', 'bg-gray-200', 'rounded-lg', 'shadow');

li.textContent = movie;

recList.appendChild(li);

});

} else {
// Show error if genre is not valid

document.getElementById('errorMessage').classList.remove('hidden');

// Hide loading spinner

document.getElementById('loadingSpinner').classList.add('hidden');

}, 1000); // Simulating an API call with a 1-second delay

});

</script>

</body>

</html>
Backend:
import pandas as pd

from sklearn.metrics.pairwise import cosine_similarity

from sklearn.preprocessing import LabelEncoder

import numpy as np

# Sample user-item interaction data (userID, itemID, rating)

user_item_data = [

('user1', 'movie1', 5),

('user1', 'movie2', 3),

('user1', 'movie3', 4),

('user2', 'movie1', 4),

('user2', 'movie2', 2),

('user2', 'movie3', 5),

('user3', 'movie1', 3),

('user3', 'movie2', 5),

('user3', 'movie3', 4)

# Sample item metadata (itemID, genre)

item_metadata = [

('movie1', 'Action'),

('movie2', 'Drama'),

('movie3', 'Comedy')

# Sample user demographic data (userID, age, gender)

user_demographics = [

('user1', 25, 'M'),

('user2', 30, 'F'),

('user3', 22, 'M')

]
# Convert the data into pandas DataFrames

user_item_df = pd.DataFrame(user_item_data, columns=['userID', 'itemID', 'rating'])

item_metadata_df = pd.DataFrame(item_metadata, columns=['itemID', 'genre'])

user_demographics_df = pd.DataFrame(user_demographics, columns=['userID', 'age', 'gender'])

# Create a pivot table for user-item ratings

pivot_table = user_item_df.pivot_table(index='userID', columns='itemID', values='rating').fillna(0)

# Calculate the cosine similarity matrix between users

cosine_sim_users = cosine_similarity(pivot_table)

# Convert it into a DataFrame for easier interpretation

cosine_sim_users_df = pd.DataFrame(cosine_sim_users, index=pivot_table.index,


columns=pivot_table.index)

# Function to get recommendations for a user based on collaborative filtering

def collaborative_filtering(user_id, cosine_sim_df, pivot_table, top_n=2):

# Get the similarity scores for the user

user_similarities = cosine_sim_df[user_id]

# Sort the users based on similarity score

similar_users = user_similarities.sort_values(ascending=False)

# Remove the user itself from the list

similar_users = similar_users.drop(user_id)

# Get ratings from similar users

similar_user_ratings = pivot_table.loc[similar_users.index]

# Get the movies rated by the similar users

recommended_movies = similar_user_ratings.mean(axis=0)
# Sort movies based on predicted rating

recommended_movies = recommended_movies.sort_values(ascending=False)

# Return the top N recommended movies

return recommended_movies.head(top_n)

# Get recommendations for 'user1'

collab_recommendations = collaborative_filtering('user1', cosine_sim_users_df, pivot_table)

print("Collaborative Filtering Recommendations for user1:")

print(collab_recommendations)

# Convert genres into numerical values using LabelEncoder

label_encoder = LabelEncoder()

item_metadata_df['genre_encoded'] = label_encoder.fit_transform(item_metadata_df['genre'])

# Create a similarity matrix based on item metadata (e.g., genre similarity)

genre_similarity_matrix = cosine_similarity(item_metadata_df[['genre_encoded']])

# Convert the similarity matrix into a DataFrame for easier interpretation

genre_similarity_df = pd.DataFrame(genre_similarity_matrix, index=item_metadata_df['itemID'],


columns=item_metadata_df['itemID'])

# Function to get content-based recommendations

def content_based_filtering(item_id, genre_sim_df, top_n=2):

# Get the similarity scores for the item

item_similarities = genre_sim_df[item_id]

# Sort the items based on similarity score

similar_items = item_similarities.sort_values(ascending=False)

# Remove the item itself from the list

similar_items = similar_items.drop(item_id)
# Return the top N recommended items

return similar_items.head(top_n)

# Get content-based recommendations for 'movie1'

content_recommendations = content_based_filtering('movie1', genre_similarity_df)

print("Content-Based Filtering Recommendations for 'movie1':")

print(content_recommendations)

# Hybrid Recommendation Function (averaging collaborative and content-based scores)

def hybrid_recommendations(user_id, item_id, cosine_sim_users_df, pivot_table,


genre_similarity_df, top_n=2):

# Get collaborative recommendations

collaborative_rec = collaborative_filtering(user_id, cosine_sim_users_df, pivot_table, top_n)

# Get content-based recommendations

content_rec = content_based_filtering(item_id, genre_similarity_df, top_n)

# Merge the recommendations and average the scores

hybrid_rec = collaborative_rec.add(content_rec, fill_value=0)

hybrid_rec = hybrid_rec.sort_values(ascending=False)

return hybrid_rec.head(top_n)

# Get hybrid recommendations for 'user1' based on 'movie1'

hybrid_rec = hybrid_recommendations('user1', 'movie1', cosine_sim_users_df, pivot_table,


genre_similarity_df)

print("Hybrid Recommendations for user1 based on 'movie1':")

print(hybrid_rec)
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy