Skip to content

Instantly share code, notes, and snippets.

@akash-ch2812
Last active September 1, 2020 14:31
Show Gist options
  • Save akash-ch2812/71a2c85d9f2854b2d41c26817e5dad76 to your computer and use it in GitHub Desktop.
Save akash-ch2812/71a2c85d9f2854b2d41c26817e5dad76 to your computer and use it in GitHub Desktop.
from django.shortcuts import render
# our home page view
def home(request):
return render(request, 'index.html')
# custom method for generating predictions
def getPredictions(pclass, sex, age, sibsp, parch, fare, C, Q, S):
import pickle
model = pickle.load(open("titanic_survival_ml_model.sav", "rb"))
scaled = pickle.load(open("scaler.sav", "rb"))
prediction = model.predict(sc.transform([[pclass, sex, age, sibsp, parch, fare, C, Q, S]]))
if prediction == 0:
return "not survived"
elif prediction == 1:
return "survived"
else:
return "error"
# our result page view
def result(request):
pclass = int(request.GET['pclass'])
sex = int(request.GET['sex'])
age = int(request.GET['age'])
sibsp = int(request.GET['sibsp'])
parch = int(request.GET['parch'])
fare = int(request.GET['fare'])
embC = int(request.GET['embC'])
embQ = int(request.GET['embQ'])
embS = int(request.GET['embS'])
result = getPredictions(pclass, sex, age, sibsp, parch, fare, embC, embQ, embS)
return render(request, 'result.html', {'result':result})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment