基于Flask+Bootstrap+机器学习的南昌市租房价格预测系统

news2025/2/27 23:00:26

🤵‍♂️ 个人主页:@艾派森的个人主页

✍🏻作者简介:Python学习者
🐋 希望大家多多支持,我们一起进步!😄
如果文章对你有帮助的话,
欢迎评论 💬点赞👍🏻 收藏 📂加关注+


目录

一、项目介绍

1.1项目简介

1.2技术工具

1.3页面概述 

二、项目步骤

2.1登录模块

2.2注册模块

2.3训练模型模块

2.3.1导入数据

2.3.2查看数据

2.3.3数据预处理

2.3.4数据可视化

2.3.5特征工程

2.3.6构建模型

2.3.7保存模型

2.4预测房价模块

2.4查看房价信息模块

三、项目总结


一、项目介绍

1.1项目简介

         本项目使用Flask框架搭建基于机器学习的南昌市租房价格预测系统 (简易版)

其中关于Flask知识点可参考文章Flask全套知识点从入门到精通,学完可直接做项目

其中关于南昌市租房价格预测可参考文章基于XGBoost算法构造房屋租赁价格评估模型

整个项目分为以下几个模块:

  • 1.登录和注册模块
  • 2.训练模型模块
  • 3.预测价格模块
  • 4.查看房价信息模块 

项目文件框架如下:

其中manager.py为主程序,password.csv为存储用户账号密码的文件,lianjia是房租价格原始数据集,model.pkl是经过机器学习算法训练出的模型。 

1.2技术工具

IDE编辑器:vscode

后端框架:Flask

前端框架:Bootstrap

1.3页面概述 

运行manager.py程序后,浏览器打开http://127.0.0.1:5000/

映入眼帘的登录页面,有账号的话就之间输入用户名和密码,没有就点击Sign up先注册再登录 

 注册页面如下: 

 登录后进入主页面如下: 

 在导航栏中有训练模型、预测价格、查看房价信息、退出模块

 训练模型模块如下:

需要依次按照步骤进行构建模型

 预测房价模块:

在预测模块只需要输入地区、装修情况、楼层情况、电梯情况、房屋面积即可,每个输入类型都有提示(必须按照提示信息填写) 

 示例如下,填完信息后点击预测即可得到预测的房价信息:

 查看房价信息模块:

 在查看房价信息模块默认展示的是全部数据,当然你也可以通过输入价格区间进行筛选。

二、项目步骤

2.1登录模块

manager.py

class LoginView(views.MethodView):    
    def __jump(self,error=None):      
        return render_template('login.html',error=error)    
    def get(self, error=None):        
        return self.__jump()    
    def post(self):        
        uname = request.form['username']      
        pwd = int(request.form['password'])
        if uname and pwd:
            data = pd.read_csv('password.csv')
            for index,item in enumerate(data.values,1):        
                if uname == item[0] and pwd == item[1]:
                    return redirect('/main')         
                if index == len(data):           
                    return self.__jump(error="用户名或者密码错误")
        else:
            return self.__jump(error="用户名或者密码不能为空")
app.add_url_rule('/login/',view_func=LoginView.as_view('my_login'))

login.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>登录</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html {
            height: 100%;
        }

        body {
            height: 100%;
        }

        .container {
            height: 100%;
            background-image: linear-gradient(to right, #999999, #330867);
        }

        .login-wrapper {
            background-color: bisque;
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }

        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128, 125, 125);
            font-size: 15px;
            outline: none;
        }

        .input-item::placeholder {
            text-transform: uppercase;
        }

        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right, #a6c1ee, #fbc2eb);
            color: #fff;
        }

        .msg {
            text-align: center;
            line-height: 88px;
        }

        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
</head>

<body>
    <div class="container">

        <div class="login-wrapper">
            <form action="/login/" method="post">
                <div class="header">Login</div>
                <div class="form-wrapper">
                    <input type="text" name="username" placeholder="username" class="input-item">
                    <input type="password" name="password" placeholder="password" class="input-item">
                    {% if error %}
                    <font color="red">{{ error }}</font>
                    {% endif %}
                    <input class="btn" type="submit" value="立即登录">
                </div>
                <div class="msg">
                    Don't have account?
                    <a href="{{url_for('my_register')}}">Sign up</a>

                </div>
            </form>

        </div>


    </div>
