├── __init__.py ├── icon.ico ├── model ├── DR_model.m ├── LR_model.m ├── RR_model.m ├── KNNR_model.m ├── LLR_model.m └── SVMR_model.m ├── README.md ├── my_pic.qrc ├── my_main_ui.spec ├── my_boston.e4p ├── model.py ├── my_main_ui.py ├── my_main_ui.ui └── Ui_my_main_ui.py /__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/icon.ico -------------------------------------------------------------------------------- /model/DR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/DR_model.m -------------------------------------------------------------------------------- /model/LR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/LR_model.m -------------------------------------------------------------------------------- /model/RR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/RR_model.m -------------------------------------------------------------------------------- /model/KNNR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/KNNR_model.m -------------------------------------------------------------------------------- /model/LLR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/LLR_model.m -------------------------------------------------------------------------------- /model/SVMR_model.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DataXujing/boston_model/master/model/SVMR_model.m -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 波士顿房价预测模型+GUI 2 | 3 | 徐静 4 | 5 | + 基于波士顿房价数据,训练了几个机器学习模型 6 | 7 | + 训练好的模型结合Pyqt,做成app 8 | 9 | + App的下载地址:链接: https://pan.baidu.com/s/1VOjnKXO_pSThG3z5cE1_dw 密码: jufa -------------------------------------------------------------------------------- /my_pic.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | pic/aboutme.png 4 | pic/aboutqt.png 5 | pic/close.png 6 | pic/connect.png 7 | pic/datadb.png 8 | pic/face.png 9 | pic/fwgh.png 10 | pic/gh.png 11 | pic/haha.png 12 | pic/jdsj.png 13 | pic/kh.png 14 | pic/lajiao.png 15 | pic/logo.png 16 | pic/me1.png 17 | pic/note.png 18 | pic/open.png 19 | pic/sc.png 20 | pic/table.png 21 | pic/xiaoche.png 22 | pic/xj.png 23 | 24 | 25 | -------------------------------------------------------------------------------- /my_main_ui.spec: -------------------------------------------------------------------------------- 1 | # -*- mode: python -*- 2 | 3 | block_cipher = None 4 | 5 | import sys 6 | sys.setrecursionlimit(500000) # or more 7 | 8 | 9 | def get_pandas_path(): 10 | import pandas 11 | pandas_path = pandas.__path__[0] 12 | return pandas_path 13 | 14 | 15 | 16 | a = Analysis(['my_main_ui.py'], 17 | pathex=['C:\\Users\\Administrator.USER-20170417DX\\Desktop\\ML+Pyqt\\code\\my_app'], 18 | binaries=[('D:/Anaconda3/Lib/site-packages/pyzbar/libiconv-2.dll','.'),('D:/Anaconda3/Lib/site-packages/pyzbar/libzbar-32.dll','.')], 19 | datas=[], 20 | hiddenimports=['sklearn','sklearn.neighbors.typedefs','scipy._lib.messagestream','sklearn.neighbors.quad_tree','sklearn.tree._utils'], 21 | hookspath=[], 22 | runtime_hooks=[], 23 | excludes=[], 24 | win_no_prefer_redirects=False, 25 | win_private_assemblies=False, 26 | cipher=block_cipher) 27 | pyz = PYZ(a.pure, a.zipped_data, 28 | cipher=block_cipher) 29 | 30 | dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"]) 31 | a.datas += dict_tree 32 | a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries) 33 | 34 | exe = EXE(pyz, 35 | a.scripts, 36 | exclude_binaries=True, 37 | name='my_main_ui', 38 | debug=False, 39 | strip=False, 40 | upx=True, 41 | console=False, 42 | icon='C:\\Users\\Administrator.USER-20170417DX\\Desktop\\ML+Pyqt\\code\\my_app\\icon.ico') 43 | coll = COLLECT(exe, 44 | a.binaries, 45 | a.zipfiles, 46 | a.datas, 47 | strip=False, 48 | upx=True, 49 | name='my_main_ui') 50 | -------------------------------------------------------------------------------- /my_boston.e4p: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | en_US 8 | b23f0bf0c5fcdd8c0c692cad3994734a773d24ec 9 | Python3 10 | PyQt5 11 | An app predict the price of Boston house. 12 | 0.1 13 | XuJing 14 | 274762204@qq.com 15 | 16 | 17 | Ui_my_main_ui.py 18 | __init__.py 19 | my_main_ui.py 20 | my_pic_rc.py 21 | 22 | 23 |
my_main_ui.ui
24 |
25 | 26 | my_pic.qrc 27 | 28 | 29 | None 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | 3 | # step0:加载必要的模型 4 | import numpy as np 5 | import pandas as pd 6 | import matplotlib.pyplot as plt 7 | 8 | import sklearn.datasets as datasets 9 | from sklearn.linear_model import LinearRegression 10 | from sklearn.linear_model import Ridge 11 | from sklearn.linear_model import Lasso 12 | from sklearn.neighbors import KNeighborsRegressor 13 | from sklearn.tree import DecisionTreeRegressor 14 | from sklearn.svm import SVR 15 | from sklearn.model_selection import train_test_split 16 | from sklearn.externals import joblib 17 | 18 | # step1:数据获取 19 | 20 | boston = datasets.load_boston() 21 | train = boston.data 22 | target = boston.target 23 | 24 | X_train,x_test,y_train,y_true = train_test_split(train,target,test_size=0.2) 25 | print(X_train,x_test) 26 | print(y_train,y_true) 27 | 28 | # step2: 初始化model 29 | LR = LinearRegression() 30 | RR= Ridge() 31 | LLR = Lasso() 32 | KNNR = KNeighborsRegressor() 33 | DR = DecisionTreeRegressor() 34 | SVMR = SVR() 35 | 36 | # step3: Train and save and predict Model 37 | # 这里省略了模型训练中评价和调参的过程 38 | # 假设这就是美国房产中介Leader要我训练的 39 | # 最终Model 40 | 41 | LR.fit(X_train,y_train) 42 | RR.fit(X_train,y_train) 43 | LLR.fit(X_train,y_train) 44 | KNNR.fit(X_train,y_train) 45 | DR.fit(X_train,y_train) 46 | SVMR.fit(X_train,y_train) 47 | 48 | 49 | # 模型保存与持久化 50 | 51 | joblib.dump(LR, "LR_model.m") 52 | joblib.dump(RR, "RR_model.m") 53 | joblib.dump(LLR, "LLR_model.m") 54 | joblib.dump(KNNR, "KNNR_model.m") 55 | joblib.dump(DR, "DR_model.m") 56 | joblib.dump(SVMR, "SVMR_model.m") 57 | 58 | # 模型加载 59 | lr_m = joblib.load("LR_model.m") 60 | rr_m = joblib.load("RR_model.m") 61 | llr_m = joblib.load("LLR_model.m") 62 | knnr_m = joblib.load("KNNR_model.m") 63 | dr_m = joblib.load("DR_model.m") 64 | svmr_m = joblib.load("SVMR_model.m") 65 | 66 | y_LR = lr_m.predict(x_test) 67 | y_RR = rr_m.predict(x_test) 68 | y_LLR = llr_m.predict(x_test) 69 | y_KNNR = knnr_m.predict(x_test) 70 | y_DR = dr_m.predict(x_test) 71 | y_SVMR = svmr_m.predict(x_test) 72 | 73 | 74 | model_pre = pd.DataFrame({'LinearRegression()':list(y_LR),'Ridge()':list(y_RR),'Lasso()':list(y_LLR), 75 | 'KNeighborsRegressor()':list(y_KNNR),'DecisionTreeRegressor()':list(y_DR), 76 | 'SVR()':list(y_SVMR)}) 77 | 78 | # Plot 79 | 80 | def model_plot(y_true,model_pre): 81 | ''' 82 | y_true:真实的label 83 | model_pre: 预测的数据(数据框) 84 | ''' 85 | cols = model_pre.columns 86 | plt.style.use("ggplot") 87 | plt.figure(figsize=(24,24)) 88 | plt.rcParams['font.sans-serif'] = ['FangSong'] 89 | plt.rcParams['axes.unicode_minus'] = False 90 | for i in range(6): 91 | plt.subplot(2,3,i+1) 92 | plt.scatter(x=range(len(y_true)),y=y_true,label='true') 93 | plt.scatter(x=range(len(model_pre[cols[i]])),y=model_pre[cols[i]],label=cols[i]) 94 | plt.title(str(cols[i])+':真实Label Vs 预测Label') 95 | plt.legend() 96 | 97 | plt.savefig("plot/model_plot.png") 98 | 99 | model_plot(y_true, model_pre) -------------------------------------------------------------------------------- /my_main_ui.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """ 4 | Module implementing MainWindow. 5 | """ 6 | 7 | from PyQt5.QtCore import pyqtSlot 8 | from PyQt5.QtWidgets import QMainWindow 9 | 10 | from Ui_my_main_ui import Ui_MainWindow 11 | 12 | from PyQt5.QtCore import * 13 | from PyQt5.QtWidgets import * 14 | from PyQt5 import * 15 | import pandas as pd 16 | import numpy as np 17 | 18 | import matplotlib.pyplot as plt 19 | 20 | import sklearn.datasets as datasets 21 | from sklearn.linear_model import LinearRegression 22 | from sklearn.linear_model import Ridge 23 | from sklearn.linear_model import Lasso 24 | from sklearn.neighbors import KNeighborsRegressor 25 | from sklearn.tree import DecisionTreeRegressor 26 | from sklearn.svm import SVR 27 | from sklearn.model_selection import train_test_split 28 | from sklearn.externals import joblib 29 | 30 | 31 | 32 | class MainWindow(QMainWindow, Ui_MainWindow): 33 | """ 34 | Class documentation goes here. 35 | """ 36 | def __init__(self, parent=None): 37 | """ 38 | Constructor 39 | 40 | @param parent reference to the parent widget 41 | @type QWidget 42 | """ 43 | super(MainWindow, self).__init__(parent) 44 | self.setupUi(self) 45 | 46 | def model_plot(self, y_true,model_pre): 47 | ''' 48 | y_true:真实的label 49 | model_pre: 预测的数据(数据框) 50 | ''' 51 | cols = model_pre.columns 52 | plt.style.use("ggplot") 53 | plt.figure(figsize=(24,24)) 54 | plt.rcParams['font.sans-serif'] = ['FangSong'] 55 | plt.rcParams['axes.unicode_minus'] = False 56 | for i in range(6): 57 | plt.subplot(2,3,i+1) 58 | plt.scatter(x=range(len(y_true)),y=y_true,label='true') 59 | plt.scatter(x=range(len(model_pre[cols[i]])),y=model_pre[cols[i]],label=cols[i]) 60 | plt.title(str(cols[i])+':真实Label Vs 预测Label') 61 | plt.legend() 62 | 63 | plt.savefig("model_plot.png") 64 | 65 | @pyqtSlot() 66 | def on_pushButton_clicked(self): 67 | """ 68 | Slot documentation goes here. 69 | """ 70 | # TODO: not implemented yet 71 | print("加载数据") 72 | 73 | boston = datasets.load_boston() 74 | train = boston.data 75 | target = boston.target 76 | 77 | self.X_train,self.x_test,self.y_train,self.y_true = train_test_split(train,target,test_size=0.2) 78 | 79 | @pyqtSlot() 80 | def on_pushButton_2_clicked(self): 81 | """ 82 | Slot documentation goes here. 83 | """ 84 | # TODO: not implemented yet 85 | print("模型预测") 86 | 87 | # 模型加载 88 | lr_m = joblib.load("model/LR_model.m") 89 | rr_m = joblib.load("model/RR_model.m") 90 | llr_m = joblib.load("model/LLR_model.m") 91 | knnr_m = joblib.load("model/KNNR_model.m") 92 | dr_m = joblib.load("model/DR_model.m") 93 | svmr_m = joblib.load("model/SVMR_model.m") 94 | 95 | try: 96 | y_LR = lr_m.predict(self.x_test) 97 | y_RR = rr_m.predict(self.x_test) 98 | y_LLR = llr_m.predict(self.x_test) 99 | y_KNNR = knnr_m.predict(self.x_test) 100 | y_DR = dr_m.predict(self.x_test) 101 | y_SVMR = svmr_m.predict(self.x_test) 102 | 103 | 104 | model_pre = pd.DataFrame({'LinearRegression()':list(y_LR),'Ridge()':list(y_RR),'Lasso()':list(y_LLR), \ 105 | 'KNeighborsRegressor()':list(y_KNNR),'DecisionTreeRegressor()':list(y_DR),'SVR()':list(y_SVMR)}) 106 | 107 | self.model_plot(self.y_true, model_pre) 108 | self.graphicsView.setStyleSheet("border-image: url(model_plot.png);") 109 | 110 | 111 | except: 112 | my_button_w3=QMessageBox.warning(self,"严重警告", '请务必先加载数据然后再点击模型预测!!!', QMessageBox.Ok|QMessageBox.Cancel, QMessageBox.Ok) 113 | 114 | 115 | 116 | @pyqtSlot() 117 | def on_action_triggered(self): 118 | """ 119 | Slot documentation goes here. 120 | """ 121 | # TODO: not implemented yet 122 | print('打开') 123 | my_button_open = QMessageBox.about(self, '打开', '点击我打开某些文件') 124 | 125 | @pyqtSlot() 126 | def on_action_2_triggered(self): 127 | """ 128 | Slot documentation goes here. 129 | """ 130 | # TODO: not implemented yet 131 | print('关闭') 132 | sys.exit(0) 133 | 134 | @pyqtSlot() 135 | def on_action_3_triggered(self): 136 | """ 137 | Slot documentation goes here. 138 | """ 139 | # TODO: not implemented yet 140 | print('联系我们') 141 | my_button_con_me = QMessageBox.about(self, '联系我们', '这个位置放的是联系我们的介绍') 142 | 143 | @pyqtSlot() 144 | def on_action_4_triggered(self): 145 | """ 146 | Slot documentation goes here. 147 | """ 148 | # TODO: not implemented yet 149 | print('关于我们') 150 | my_button_about_me = QMessageBox.about(self, '关于我们', '这个位置放的是关于我们的介绍') 151 | 152 | 153 | @pyqtSlot() 154 | def on_action_QT_triggered(self): 155 | """ 156 | Slot documentation goes here. 157 | """ 158 | # TODO: not implemented yet 159 | print('关于qt') 160 | my_button_about_QT = QMessageBox.aboutQt(self, '关于QT') 161 | 162 | 163 | 164 | if __name__ == "__main__": 165 | import sys 166 | app = QtWidgets.QApplication(sys.argv) 167 | splash = QSplashScreen(QtGui.QPixmap(':/my_pic/pic/face.png')) 168 | splash.show() 169 | QThread.sleep(0.5) 170 | splash.showMessage('正在加载机器学习算法...' ) 171 | QThread.sleep(1) 172 | splash.showMessage('正在初始化程序...') 173 | QThread.sleep(0.5) 174 | #splash.show() 175 | app. processEvents() 176 | ui =MainWindow() 177 | # ui.setDaemon(True`) 178 | # ui.start() 179 | ui.show() 180 | splash.finish(ui) 181 | sys.exit(app.exec_()) 182 | 183 | -------------------------------------------------------------------------------- /my_main_ui.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 930 10 | 600 11 | 12 | 13 | 14 | 波士顿房价预测系统 v1.0 15 | 16 | 17 | 18 | :/my_pic/pic/kh.png:/my_pic/pic/kh.png 19 | 20 | 21 | 22 | 23 | 24 | 20 25 | 20 26 | 191 27 | 161 28 | 29 | 30 | 31 | 房价预测操作 32 | 33 | 34 | 35 | 36 | 20 37 | 30 38 | 151 39 | 31 40 | 41 | 42 | 43 | 加载数据源 44 | 45 | 46 | 47 | :/my_pic/pic/lajiao.png:/my_pic/pic/lajiao.png 48 | 49 | 50 | 51 | 52 | 53 | 20 54 | 90 55 | 151 56 | 31 57 | 58 | 59 | 60 | 模型预测房价 61 | 62 | 63 | 64 | :/my_pic/pic/xiaoche.png:/my_pic/pic/xiaoche.png 65 | 66 | 67 | 68 | 69 | 70 | 71 | 240 72 | 20 73 | 671 74 | 521 75 | 76 | 77 | 78 | 模型预测结果 79 | 80 | 81 | 82 | 83 | 10 84 | 20 85 | 651 86 | 491 87 | 88 | 89 | 90 | false 91 | 92 | 93 | background-image: url(:/my_pic/pic/face.png); 94 | 95 | 96 | 97 | 98 | 99 | 100 | 213 101 | 20 102 | 20 103 | 521 104 | 105 | 106 | 107 | Qt::Vertical 108 | 109 | 110 | 111 | 112 | 113 | 20 114 | 260 115 | 201 116 | 271 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 0 125 | 0 126 | 930 127 | 23 128 | 129 | 130 | 131 | 132 | 文件 133 | 134 | 135 | 136 | 137 | 138 | 139 | 帮助 140 | 141 | 142 | 143 | 144 | 145 | 关于 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | :/my_pic/pic/open.png:/my_pic/pic/open.png 158 | 159 | 160 | 打开 161 | 162 | 163 | 164 | 165 | 166 | :/my_pic/pic/close.png:/my_pic/pic/close.png 167 | 168 | 169 | 关闭 170 | 171 | 172 | 173 | 174 | 175 | :/my_pic/pic/connect.png:/my_pic/pic/connect.png 176 | 177 | 178 | 联系我们 179 | 180 | 181 | 182 | 183 | 184 | :/my_pic/pic/aboutme.png:/my_pic/pic/aboutme.png 185 | 186 | 187 | 关于我们 188 | 189 | 190 | 191 | 192 | 193 | :/my_pic/pic/aboutqt.png:/my_pic/pic/aboutqt.png 194 | 195 | 196 | 关于QT 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /Ui_my_main_ui.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Form implementation generated from reading ui file 'C:\Users\Administrator.USER-20170417DX\Desktop\ML+Pyqt\code\my_app\my_main_ui.ui' 4 | # 5 | # Created by: PyQt5 UI code generator 5.10 6 | # 7 | # WARNING! All changes made in this file will be lost! 8 | 9 | from PyQt5 import QtCore, QtGui, QtWidgets 10 | 11 | class Ui_MainWindow(object): 12 | def setupUi(self, MainWindow): 13 | MainWindow.setObjectName("MainWindow") 14 | MainWindow.resize(930, 600) 15 | icon = QtGui.QIcon() 16 | icon.addPixmap(QtGui.QPixmap(":/my_pic/pic/kh.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 17 | MainWindow.setWindowIcon(icon) 18 | self.centralWidget = QtWidgets.QWidget(MainWindow) 19 | self.centralWidget.setObjectName("centralWidget") 20 | self.groupBox = QtWidgets.QGroupBox(self.centralWidget) 21 | self.groupBox.setGeometry(QtCore.QRect(20, 20, 191, 161)) 22 | self.groupBox.setObjectName("groupBox") 23 | self.pushButton = QtWidgets.QPushButton(self.groupBox) 24 | self.pushButton.setGeometry(QtCore.QRect(20, 30, 151, 31)) 25 | self.pushButton.setFixedHeight(40) 26 | self.pushButton.setStyleSheet("QPushButton{color:white;background:LimeGreen;border-radius:20px;border:3px solid black;}") 27 | icon1 = QtGui.QIcon() 28 | icon1.addPixmap(QtGui.QPixmap(":/my_pic/pic/lajiao.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 29 | self.pushButton.setIcon(icon1) 30 | self.pushButton.setObjectName("pushButton") 31 | self.pushButton_2 = QtWidgets.QPushButton(self.groupBox) 32 | self.pushButton_2.setGeometry(QtCore.QRect(20, 90, 151, 31)) 33 | self.pushButton_2.setFixedHeight(40) 34 | self.pushButton_2.setStyleSheet("QPushButton{color:white;background:Orange;border-radius:20px;border:3px solid black;}") 35 | icon2 = QtGui.QIcon() 36 | icon2.addPixmap(QtGui.QPixmap(":/my_pic/pic/xiaoche.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 37 | self.pushButton_2.setIcon(icon2) 38 | self.pushButton_2.setObjectName("pushButton_2") 39 | self.groupBox_2 = QtWidgets.QGroupBox(self.centralWidget) 40 | self.groupBox_2.setGeometry(QtCore.QRect(240, 20, 671, 521)) 41 | self.groupBox_2.setObjectName("groupBox_2") 42 | self.graphicsView = QtWidgets.QGraphicsView(self.groupBox_2) 43 | self.graphicsView.setGeometry(QtCore.QRect(10, 20, 651, 491)) 44 | self.graphicsView.setStyleSheet("background-image: url(:/my_pic/pic/face.png);") 45 | self.graphicsView.setObjectName("graphicsView") 46 | self.line = QtWidgets.QFrame(self.centralWidget) 47 | self.line.setGeometry(QtCore.QRect(213, 20, 20, 521)) 48 | self.line.setFrameShape(QtWidgets.QFrame.VLine) 49 | self.line.setFrameShadow(QtWidgets.QFrame.Sunken) 50 | self.line.setObjectName("line") 51 | self.calendarWidget = QtWidgets.QCalendarWidget(self.centralWidget) 52 | self.calendarWidget.setGeometry(QtCore.QRect(20, 260, 201, 271)) 53 | self.calendarWidget.setObjectName("calendarWidget") 54 | MainWindow.setCentralWidget(self.centralWidget) 55 | self.menuBar = QtWidgets.QMenuBar(MainWindow) 56 | self.menuBar.setGeometry(QtCore.QRect(0, 0, 930, 23)) 57 | self.menuBar.setObjectName("menuBar") 58 | self.menu = QtWidgets.QMenu(self.menuBar) 59 | self.menu.setObjectName("menu") 60 | self.menu_2 = QtWidgets.QMenu(self.menuBar) 61 | self.menu_2.setObjectName("menu_2") 62 | self.menu_3 = QtWidgets.QMenu(self.menuBar) 63 | self.menu_3.setObjectName("menu_3") 64 | MainWindow.setMenuBar(self.menuBar) 65 | self.action = QtWidgets.QAction(MainWindow) 66 | icon3 = QtGui.QIcon() 67 | icon3.addPixmap(QtGui.QPixmap(":/my_pic/pic/open.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 68 | self.action.setIcon(icon3) 69 | self.action.setObjectName("action") 70 | self.action_2 = QtWidgets.QAction(MainWindow) 71 | icon4 = QtGui.QIcon() 72 | icon4.addPixmap(QtGui.QPixmap(":/my_pic/pic/close.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 73 | self.action_2.setIcon(icon4) 74 | self.action_2.setObjectName("action_2") 75 | self.action_3 = QtWidgets.QAction(MainWindow) 76 | icon5 = QtGui.QIcon() 77 | icon5.addPixmap(QtGui.QPixmap(":/my_pic/pic/connect.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 78 | self.action_3.setIcon(icon5) 79 | self.action_3.setObjectName("action_3") 80 | self.action_4 = QtWidgets.QAction(MainWindow) 81 | icon6 = QtGui.QIcon() 82 | icon6.addPixmap(QtGui.QPixmap(":/my_pic/pic/aboutme.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 83 | self.action_4.setIcon(icon6) 84 | self.action_4.setObjectName("action_4") 85 | self.action_QT = QtWidgets.QAction(MainWindow) 86 | icon7 = QtGui.QIcon() 87 | icon7.addPixmap(QtGui.QPixmap(":/my_pic/pic/aboutqt.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) 88 | self.action_QT.setIcon(icon7) 89 | self.action_QT.setObjectName("action_QT") 90 | self.menu.addAction(self.action) 91 | self.menu.addAction(self.action_2) 92 | self.menu_2.addAction(self.action_3) 93 | self.menu_3.addAction(self.action_4) 94 | self.menu_3.addAction(self.action_QT) 95 | self.menuBar.addAction(self.menu.menuAction()) 96 | self.menuBar.addAction(self.menu_2.menuAction()) 97 | self.menuBar.addAction(self.menu_3.menuAction()) 98 | 99 | self.retranslateUi(MainWindow) 100 | QtCore.QMetaObject.connectSlotsByName(MainWindow) 101 | 102 | def retranslateUi(self, MainWindow): 103 | _translate = QtCore.QCoreApplication.translate 104 | MainWindow.setWindowTitle(_translate("MainWindow", "波士顿房价预测系统 v1.0")) 105 | self.groupBox.setTitle(_translate("MainWindow", "房价预测操作")) 106 | self.pushButton.setText(_translate("MainWindow", "加载数据源")) 107 | self.pushButton_2.setText(_translate("MainWindow", "模型预测房价")) 108 | self.groupBox_2.setTitle(_translate("MainWindow", "模型预测结果")) 109 | self.menu.setTitle(_translate("MainWindow", "文件")) 110 | self.menu_2.setTitle(_translate("MainWindow", "帮助")) 111 | self.menu_3.setTitle(_translate("MainWindow", "关于")) 112 | self.action.setText(_translate("MainWindow", "打开")) 113 | self.action_2.setText(_translate("MainWindow", "关闭")) 114 | self.action_3.setText(_translate("MainWindow", "联系我们")) 115 | self.action_4.setText(_translate("MainWindow", "关于我们")) 116 | self.action_QT.setText(_translate("MainWindow", "关于QT")) 117 | 118 | import my_pic_rc 119 | 120 | if __name__ == "__main__": 121 | import sys 122 | app = QtWidgets.QApplication(sys.argv) 123 | MainWindow = QtWidgets.QMainWindow() 124 | ui = Ui_MainWindow() 125 | ui.setupUi(MainWindow) 126 | MainWindow.show() 127 | sys.exit(app.exec_()) 128 | 129 | --------------------------------------------------------------------------------