如何在HTML页面上获取我的线性回归模型的预测值

时间:2019-07-16 07:14:28

标签: python html django machine-learning

我正在通过django项目准备机器学习模型,但无法通过views.py到html页面获取该值。

我尝试过使用相同的概念在html页面上打印任何值,但是当我将其发送给我的机器学习模型时却无法获取该值。

Views.py:

from django.shortcuts import render,HttpResponse
import pandas as pd
import statsmodels.formula.api as sm

def pricepred(request):
     wine =  pd.read_csv('https://drive.google.com/file/d/1Eww8ChM1ZQgwCCKkMiUBi1xcs39R6C45/view')
    model = sm.ols('Price ~ AGST + HarvestRain + WinterRain + Age', data=wine).fit()
    d = {'Year': pd.Series([2019]), 'WinterRain': pd.Series([700]), 'AGST': pd.Series([15]),
     'HarvestRain': pd.Series([100]), 'Age': pd.Series([10]), 'FrancePop': pd.Series([90000.000])}
    df_test = pd.DataFrame(d)
    predictDF = model.predict(df_test)
    context = {
        'pred': predictDF
    }
    return render(request, 'pricepred.html', context)

pricepred.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {% load static %}
    <title>Real Price</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" type="text/css">
    <link href="{% static 'CSS/style.css' %}" type="text/css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
    </script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

  </head>
 <body>
 <div class="container-fluid">
  <h1>Welcome to Price Prediction Page</h1>

            {{ pred }}

  </div>

</body>
</html>

urls.py:

from django.urls import path
from . import views

urlpatterns = [
    path('pricepred/', views.pricepred),
]

我希望在html页面上输出“ pred”,即prediictDF的值,但是在pricepred页面上却收到“ urlopen错误[Errno 11001] getaddrinfo失败”

0 个答案:

没有答案