diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..9b70063 --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..81dd245 --- /dev/null +++ b/templates/home.html @@ -0,0 +1 @@ +

Titanic Survival Prediction algorithm

\ No newline at end of file diff --git a/templates/predict.html b/templates/predict.html new file mode 100644 index 0000000..3d9428d --- /dev/null +++ b/templates/predict.html @@ -0,0 +1,5 @@ +
+ {% csrf_token %} + {{form.as_p}} + +
diff --git a/titanic.pkl b/titanic.pkl new file mode 100644 index 0000000..91c3b0f Binary files /dev/null and b/titanic.pkl differ diff --git a/titanicsurvival/__init__.py b/titanicsurvival/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/titanicsurvival/__pycache__/__init__.cpython-37.pyc b/titanicsurvival/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..ec0e910 Binary files /dev/null and b/titanicsurvival/__pycache__/__init__.cpython-37.pyc differ diff --git a/titanicsurvival/__pycache__/settings.cpython-37.pyc b/titanicsurvival/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..d99dff3 Binary files /dev/null and b/titanicsurvival/__pycache__/settings.cpython-37.pyc differ diff --git a/titanicsurvival/__pycache__/urls.cpython-37.pyc b/titanicsurvival/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..8236e50 Binary files /dev/null and b/titanicsurvival/__pycache__/urls.cpython-37.pyc differ diff --git a/titanicsurvival/__pycache__/wsgi.cpython-37.pyc b/titanicsurvival/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..9afa8a7 Binary files /dev/null and b/titanicsurvival/__pycache__/wsgi.cpython-37.pyc differ diff --git a/titanicsurvival/asgi.py b/titanicsurvival/asgi.py new file mode 100644 index 0000000..fd8c15f --- /dev/null +++ b/titanicsurvival/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for titanicsurvival project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings') + +application = get_asgi_application() diff --git a/titanicsurvival/settings.py b/titanicsurvival/settings.py new file mode 100644 index 0000000..143e864 --- /dev/null +++ b/titanicsurvival/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for titanicsurvival project. + +Generated by 'django-admin startproject' using Django 3.0.2. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates') + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'e^vb$7ee7t3xdbpb5@bn$4e-a2182a%0v6crt0(_aotmo$jnkm' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'titanicsurvivalapp' + ] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'titanicsurvival.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [TEMPLATES_DIR], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'titanicsurvival.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/titanicsurvival/urls.py b/titanicsurvival/urls.py new file mode 100644 index 0000000..821179e --- /dev/null +++ b/titanicsurvival/urls.py @@ -0,0 +1,24 @@ +"""titanicsurvival URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path +from titanicsurvivalapp import views + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', views.home, name="home"), + path('predict', views.predict, name="predict") +] diff --git a/titanicsurvival/wsgi.py b/titanicsurvival/wsgi.py new file mode 100644 index 0000000..8f6c225 --- /dev/null +++ b/titanicsurvival/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for titanicsurvival project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'titanicsurvival.settings') + +application = get_wsgi_application() diff --git a/titanicsurvivalapp/__init__.py b/titanicsurvivalapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/titanicsurvivalapp/__pycache__/__init__.cpython-37.pyc b/titanicsurvivalapp/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..2251f9e Binary files /dev/null and b/titanicsurvivalapp/__pycache__/__init__.cpython-37.pyc differ diff --git a/titanicsurvivalapp/__pycache__/admin.cpython-37.pyc b/titanicsurvivalapp/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..1a060d2 Binary files /dev/null and b/titanicsurvivalapp/__pycache__/admin.cpython-37.pyc differ diff --git a/titanicsurvivalapp/__pycache__/forms.cpython-37.pyc b/titanicsurvivalapp/__pycache__/forms.cpython-37.pyc new file mode 100644 index 0000000..78483af Binary files /dev/null and b/titanicsurvivalapp/__pycache__/forms.cpython-37.pyc differ diff --git a/titanicsurvivalapp/__pycache__/models.cpython-37.pyc b/titanicsurvivalapp/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..130b5c9 Binary files /dev/null and b/titanicsurvivalapp/__pycache__/models.cpython-37.pyc differ diff --git a/titanicsurvivalapp/__pycache__/views.cpython-37.pyc b/titanicsurvivalapp/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..286e233 Binary files /dev/null and b/titanicsurvivalapp/__pycache__/views.cpython-37.pyc differ diff --git a/titanicsurvivalapp/admin.py b/titanicsurvivalapp/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/titanicsurvivalapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/titanicsurvivalapp/apps.py b/titanicsurvivalapp/apps.py new file mode 100644 index 0000000..d90b3fa --- /dev/null +++ b/titanicsurvivalapp/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TitanicsurvivalappConfig(AppConfig): + name = 'titanicsurvivalapp' diff --git a/titanicsurvivalapp/forms.py b/titanicsurvivalapp/forms.py new file mode 100644 index 0000000..519c245 --- /dev/null +++ b/titanicsurvivalapp/forms.py @@ -0,0 +1,17 @@ +from django import forms + + +class InputForm(forms.Form): + P_class = ( + ('1', '1st Class'), + ('2', '2nd Class'), + ('3', '3rd Class') + ) + gender = ( + ('0', 'Female'), + ('1', 'Male') + ) + name = forms.CharField(required=True) + passenger_class = forms.ChoiceField(choices=P_class, required=True) + age = forms.IntegerField(required=True) + gender = forms.ChoiceField(choices=gender) \ No newline at end of file diff --git a/titanicsurvivalapp/migrations/__init__.py b/titanicsurvivalapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/titanicsurvivalapp/migrations/__pycache__/__init__.cpython-37.pyc b/titanicsurvivalapp/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..d6760a1 Binary files /dev/null and b/titanicsurvivalapp/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/titanicsurvivalapp/models.py b/titanicsurvivalapp/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/titanicsurvivalapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/titanicsurvivalapp/tests.py b/titanicsurvivalapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/titanicsurvivalapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/titanicsurvivalapp/views.py b/titanicsurvivalapp/views.py new file mode 100644 index 0000000..eddf30d --- /dev/null +++ b/titanicsurvivalapp/views.py @@ -0,0 +1,23 @@ +from django.shortcuts import render +import pickle +import pandas as pd +from .forms import * + +# Create your views here. + +def home(request): + titanic_model = pickle.load(open("titanic.pkl", "rb")) + input_data = [[2.0, 18.0, 0.0, 1.0]] + data = pd.DataFrame(input_data, columns=['Pclass','Age', 'Sex_female', 'Sex_male']) + print(titanic_model.predict(data)) + return render(request, 'home.html') + +def predict(request): + if request.method == "GET": + form = InputForm() + return render(request, 'predict.html', {"form":form}) + if request.method == "POST": + form = InputForm(request.POST) + if form.is_valid(): + print(form['gender'].value()) + return render(request, 'predict.html') \ No newline at end of file