</body>

</html>

2.2注册模块

manager.py

# 注册类视图
class RegisterView(views.MethodView):    
    def __jump(self,error=None):      
        return render_template('register.html',error=error)    
    def get(self,error=None):        
        return self.__jump()    
    def post(self):        
        # 模拟实现     
        uname = request.form['username']      
        pwd = request.form['password'] 
        print(uname,pwd) 
        if uname and pwd:
            with open('password.csv','a',encoding='utf-8',newline='\n')as f:  
                cswriter = csv.writer(f)
                cswriter.writerow((uname,pwd))
                f.flush()  
                
            return redirect('/login')     
        else:            
            return self.__jump(error="用户名或者密码不能为空")
app.add_url_rule('/register/',view_func=RegisterView.as_view('my_register'))

register.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>

    <style>
        * {
            margin: 0;
            padding: 0;
        }
        html {
            height: 100%;
        }
        body {
            height: 100%;
        }
        .container {
            height: 100%;
            background-image: linear-gradient(to right, #999999, #330867);
        }
        .login-wrapper {
            background-color: bisque;
            width: 358px;
            height: 588px;
            border-radius: 15px;
            padding: 0 50px;
            position: relative;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
        .header {
            font-size: 38px;
            font-weight: bold;
            text-align: center;
            line-height: 200px;
        }
        .input-item {
            display: block;
            width: 100%;
            margin-bottom: 20px;
            border: 0;
            padding: 10px;
            border-bottom: 1px solid rgb(128,125,125);
            font-size: 15px;
            outline: none;
        }
        .input-item::placeholder {
            text-transform: uppercase;
        }
        .btn {
            text-align: center;
            padding: 10px;
            width: 100%;
            margin-top: 40px;
            background-image: linear-gradient(to right,#a6c1ee, #fbc2eb);
            color: #fff;
        }
        .msg {
            text-align: center;
            line-height: 88px;
        }
        a {
            text-decoration-line: none;
            color: #abc1ee;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="login-wrapper">
            <form action="/register/" method="post">
                <div class="header">Register</div>
                <div class="form-wrapper">
                <input type="text" name="username" placeholder="username" class="input-item">
                <input type="password" name="password" placeholder="password" class="input-item">
                <!-- <a href="{{url_for('my_login')}}"><div class="btn">Submit</div></a>  -->
                {% if error %}
                <font color="red">{{ error }}</font>
                {% endif %}
                <input class="btn" type="submit" value="Submit">
                
            </div>
            </form>
            
        </div>
    </div>
</body>
</html>


2.3训练模型模块

2.3.1导入数据

manager.py

@app.route('/load_data')
def load_data():  
    return render_template('load_data.html')

load_data.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>导入数据</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="" >
                  <button type="button" class="btn btn-outline-primary" disabled>1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('see_data')}}">
                  <button type="button" class="btn btn-outline-primary">2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10"  style="margin-top: 10px;">
        <div class="card">
          <div class="card-body">
            <div class="card-body">
              <img src="../static/img/load_data.png" width="1160px">
              <br>
              <br>
              <p>导入数据成功!!!</p>
            </div>
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.2查看数据

manager.py

@app.route('/see_data')
def see_data():  
    return render_template('see_data.html')

see_data.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查看数据</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="" >
                  <button type="button" class="btn btn-outline-primary" disabled>1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('dispose_data')}}">
                  <button type="button" class="btn btn-outline-primary">3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10"  style="margin-top: 10px;">
        <div class="card">
          <div class="card-body">
            <p>数据大小为:(1500,13)</p>
            <p>数据基本信息为:</p>
            <img src="../static/img/see_data1.png">
            <br>
            <br>
            <p>数值型数据描述为:</p>
            <img src="../static/img/see_data2.png">
            <br>
            <br>
            <p>非数值型数据描述为:</p>
            <br>
            <img src="../static/img/see_data3.png">
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.3数据预处理

manager.py

@app.route('/dispose_data')
def dispose_data():  
    return render_template('dispose_data.html')

