[英]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.