Index.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reservation Cancellation Prediction</title>
<!-- Bootstrap CSS -->
<link
href="[Link]
rel="stylesheet">
<!-- Link to your CSS file -->
<link href="{{ url_for('static', filename='[Link]') }}" rel="stylesheet">
</head>
<body>
<div class="background">
<div class="container">
<h1 class="text-center">Reservation Cancellation Prediction</h1>
<form action="/predict" method="post" class="mt-4">
<div class="form-group">
<label for="adults">Adults:</label>
<input type="number" name="adults" class="form-control"
required value="{{ [Link]('adults', '') }}">
</div>
<div class="form-group">
<label for="children">Children:</label>
<input type="number" name="children" class="form-control"
required value="{{ [Link]('children', '') }}">
</div>
<div class="form-group">
<label for="weekday_nights">Weekday Nights:</label>
<input type="number" name="weekday_nights" class="form-
control" required value="{{ [Link]('weekday_nights', '') }}">
</div>
<div class="form-group">
<label for="weekend_nights">Weekend Nights:</label>
<input type="number" name="weekend_nights" class="form-
control" required value="{{ [Link]('weekend_nights', '') }}">
</div>
<div class="form-group">
<label for="lead_time">Lead Time:</label>
<input type="number" name="lead_time" class="form-control"
required value="{{ [Link]('lead_time', '') }}">
</div>
<div class="form-group">
<label for="previous_cancellations">Previous
Cancellations:</label>
<input type="number" name="previous_cancellations"
class="form-control" required
value="{{ [Link]('previous_cancellations', '') }}" >
</div>
<div class="form-group">
<label for="special_requests">Special Requests:</label>
<input type="number" name="special_requests" class="form-
control" required value="{{ [Link]('special_requests', '') }}" >
</div>
<button type="submit" class="btn btn-primary btn-
block">Predict</button>
</form>
</div>
</div>
<!-- Bootstrap JS and dependencies -->
<script src="[Link]
<script
src="[Link]
script>
<script
src="[Link] ></sc
ript>
</body>
</html>
[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prediction Result</title>
<!-- Bootstrap CSS -->
<link
href="[Link]
rel="stylesheet">
<!-- Link to your CSS file -->
<link href="{{ url_for('static', filename='[Link]') }}" rel="stylesheet">
</head>
<body>
<div class="container text-center">
<h1>Prediction Result</h1>
<div class="mt-4">
{% if result == "Reservation will Cancel" %}
<div class="alert alert-danger" role="alert">
{{ result }}
</div>
{% else %}
<div class="alert alert-success" role="alert">
{{ result }}
</div>
{% endif %}
</div>
<div class="mt-4">
<a href="/" class="btn btn-primary">Go Back</a>
</div>
</div>
<!-- Bootstrap JS and dependencies -->
<script src="[Link]
<script
src="[Link]
script>
<script
src="[Link] ></sc
ript>
</body>
</html>
[Link]:
body {
background-color: #f8f9fa; /* Light background color */
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 110vh;
overflow: auto; /* Ensure no scrollbars if unnecessary */
}
.background {
background-image: url('/static/[Link]'); /* Corrected path */
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 120vh; /* Full viewport height */
width: 100vw; /* Full viewport width */
position: absolute;
}
.container {
margin-top: 10px;
padding: 20px;
background-color: rgba(255, 255, 255, 0.9); /* Semi-transparent white */
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin-left: auto;
margin-right: auto;
}
.alert {
font-size: 1.2em;
font-weight: bold;
}
.btn-primary {
margin-top: 20px;
}
[Link]:
from flask import Flask, render_template, request
import numpy as np
import joblib
app = Flask(__name__)
# Load the trained model
model = [Link]('reservation_cancellation_model.pkl')
@[Link]('/')
def home():
return render_template('[Link]')
@[Link]('/predict', methods=['POST'])
def predict():
try:
# Collect data from the form
features = [
float([Link]['adults']),
float([Link]['children']),
float([Link]['weekday_nights']),
float([Link]['weekend_nights']),
float([Link]['lead_time']),
float([Link]['previous_cancellations']),
float([Link]['special_requests'])
]
input_data = [Link]([features])
prediction = [Link](input_data)[0]
result = "Reservation will Cancel" if prediction == 1 else "Reservation
will Not Cancel"
return render_template('[Link]', result=result)
except Exception as e:
return f"Error: {e}"
if __name__ == "__main__":
[Link](debug=True)
Model_training.py:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from [Link] import RandomForestClassifier
from [Link] import accuracy_score, precision_score, recall_score,
f1_score
import joblib
# Load dataset from CSV file
data = pd.read_csv('data/[Link]')
# Features and target variable
X = [Link]('is_canceled', axis=1)
y = data['is_canceled']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
# Train the Random Forest model
model = RandomForestClassifier(random_state=42)
[Link](X_train, y_train)
# Evaluate the model
y_pred = [Link](X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
print("Precision:", precision_score(y_test, y_pred))
print("Recall:", recall_score(y_test, y_pred))
print("F1 Score:", f1_score(y_test, y_pred))
# Save the trained model
[Link](model, 'reservation_cancellation_model.pkl')
[Link]:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from [Link] import RandomForestClassifier
from [Link] import accuracy_score, precision_score, recall_score,
f1_score
import joblib
# Load dataset from CSV file
data = pd.read_csv('data/[Link]')
# Features and target variable
X = [Link]('is_canceled', axis=1)
y = data['is_canceled']
# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
# Train the Random Forest model
model = RandomForestClassifier(random_state=42)
[Link](X_train, y_train)
# Evaluate the model
y_pred = [Link](X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))
print("Precision:", precision_score(y_test, y_pred))
print("Recall:", recall_score(y_test, y_pred))
print("F1 Score:", f1_score(y_test, y_pred))
# Save the trained model
[Link](model, 'reservation_cancellation_model.pkl')