dispose_data.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据预处理</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="" >
                  <button type="button" class="btn btn-outline-primary" disabled>1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('display_data')}}">
                  <button type="button" class="btn btn-outline-primary" >4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10">
        <div class="card" style="margin-top: 20px;">
          <div class="card-body">
            <p>查看数据缺失值情况:</p>
            <img src="../static/img/dispose_data.png">
            <br>
            <br>
            <p>检测数据是否存在重复值:True</p>
            <p>删除重复值前的数据的大小:(1500,13)</p>
            <p>删除重复值后的数据的大小:(1445,13)</p>
            <p>数据预处理完毕!!!</p>
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.4数据可视化

manager.py

@app.route('/display_data')
def display_data():  
    return render_template('display_data.html')

display_data.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据可视化</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="" >
                  <button type="button" class="btn btn-outline-primary" disabled>1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('feature_engineering')}}">
                  <button type="button" class="btn btn-outline-primary">5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10" style="margin-top: 10px;">
        <div class="card" >
          <div class="card-body">
            <img src="../static/img/display_data4.png">
            <img src="../static/img/display_data3.png">
            <img src="../static/img/display_data2.png"  width="1160px">
            <img src="../static/img/display_data1.png"  width="1160px">
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.5特征工程

manager.py

@app.route('/feature_engineering')
def feature_engineering():  
    return render_template('feature_engineering.html')

feature_engineering.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>特征工程</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="" >
                  <button type="button" class="btn btn-outline-primary" disabled>1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('build_model')}}">
                  <button type="button" class="btn btn-outline-primary" >6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10">
        <div class="card" style="margin-top: 20px;">
          <div class="card-body">
            <img src="../static/img/feature_engineering.png" >
              <br>
              <br>
              <p>特征工程完毕!!!</p>
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.6构建模型

manager.py

@app.route('/build_model')
def build_model():  
    return render_template('build_model.html')

build_model.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>构建模型</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('load_data')}}" >
                  <button type="button" class="btn btn-outline-primary">1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('save_model')}}">
                <button type="button" class="btn btn-outline-primary">7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('index')}}">
                <button type="button" class="btn btn-outline-primary" disabled>返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10">
        <div class="card" style="margin-top: 20px;">
          <div class="card-body">
            <p>Model is:  RandomForestRegressor()</p>
            <p>Training score:  0.9049714978258847</p>
            <p>r2 score is:  0.5589430756516771</p>
            <p>MAE: 451.4159751799188</p>
            <p>MSE: 450572.2871418395</p>
            <p>RMSE: 671.2468153681174</p>
               
            <br>
            <p>真实值和预测值的差值图如下:</p>
            <img src="../static/img/build_model1.png" alt="">
            <img src="../static/img/build_model2.png" alt="">
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.3.7保存模型

manager.py

@app.route('/save_model')
def save_model():
    return render_template('save_model.html')

save_model.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>构建模型</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">

</head>
<body>
  <div class="container-fluid">
    <div class="row">
      <div class="col-xl-2">
        <div class="top" style="margin-top: 40px;margin-left: 40px;">
          <ul class="nav flex-column">
              <li class="nav-item" >
                <a class="nav-link" href="{{url_for('load_data')}}" >
                  <button type="button" class="btn btn-outline-primary">1.导入数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>2.查看数据</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>3.数据预处理</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>4.数据可视化</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>5.特征工程</button>  
                </a>
              </li>
              <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
                <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
              </svg>
              <li class="nav-item" >
                <a class="nav-link" href="">
                  <button type="button" class="btn btn-outline-primary" disabled>6.构建模型</button>  
                </a>
              </li>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="">
                <button type="button" class="btn btn-outline-primary" disabled>7.保存模型</button>  
              </a>
            </li>
            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16" style="margin-left: 60px;">
              <path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
            </svg>
            <li class="nav-item" >
              <a class="nav-link" href="{{url_for('main')}}">
                <button type="button" class="btn btn-outline-primary">返回首页</button>  
              </a>
            </li>
              
            </ul>
      </div>
      </div>
      <div class="col-xl-10">
        <div class="card" style="margin-top: 20px;">
          <div class="card-body">
            <p>模型保存成功!!!</p>
            <br>
          </div>
        </div>
      </div>
    </div>
   
  </div>
    
