generated from Nathaniel633/student1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitanic.html
94 lines (88 loc) · 2.77 KB
/
titanic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
permalink: /titanic/
layout: default
title: Titanic
search_exclude: true
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Titanic Survival Prediction</title>
</head>
<body>
<h1>Titanic Survival Prediction</h1>
<div>
<label for="passenger-class">Passenger Class:</label>
<select id="passenger-class">
<option value="1">First Class</option>
<option value="2">Second Class</option>
<option value="3">Third Class</option>
</select>
</div>
<div>
<label for="age">Age:</label>
<input type="number" id="age" min="0">
</div>
<div>
<label for="gender">Gender:</label>
<select id="gender">
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</div>
<div>
<label for="sibsp"># of Siblings and Spouses:</label>
<input type="number" id="sibsp" min="0">
</div>
<div>
<label for="parch"># of Parents and children on board:</label>
<input type="number" id="parch" min="0">
</div>
<div>
<label for="fare">Fare:</label>
<input type="number" id="fare" min="0">
</div>
<div>
<button onclick="predictSurvival()">Predict Survival</button>
</div>
<div id="prediction"></div>
<button onclick="displayText()">Click Me!</button>
<div id="textField" style="display: none;">
This is the text that appears when you click the button.
</div>
<script>
function predictSurvival() {
const Pclass = document.getElementById('passenger-class').value;
const Age = document.getElementById('age').value;
const Sex = document.getElementById('sex').value;
const SibSp = document.getElementById('sibsp').value;
const Parch = document.getElementById('parch').value;
const Fare = document.getElementById('fare').value;
const data = {
Pclass,
Sex,
Age,
SibSp,
Parch,
Fare
};
fetch('http://127.0.0.1:8087/api/titanic/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(prediction => {
document.getElementById('prediction').innerText = `Survival Prediction: ${prediction.message*100}%`;
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
</body>
</html>