简体   繁体   English

有没有办法将输入以预测 function 转换为分类数据,以便用户友好?

[英]Is there a way to convert input to predict function into categorical data so it is user-friendly?

The to test my code is: print(regressor.predict([[1, 0, 0, 90, 100]]))测试我的代码是: print(regressor.predict([[1, 0, 0, 90, 100]]))

This then provides an output.这提供了一个 output。 The first 3 elements in the array represent morning, afternoon and evening.数组中的前 3 个元素代表早上、下午和晚上。

ie IE

1, 0 , 0 is morning
0, 1, 0 is afternoon
0, 0, 1 is evening

I want the user to be able to input Morning, Afternoon or Evening instead of having to put in something like print(regressor.predict([[1, 0, 0, 90, 100]])) which means morning, inputvariable1 = 90 and inputvariable2 = 100.我希望用户能够输入 Morning、Afternoon 或 Evening 而不必输入类似 print(regressor.predict([[1, 0, 0, 90, 100]])) 的东西,这意味着早上,inputvariable1 = 90和输入变量2 = 100。

Essentially at the end, when I run my notebook, I want it to ask the user for the following inputs:基本上在最后,当我运行我的笔记本时,我希望它向用户询问以下输入:

Period of Day (ie Morning, Afternoon, Evening).一天中的时段(即早上、下午、晚上)。 InputVariable1 InputVariable2输入变量 1 输入变量 2

Once they input these, the predict function should be applied and the output should be printed.一旦他们输入这些,就应该应用预测 function 并且应该打印 output。

You can use if elif and else statements like this.您可以像这样使用 if elif 和 else 语句。

time_of_day = input("Enter morning, afternoon, or evening")
inputVariable1 = input("Enter inputVariable1")
inputVariable2 = input("Enter inputVariable2")

if time_of_day == "morning":
    print(regressor.predict([[1, 0, 0, inputVariable1, inputVariable2]]))
elif time_of_day == "afternoon":
    print(regressor.predict([[0, 1, 0, inputVariable1, inputVariable2]]))
else:
    print(regressor.predict([[0, 0, 1, inputVariable1, inputVariable2]]))

You can take the input from user and map to the list stored and append other inputs as required.您可以根据需要从用户和 map 到存储的列表和 append 其他输入中获取输入。

d = {
"morning": [1, 0, 0],
"afternoon": [0, 1, 0],
"evening": [0, 0, 1]
}

period = input("Enter Period of Day (i.e. Morning, Afternoon, Evening)")
input_var_1 = int(input("Enter input var 1"))
input_var_2 = int(input("Enter input var 2"))

l = [d[period.lower()] + [input_var_1, input_var_2]]

print(model.predict(l))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置用户友好和显式标志值的最 Pythonic 方式? - Most Pythonic way of setting user-friendly and explicit flag values? 使 Spotipy 程序用户友好 - Making Spotipy program user-friendly Python 中的用户友好时间格式? - User-friendly time format in Python? Python - 检查缺失库依赖项的用户友好方式的最佳实践? - Python - Best practice for user-friendly way of checking for missing library dependencies? Django Python-以易于使用的方式向用户显示数据,包括通过views.py从models.py到HTML模板 - Django Python - Displaying data to user in user-friendly manner from models.py to HTML template through views.py 将 django 项目作为完整安装文件 (setup.exe) 交付以方便用户且不泄露整个脚本的最佳方式是什么? - What is the best way to deliver django project as a full installation file (setup.exe) to be user-friendly and not revealing your whole scripts? Debian(raspberry pi)中用户友好的python代码编辑器 - user-friendly python code editor in debian (raspberry pi) 在Twitch机器人中添加帐户和更友好的集成 - Adding account and more user-friendly integration into Twitch bot 我正在尝试以更加用户友好的方式从文件 (tasks.txt) 中打印所有已登录用户的任务。 这是我到目前为止所拥有的 - I am trying to print all of the logged-in users tasks from a file(tasks.txt) in a more user-friendly manner. This is what I have so far 损失 function 和用于训练“分类输入”到“分类输出”model 的数据格式? - Loss function and data format for training a ''categorical input' to 'categorical output' model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM