23.02.15-django,HTML

류소리·2023년 2월 15일
0

장고

목록 보기
9/9

김석훈 - 웹.

웹생성 : python manage.py startapp ml
cakd8 setting.py 에 등록
cakd8 urls.py : path('ml/', include('ml.urls')),
ml에 urls.py 만들어줌.

https://terryvery.tistory.com/63

from django.shortcuts import render
import joblib
import pandas as pd
import pickle

def inputdata(request):
    return render(request, 'ml/inputdata.html')

def ml_result(request):
    cls = joblib.load('ml/tcl_model.pkl')

    df = pd.DataFrame (columns= ['fare_cat', 'age_cat', 'family', 'female', 'male',
       'town_C', 'town_Q', 'town_S'] )
          
    lis =[]
        
    lis.append(request.GET['fare_cat'])
    lis.append(request.GET['age_cat'])
    lis.append(request.GET['family'])
    lis.append(request.GET['female'])
    lis.append(request.GET['male'])
    lis.append(request.GET['town_C'])
    lis.append(request.GET['town_Q'])
    lis.append(request.GET['town_S'])

    df.loc[0,:] = lis
    ans = cls.predict(df)
    if ans ==0:
        ans ='Dead'
    else:
        ans ="Sevived"
    return render(request, 'm;/ml_result.html',{'lis':lis, 'ans':ans})        

{% extends 'blog/base_full_width.html' %}
{% load crispy_forms_tags %}
{% block head_title %}ml_inputdata{% endblock %}

{% block main_area %}
<h1>타이타닉 생존자 예측</h1><br>
<h2>Input Data</h2><br>

    <form action="{% url 'ml_result' %}">
        fare_cat: <input type="text" required name ="fare_cat"><br>
        age_cat: <input type="text" required name ="age_cat"><br>
        family: <input type="text" required name ="family"><br>
        female: <input type="text" required name ="female"><br>
        male: <input type="text" required name ="male"><br>
        town_C: <input type="text" required name ="town_C"><br>
        town_Q: <input type="text" required name ="town_Q"><br>
        town_S: <input type="text" required name ="town_S"><br>
                <input type='submit' name="" value="submit">
    </form>   
{% endblock %}

nabvar add

<li class="nav-item">
                    <a class="nav-link" href="/blog/">ML</a>
                </li>
profile
새싹 빅테이터 개발자

0개의 댓글