Ex_treme's blog.

利用KNN分类器采访随机游客预测天气感知度

2018/11/14 Share

实例构造

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# -*- coding: utf-8 -*-
# @Time : 18-11-14 下午6:05
# @Author : Ex_treme
# @Email : pzsyjsgldd@163.com
# @File : example.py
# @Software: PyCharm
from knn import create_dataset
from knn import knn_Classifier

def predict_temperature(dataset, labels):
iceCream = float(input("Q:请问你今天吃了几个冰淇淋?\n"))
drinkWater = float(input("Q:请问你今天喝了几升水?\n"))
playAct = float(input("Q:请问你今天在户外运动了几个小时?\n"))
k = knn_Classifier([iceCream,drinkWater,playAct], dataset, labels)
res = k.classify(len(dataset))
return print("该游客认为今天天气:",res)


if __name__ == "__main__":
dataset, labels = create_dataset()
predict_temperature(dataset, labels)

结果预测

    /home/pzs741/anaconda3/bin/python /home/pzs741/PycharmProjects/nlp/example.py
    Q:请问你今天吃了几个冰淇淋?
    1
    Q:请问你今天喝了几升水?
    1
    Q:请问你今天在户外运动了几个小时?
    1
    该游客认为今天天气: 一般热

    Process finished with exit code 0
CATALOG
  1. 1. 实例构造
  2. 2. 结果预测