</body>
</html>

2.4预测房价模块

manager.py

class PredictView(views.MethodView):    
    def __jump(self,result=None,error=None):      
        return render_template('predict_price.html',result=result,error=error)    
    def get(self, result=None,error=None):        
        return self.__jump()    
    def post(self):
        try:        
            address = request.form['address']      
            derection = request.form['derection']        
            floor = request.form['floor']        
            elevator = request.form['elevator']        
            area = float(request.form['area'])      
            new_data = pd.DataFrame(data=[[address,derection,area,floor,elevator]],columns=['address','derection','area','floor','elevator'])
        
            new_data['address'].replace(to_replace={'南昌县':0,'红谷滩':1,'新建区':2,'高新区':3,'东湖区':4,'西湖区':5,'经开区':6,'青山湖区':7,'青云谱区':8,'湾里区':9,'进贤县':10},inplace=True)
            new_data['derection'].replace(to_replace={'精装修':1,'简装修':0},inplace=True)
            new_data['floor'].replace(to_replace={'高':0,'中':1,'低':2},inplace=True)
            new_data['elevator'].replace(to_replace={'有':1,'无':0},inplace=True)

            predict = model.predict(new_data)[0]
            return self.__jump(result=predict) 
        except:
            return self.__jump(error='输入数据格式不对,请重新输入!')   
app.add_url_rule('/predict_price/',view_func=PredictView.as_view('my_predict'))

predict_price.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预测租房价格</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">
</head>
<body>
    <div class="container">
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <a class="navbar-brand" href="{{url_for('main')}}">首页</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
              <div class="navbar-nav">
                <a class="nav-link" href="{{url_for('train_model')}}">训练模型<span class="sr-only">(current)</span></a>
                <a class="nav-link active" href="{{url_for('predict_price')}}">预测租房价格</a>
                <a class="nav-link" href="{{url_for('my_look')}}">查看租房价格信息</a>
              </div>
            </div>
          </nav>

          <div class="container-fluid">
            <div class="row">
              <div class="col col-lg-2">
               
              </div>
              <div class="col-md-auto">
                  <form action="/predict_price/" method="post">
                    <div class="form-group row">
                        <label for="inputPassword" class="col-sm-4 col-form-label">请选择地区:</label>
                        <div class="col-sm-8">
                          <input type="text" placeholder="南昌县/红谷滩/新建区/..." name="address" class="form-control">
                        </div>
                      </div>
                    
                    <div class="form-group row">
                        <label for="inputPassword" class="col-sm-4 col-form-label">装修类型:</label>
                        <div class="col-sm-8">
                          <input type="text" placeholder="简装修/精装修" name="derection" class="form-control">
                        </div>
                      </div>

                      <div class="form-group row">
                        <label for="inputPassword" class="col-sm-4 col-form-label">楼层情况:</label>
                        <div class="col-sm-8">
                          <input type="text" placeholder="高/中/低" name="floor" class="form-control">
                        </div>
                      </div>

                      <div class="form-group row">
                        <label for="inputPassword" class="col-sm-4 col-form-label">电梯情况:</label>
                        <div class="col-sm-8">
                          <input type="text" placeholder="有/无" name="elevator" class="form-control">
                        </div>
                      </div>

                      <div class="form-group row">
                        <label for="inputPassword" class="col-sm-4 col-form-label">房屋面积:</label>
                        <div class="col-sm-8">
                          <input type="text" placeholder="㎡" name="area" class="form-control" id="inputPassword">
                        </div>

                    <button style="margin-left: 10px;" type="submit" class="btn btn-primary">预测</button>
                  </form>
              </div>
              {% if error %}
              <font color="red">{{ error }}</font>
              {% endif %}
              {% if result %}
              <font color="red">预测的房价为:{{ result }}</font>
              {% endif %}
              <div class="col col-lg-2">
                
              </div>
            </div>
          </div>
    </div>
</body>
</html>

2.4查看房价信息模块

manager.py

