Model Prediction

parent 80ebb434
covid_ai @ d5035b1a
Subproject commit d5035b1a12ef412897415c7e9cc9438dd8106a2a
Temperature,Humidity,Rainfall,Soli_Water_availability,Seeds,havest,havest_Period_Days
28,29,27,1,26000,110000,105
28,29,27,1,26000,110000,105
28,29,27,1,26000,110000,105
32,28,29,1,26000,100000,99
32,28,29,1,26000,100000,99
32,28,29,1,26000,100000,99
32,28,29,1,26000,100000,99
33,28,28,1,26000,96000,95
33,28,28,1,26000,96000,95
33,28,28,1,26000,96000,95
This source diff could not be displayed because it is too large. You can view the blob instead.
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CovidapiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'covidapi'
# Generated by Django 4.0.4 on 2022-09-19 04:51
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Covid',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('Breathing_Problem', models.CharField(max_length=100, verbose_name='Breathing_Problem')),
('Fever', models.CharField(max_length=100, verbose_name='Fever')),
('Dry_Cough', models.CharField(max_length=100, verbose_name='Dry_Cough')),
('Sore_throat', models.CharField(max_length=100, verbose_name='Sore_throat')),
('Running_Nose', models.CharField(max_length=100, verbose_name='Running_Nose')),
('Asthma', models.CharField(max_length=100, verbose_name='Asthma')),
('Chronic_Lung_Disease', models.CharField(max_length=100, verbose_name='Chronic_Lung_Disease')),
('Headache', models.CharField(max_length=100, verbose_name='Headache')),
('Heart_Disease', models.CharField(max_length=100, verbose_name='Heart_Disease')),
('Diabetes', models.CharField(max_length=100, verbose_name='Diabetes')),
('Hyper_Tension', models.CharField(max_length=100, verbose_name='Hyper_Tension')),
('Fatigue', models.CharField(max_length=100, verbose_name='Fatigue')),
('Gastrointestinal', models.CharField(max_length=100, verbose_name='Gastrointestinal')),
('Abroad_travel', models.CharField(max_length=100, verbose_name='Abroad_travel')),
('Contact_with_COVID_Patient', models.CharField(max_length=100, verbose_name='Contact_with_COVID_Patient')),
('Attended_Large_Gathering', models.CharField(max_length=100, verbose_name='Attended_Large_Gathering')),
('Visited_Public_Exposed_Places', models.CharField(max_length=100, verbose_name='Visited_Public_Exposed_Places')),
('Family_working_in_Public_Exposed_Places', models.CharField(max_length=100, verbose_name='Family_working_in_Public_Exposed_Places')),
('Wearing_Masks', models.CharField(max_length=100, verbose_name='Wearing_Masks')),
('Sanitization_from_Market', models.CharField(max_length=100, verbose_name='Sanitization_from_Market')),
('covid_result', models.CharField(max_length=100, verbose_name='covid_result')),
],
),
]
from django.db import models
# Create your models here.
class Covid (models.Model) :
Breathing_Problem = models.CharField(("Breathing_Problem"), max_length=100)
Fever = models.CharField(("Fever"), max_length=100)
Dry_Cough = models.CharField(("Dry_Cough"), max_length=100)
Sore_throat = models.CharField(("Sore_throat"), max_length=100)
Running_Nose = models.CharField(("Running_Nose"), max_length=100)
Asthma = models.CharField(("Asthma"), max_length=100)
Chronic_Lung_Disease = models.CharField(("Chronic_Lung_Disease"), max_length=100)
Headache = models.CharField(("Headache"), max_length=100)
Heart_Disease = models.CharField(("Heart_Disease"), max_length=100)
Diabetes = models.CharField(("Diabetes"), max_length=100)
Hyper_Tension = models.CharField(("Hyper_Tension"), max_length=100)
Fatigue = models.CharField(("Fatigue"), max_length=100)
Gastrointestinal = models.CharField(("Gastrointestinal"), max_length=100)
Abroad_travel = models.CharField(("Abroad_travel"), max_length=100)
Contact_with_COVID_Patient = models.CharField(("Contact_with_COVID_Patient"), max_length=100)
Attended_Large_Gathering = models.CharField(("Attended_Large_Gathering"), max_length=100)
Visited_Public_Exposed_Places = models.CharField(("Visited_Public_Exposed_Places"), max_length=100)
Family_working_in_Public_Exposed_Places = models.CharField(("Family_working_in_Public_Exposed_Places"), max_length=100)
Wearing_Masks = models.CharField(("Wearing_Masks"), max_length=100)
Sanitization_from_Market = models.CharField(("Sanitization_from_Market"), max_length=100)
covid_result = models.CharField(("covid_result"), max_length=100)
from django.test import TestCase
# Create your tests here.
from django.urls import path
from . import views
urlpatterns = [
path('',views.getData),
path('add',views.addItem),
]
\ No newline at end of file
from tokenize import String
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework import serializers
import pandas as pd
import sqlite3
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import math
# Create your views here.
@api_view(['GET'])
def getData(request):
# Loading the Dataset
DateSet = pd.read_csv("assets/csv/covid.csv", skipinitialspace=True)
# variables
x = DateSet[['Fever', 'Headache', 'Dry_Cough','Sore_throat', 'Breathing_Problem']]
y = DateSet['covid_result']
# train test split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=2)
# LinearRegression algorithm
LR = LinearRegression()
LR.fit(x_train, y_train)
Fever = 1
Headache = 0
Dry_Cough = 1
Sore_throat = 1
Breathing_Problem = 0
new_input = [[int(Fever),int(Headache),int(Dry_Cough),int(Sore_throat),int(Breathing_Problem)]]
Predicted_value = LR.predict(x)
Predicted_covid = LR.predict(new_input)
print (Predicted_covid)
return Response(math.ceil(Predicted_covid[0]*100)/100)
@api_view(['POST'])
def addItem(request):
val = request.data
print(val['fever'])
print(val['headache'])
DateSet = pd.read_csv("assets/csv/covid.csv", skipinitialspace=True)
# variables
x = DateSet[['Fever', 'Headache', 'Dry_Cough','Sore_throat', 'Breathing_Problem']]
y = DateSet['covid_result']
# train test split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=2)
# LinearRegression algorithm
LR = LinearRegression()
LR.fit(x_train, y_train)
Fever = 1
Headache = 0
Dry_Cough = 1
Sore_throat = 1
Breathing_Problem = 0
if val['fever'] == "Yes":
val_fever = 1
else:
val_fever = 0
if val['headache'] == "Yes":
val_headache = 1
else:
val_headache = 0
if val['dry_cough'] == "Yes":
val_dry_cough = 1
else:
val_dry_cough = 0
if val['sor_throt'] == "Yes":
val_sor_throt = 1
else:
val_sor_throt = 0
if val['breathing_problem'] == "Yes":
val_breathing_problem = 1
else:
val_breathing_problemt = 0
new_input = [[int(val_fever),int(val_headache),int(val_dry_cough),int(val_sor_throt),int(val_breathing_problem)]]
Predicted_value = LR.predict(x)
Predicted_covid = LR.predict(new_input)
# print (Predicted_covid)
return Response(math.ceil(Predicted_covid[0]*100)/100)
# con = sqlite3.connect("db.sqlite3")
# df = pd.read_sql_query("SELECT * from covidapi_covid", con)
# rslt_df = df.loc[(df['Fever'] == val['fever']) & (df['Headache'] == val['headache']) & (df['Dry_Cough'] == val['dry_cough']) & (df['Sore_throat'] == val['sor_throt']) & (df['Breathing_Problem'] == val['breathing_problem'])& (df['covid_result'] == "Yes")]
# print(rslt_df.shape[0])
# return Response(rslt_df.shape[0])
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapi.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()
"""
ASGI config for myapi 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/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapi.settings')
application = get_asgi_application()
"""
Django settings for myapi project.
Generated by 'django-admin startproject' using Django 4.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-6sy-znsw%-l-wv@u++d#k75b9^e+5ra7-sik4y0-s%4e)&(&0u'
# 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',
'covidapi',
'rest_framework',
'corsheaders',
]
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',
'corsheaders.middleware.CorsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True
ROOT_URLCONF = 'myapi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'myapi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.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/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
"""myapi URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.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, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('covidapi.urls')),
]
"""
WSGI config for myapi 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/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapi.settings')
application = get_wsgi_application()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment