sklearn决策树简单应用——预测风向

 所需图片↓

 

import tkinter as tk
from tkinter import ttk
import joblib
import pandas


seasons_dict = {'春': 1, '夏': 2, '秋': 3, '冬': 4}
winds_dict = {'东北风': 1, '西北风': 2, '东南风': 3, '西南风': 4}

pics_dict ={'东南风':'images/东南风.gif',
            '东北风':'images/东北风.gif',
            '西南风':'images/西南风.gif',
            '西北风':'images/西北风.gif'}
tips_dict ={'东南风':'预测结果:东南风','东北风':'预测结果:东北风','西南风':'预测结果:西南风','西北风':'预测结果:西北风'}

model = joblib.load('风向预测.pkl')

#以上是调用模型的代码

def show():
    global img, tip
    season_value = seasons_dict[season_combo.get()]
    speed_value = speed_scale.get()
    humi_value = humi_scale.get()
    temp_value = temp_scale.get()
    pres_value = pres_scale.get()

    data = {}
    data['季节'] = season_value
    data['湿度'] = humi_value
    data['气压'] = pres_value
    data['温度'] = temp_value
    data['风速'] = speed_value
    df_data = pandas.DataFrame(data, index=[0])
    y_pre = model.predict(df_data)

    if y_pre == '东南风':
        pic = pics_dict['东南风']
        tip = tips_dict['东南风']
    elif y_pre == '东北风':
        pic = pics_dict['东北风']
        tip = tips_dict['东北风']
    elif y_pre == '西南风':
        pic = pics_dict['西南风']
        tip = tips_dict['西南风']
    elif y_pre == '西北风':
        pic = pics_dict['西北风']
        tip = tips_dict['西北风']
    
    img = tk.PhotoImage(file=pic)
    info_label.config(text=tip)
    img_label.config(image=img)


win = tk.Tk()
win.geometry('600x600')
win.title('风向预测工具')

season_label = tk.Label(win, text='季节:')
season_label.place(x=50, y=80)
season_combo = ttk.Combobox(win, width=12, values=['春', '夏', '秋', '冬'])
season_combo.current(0)
season_combo.place(x=100, y=80)

speed_scale = tk.Scale(win, label='风速:', from_=0, to=100, orient=tk.HORIZONTAL, tickinterval=50, length=200, resolution=0.1)
speed_scale.place(x=50, y=140)

temp_scale = tk.Scale(win, label='温度:',orient=tk.HORIZONTAL, from_=-20   ,to=40   ,tickinterval=20 ,length=200  )
temp_scale.place(x=50, y=   240)

humi_scale = tk.Scale(win, label='湿度:',orient=tk.HORIZONTAL, from_=0   ,to=100   ,tickinterval=50 ,length=200  )
humi_scale.place(x=50  , y=340   )

pres_scale = tk.Scale(win, label='气压:',orient=tk.HORIZONTAL, from_=990   ,to=1050   ,tickinterval=  30 ,length=200)
pres_scale.place(x=50  , y=440  )

submit_button = tk.Button(win, text='提交', width=10, command=show)
submit_button.place(x=100, y=550)

tip = '使用风向预测工具可以得到不同气侯情况下对应的风向'
info_label = tk.Label(win, text=tip, wraplength=270, justify='left', font=('黑体', 14))
info_label.place(x=300, y=150)

img = tk.PhotoImage(file='images/初始图片.gif')
img_label = tk.Label(win, image=img)
img_label.place(x=320, y=220)


win.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值