class LookPriceView(views.MethodView):    
    def __jump(self,houses=None,error=None):      
        return render_template('look_house_price.html',houses=houses,error=error)    
    def get(self, houses=None,error=None): 
        data = pd.read_csv('lianjia.csv')
        houses = []
        for item in data.values:
            house = {}
            house['address'] = item[1]
            house['price'] = item[2]
            house['lease method'] = item[3]
            house['layout'] = item[4]
            house['derection'] = item[5]
            house['area'] = item[6]
            house['orientation'] = item[7]
            house['floor'] = item[8]
            house['elevator'] = item[9]
            house['water'] = item[10]
            house['power'] = item[11]
            house['gas'] = item[12]
            houses.append(house)
        return self.__jump(houses=houses)    
    def post(self):
        try:        
            min_price = float(request.form['min'])   
            max_price = float(request.form['max'])
               
            data = pd.read_csv('lianjia.csv')
            data = data[(data['price']>min_price) & (data['price']<max_price)]  
            houses = []
            for item in data.values:
                house = {}
                house['address'] = item[1]
                house['price'] = item[2]
                house['lease method'] = item[3]
                house['layout'] = item[4]
                house['derection'] = item[5]
                house['area'] = item[6]
                house['orientation'] = item[7]
                house['floor'] = item[8]
                house['elevator'] = item[9]
                house['water'] = item[10]
                house['power'] = item[11]
                house['gas'] = item[12]
                houses.append(house)

            return self.__jump(houses=houses) 
        except:
            return self.__jump(error='输入数据格式不对,请重新输入!')
app.add_url_rule('/look_price/',view_func=LookPriceView.as_view('my_look'))

 look_house_price.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查看租房价格信息</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <link rel="stylesheet" href="../static/main.css">
</head>
<body>
    <div class="container">
        <nav class="navbar navbar-expand-lg navbar-light bg-light">
            <a class="navbar-brand" href="{{url_for('main')}}">首页</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
              <div class="navbar-nav">
                <a class="nav-link" href="{{url_for('train_model')}}">训练模型<span class="sr-only">(current)</span></a>
                <a class="nav-link" href="{{url_for('predict_price')}}">预测租房价格</a>
                <a class="nav-link active" href="{{url_for('my_look')}}">查看租房价格信息</a>
              </div>
            </div>
          </nav>
          <div>
            <form action="/look_price/" method="post">
              <div class="form-group row">
                  <label for="inputPassword" class="col-sm-2 col-form-label">请输入价格区间:</label>
                  <div class="col-sm-3">
                    <input type="text" placeholder="1000" name="min" class="form-control">
                  </div>
                  <div class="col-sm-1">
                    ——
                  </div>
                  <div class="col-sm-3">
                    <input type="text" placeholder="2000" name="max" class="form-control">
                  </div>
                  <div class="col-sm-3">
                    <input type="submit" value="搜索" class="btn btn-primary">
                  </div>
                </div>
            </form>
            <section class="counts section-bg">
              <div class="container">
                <table class="table text-nowrap">
                  <tr class="text-center">
                    <td>address</td>
                    <td>lease method</td>
                    <td>layout</td>
                    <td>derection</td>
                    <td>area</td>
                    <td>orientation</td>
                    <td>floor</td>
                    <td>elevator</td>
                    <td>water</td>
                    <td>power</td>
                    <td>gas</td>
                    <td>price</td>
                  </tr>
                  {% for house in houses %}
                  <tr class="text-center">
                    <td>{{ house.address }}</td>
                    <td>{{ house['lease method'] }}</td>
                    <td>{{ house.layout }}</td>
                    <td>{{ house.derection }}</td>
                    <td>{{ house.area }}</td>
                    <td>{{ house.orientation }}</td>
                    <td>{{ house.floor }}</td>
                    <td>{{ house.elevator }}</td>
                    <td>{{ house.water }}</td>
                    <td>{{ house.power }}</td>
                    <td>{{ house.gas }}</td>
                    <td>{{ house.price }}</td>
                  </tr>
                  {% endfor %}
                </table>
              </div>
            </section><!-- End Counts Section -->
          </div>
    </div>
</body>
</html>

三、项目总结

        本次我们使用了Flask框架结合了基于机器学习的房价预测模型,构建了一个简易版基于机器学习的南昌市租房价格预测系统,整个项目还有很多地方可以优化,比如页面美化、模块添加等等,这些就留给学习的小伙伴根据自身需求进行创新升级!喜欢本项目的话就三连支持一下啦!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/482393.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

