???♂? 個人主頁:@艾派森的個人主頁
???作者簡介:Python學習者
?? 希望大家多多支持,我們一起進步!??
如果文章對你有幫助的話,
歡迎評論 ??點贊???? 收藏 ??加關注+
目錄
一、項目介紹
1.1項目簡介
1.2技術工具
1.3頁面概述?
二、項目步驟
2.1登錄模塊
2.2注冊模塊
2.3訓練模型模塊
2.3.1導入數(shù)據(jù)
2.3.2查看數(shù)據(jù)
2.3.3數(shù)據(jù)預處理
2.3.4數(shù)據(jù)可視化
2.3.5特征工程
2.3.6構建模型
2.3.7保存模型
2.4預測房價模塊
2.4查看房價信息模塊
三、項目總結
?文章來源地址http://www.zghlxwxcb.cn/news/detail-431601.html
一、項目介紹
1.1項目簡介
? ? ? ? ?本項目使用Flask框架搭建基于機器學習的南昌市租房價格預測系統(tǒng) (簡易版)
其中關于Flask知識點可參考文章Flask全套知識點從入門到精通,學完可直接做項目
其中關于南昌市租房價格預測可參考文章基于XGBoost算法構造房屋租賃價格評估模型
整個項目分為以下幾個模塊:
- 1.登錄和注冊模塊
- 2.訓練模型模塊
- 3.預測價格模塊
- 4.查看房價信息模塊?
項目文件框架如下:
其中manager.py為主程序,password.csv為存儲用戶賬號密碼的文件,lianjia是房租價格原始數(shù)據(jù)集,model.pkl是經(jīng)過機器學習算法訓練出的模型。?
1.2技術工具
IDE編輯器:vscode
后端框架:Flask
前端框架:Bootstrap
1.3頁面概述?
運行manager.py程序后,瀏覽器打開http://127.0.0.1:5000/
映入眼簾的登錄頁面,有賬號的話就之間輸入用戶名和密碼,沒有就點擊Sign up先注冊再登錄?
?注冊頁面如下:?
?登錄后進入主頁面如下:?
?在導航欄中有訓練模型、預測價格、查看房價信息、退出模塊
?訓練模型模塊如下:
需要依次按照步驟進行構建模型
?預測房價模塊:
在預測模塊只需要輸入地區(qū)、裝修情況、樓層情況、電梯情況、房屋面積即可,每個輸入類型都有提示(必須按照提示信息填寫)?
?示例如下,填完信息后點擊預測即可得到預測的房價信息:
?查看房價信息模塊:
?在查看房價信息模塊默認展示的是全部數(shù)據(jù),當然你也可以通過輸入價格區(qū)間進行篩選。
二、項目步驟
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):
# 模擬實現(xiàn)
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導入數(shù)據(jù)
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>導入數(shù)據(jù)</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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>導入數(shù)據(jù)成功!!!</p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
2.3.2查看數(shù)據(jù)
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>查看數(shù)據(jù)</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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>數(shù)據(jù)大小為:(1500,13)</p>
<p>數(shù)據(jù)基本信息為:</p>
<img src="../static/img/see_data1.png">
<br>
<br>
<p>數(shù)值型數(shù)據(jù)描述為:</p>
<img src="../static/img/see_data2.png">
<br>
<br>
<p>非數(shù)值型數(shù)據(jù)描述為:</p>
<br>
<img src="../static/img/see_data3.png">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
2.3.3數(shù)據(jù)預處理
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>數(shù)據(jù)預處理</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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>查看數(shù)據(jù)缺失值情況:</p>
<img src="../static/img/dispose_data.png">
<br>
<br>
<p>檢測數(shù)據(jù)是否存在重復值:True</p>
<p>刪除重復值前的數(shù)據(jù)的大小:(1500,13)</p>
<p>刪除重復值后的數(shù)據(jù)的大?。海?445,13)</p>
<p>數(shù)據(jù)預處理完畢?。?!</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
2.3.4數(shù)據(jù)可視化
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>數(shù)據(jù)可視化</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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.導入數(shù)據(jù)</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.查看數(shù)據(jù)</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.數(shù)據(jù)預處理</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.數(shù)據(jù)可視化</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,'新建區(qū)':2,'高新區(qū)':3,'東湖區(qū)':4,'西湖區(qū)':5,'經(jīng)開區(qū)':6,'青山湖區(qū)':7,'青云譜區(qū)':8,'灣里區(qū)':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='輸入數(shù)據(jù)格式不對,請重新輸入!')
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">請選擇地區(qū):</label>
<div class="col-sm-8">
<input type="text" placeholder="南昌縣/紅谷灘/新建區(qū)/..." 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='輸入數(shù)據(jù)格式不對,請重新輸入!')
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">請輸入價格區(qū)間:</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框架結合了基于機器學習的房價預測模型,構建了一個簡易版基于機器學習的南昌市租房價格預測系統(tǒng),整個項目還有很多地方可以優(yōu)化,比如頁面美化、模塊添加等等,這些就留給學習的小伙伴根據(jù)自身需求進行創(chuàng)新升級!喜歡本項目的話就三連支持一下啦!文章來源:http://www.zghlxwxcb.cn/news/detail-431601.html
?
到了這里,關于基于Flask+Bootstrap+機器學習的南昌市租房價格預測系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!