图片分类:精细化分类,(Fine-Grained Categorization) 基于人的行为的精细化分类

文字大纲 简介数据集常用数据集方法1 : 强监督方法2 : 弱监督Two Level Attention Model双线性网络 Bilinear CNN model参考文献和学习路径简介 细粒度图像识别 (fine-grained image recognition),即 精细化分类。 细粒度图像分类(Fine-Grained Categorization), 又被称作…

2023年05月IDE流行度最新排名

点击查看最新IDE流行度最新排名&#xff08;每月更新&#xff09; 2023年05月IDE流行度最新排名 顶级IDE排名是通过分析在谷歌上搜索IDE下载页面的频率而创建的 一个IDE被搜索的次数越多&#xff0c;这个IDE就被认为越受欢迎。原始数据来自谷歌Trends 如果您相信集体智慧&am…

感知机介绍

1&#xff0c;数学定义&#xff1a; Note:<>在数学中通常指求期望的意思。 假设我们用感知机区分cat和dog&#xff0c;使用下面三个特征&#xff1a;x1: color of hair&#xff1b;x2:length of leg&#xff1b;x3:volume of head。cat 用1表示&#xff0c;dog用-1表示&…

Golang每日一练(leetDay0053)

目录 155. 最小栈 Min Stack &#x1f31f;&#x1f31f; 156. 二叉树的上下翻转 Binary Tree Upside Down &#x1f31f;&#x1f31f; &#x1f31f; 每日一练刷题专栏 &#x1f31f; Golang每日一练 专栏 Python每日一练 专栏 C/C每日一练 专栏 Java每日一练 专栏 …

ArrayList集合扩容机制入门

首先&#xff0c;ArrayList集合存储的数据在底层是一个数组&#xff08;名字elementData&#xff09;&#xff0c;这个数组是Object的数组&#xff0c;因为是Object数组&#xff0c;所以集合啥都可以装。 讲解ArrayList的扩容机制&#xff0c;要从ArrayList的构造器来分类&…

Spark RDD 持久化(CheckPoint 检查点)

RDD Cache 缓存 RDD 通过 Cache 或者 Persist 方法将前面的计算结果缓存&#xff0c;默认情况下会把数据以缓存 在 JVM 的堆内存中。但是并不是这两个方法被调用时立即缓存&#xff0c;而是触发后面的 action 算 子时&#xff0c;该 RDD 将会被缓存在计算节点的内存中 // cach…

debian11快速 ceph集群17.2.6(Quincy版)

由于网友跟我讲Pacific版快到期了&#xff0c;所以出一个Quincy版的部署文档 配置一下源 echo "deb http://mirrors.163.com/ceph/debian-quincy/ bullseye main" > /etc/apt/sources.list.d/ceph.list还是像以前一样使用docker或者podman 安装工具cephadm ce…

java获取文件名后缀方法

Java是一种应用广泛的编程语言&#xff0c;可以通过多种方式来实现对文件的操作。如文件名后缀、文件扩展名等。今天我们来看下 Java是如何获取文件名后缀的吧&#xff01; 1.打开一个空文件&#xff0c;将其复制到一个新的文件夹中。 2.新建一个类&#xff0c;在里面定义方法&…

mysql 数据库备份

目录 数据库备份的方式 一、备份整个 $datadir 二、用mysqldump备份 备份某个库 只备份某个库下某个表 有很多库时候&#xff0c;一次性备份所有的库 一次指定备份某几个库 只备份表结构&#xff0c;不要里面数据 数据库还原的方式 1、在对应数据库下source还原 2…

学系统集成项目管理工程师(中项)系列16a_风险管理(上)

1. 风险的定义 1.1. 损失的不确定性 1.1.1. 狭义 1.2. 带来损失的可能性&#xff0c;也指可能获利的机会 1.2.1. 广义 1.3. 风险是一种不确定的事件或条件&#xff0c;一旦发生&#xff0c;就会产生积极或消极的影响 2. 性质划分 2.1. 纯粹风险 2.1.1. 只有损失可能性而…

IntelliJ IDEA修改背景颜色大全(护眼绿等)设置注释颜色

一.IDEA默认有3种背景颜色 路径为File->settings->Editor->Color Scheme可以设置软件默认颜色&#xff0c;旁边的小齿轮添加颜色名字 二.IDEA扩展颜色&#xff08;护眼绿&#xff09; 第一种方法&#xff1a; IDEA设置一张背景图片,路径&#xff1a;File->Setti…

C#,生信软件实践(02)——欧洲分子生物学实验室(EMBL格式文件)转为核酸序列或多肽序列(FASTA格式文件)的源代码

>生信老白写的基础代码.fasta MAYBENOANYUSAGE 1 EMBL 1.1 EMBL组织 欧洲分子生物学实验室EMBL&#xff08;European Molecular Biology Laboratory&#xff09;1974年由欧洲14个国家加上亚洲的以色列共同发起建立&#xff0c;现在由欧洲30个成员国政府支持组成&#xf…

【ARMv8 编程】A64 内存访问指令——内存存储指令

在内存加载一节中实际上已经使用了内存存储指令了&#xff0c;内存存储指令将寄存器的值存储到内存中。 同样&#xff0c;Store 指令的一般形式如下&#xff1a; STR Rn, <addr> 还有 unscaled-offset 偏移形式&#xff0c;例如 STUR<type>。 程序员通常不需要明…

Python多元线性回归预测模型实验完整版

多元线性回归预测模型 实验目的 通过多元线性回归预测模型&#xff0c;掌握预测模型的建立和应用方法&#xff0c;了解线性回归模型的基本原理 实验内容 多元线性回归预测模型 实验步骤和过程 (1)第一步&#xff1a;学习多元线性回归预测模型相关知识。 一元线性回归模型…

高级数据结构专题

1.树状数组 设计二分&#xff0c;二叉树&#xff0c;位运算&#xff0c;前缀和等思想 lowbit x & -x 功能&#xff1a;找到x的二进制数的最后一个1 1.1 树状数组模板 def lowbit(x):return x &-x def add (x,d):while(x < n) :tree[x] dxlowbit(x) def sum(x):an…

零基础学会 Java,这是你需要按照学习的步骤,加油,新加入的你

学习 Java 需要遵循一定的步骤&#xff0c;首先需要学习计算机基础知识&#xff0c;例如算法、数据结构、计算机组成原理等。如果没有相关背景知识&#xff0c;可以参加计算机相关课程进行学习。其次是学习编程基础知识&#xff0c;例如控制流、变量、函数等&#xff0c;你可以…

详解c++---list模拟实现

目录标题 list的准备工作构造函数push_backlist迭代器beginendinserteraseclearconst迭代器list迭代器区间构造swap现代拷贝构造函数现代赋值重载sizeempty->重载 list的准备工作 首先我们知道list是一个带头双向链表&#xff0c;他的数据就会存储在一个一个的节点里面&…

Python基础合集 练习22 (错误与异常处理语句2)

‘’’ try: 语句块 except: 语句块2 else ‘’’ class Mobe1(): def init(self) -> None: pass def mob1(self):while True:try:num int(input(请输入一个数: ))result 50 / numprint(result)print(50/{0}{1}.format(num, result))except (ZeroDivisionError, ValueEr…

时代浪潮已经袭来 AI人工智能频频爆火 ChatGPT改变行业未来

目录 1 人工智能的发展 1.1人工智能发展历程 1.1.1 人工智能的起源 1.1.2 人工智能发展的起起伏伏 1.1.3 人工智能多元化 2 什么是ChatGPT 2.1 ChatGPT的主要功能 2.2ChatGPT对企业的多种优势 2.3 不必担心ChatGPT带来的焦虑 3 人工智能对行业未来的影响 3.1 人工智…

UG NX二次开发(C++)-建模-根据UFun创建的Tag_t转换为Body

文章目录 1、前言2、用UF_MODL_create_block1创建一个块3、将Tag_t转换为Body出现错误3、解决方法4、结论 1、前言 经常采用UG NX二次开发&#xff08;NXOpen C#&#xff09;&#xff08;UG NX二次开发&#xff08;C#&#xff09;专栏&#xff09;&#xff0c;在用UFun创建一个…