The to test my code is: print(regressor.predict([[1, 0, 0, 90, 100]]))
This then provides an output. The first 3 elements in the array represent morning, afternoon and evening.
i.e.
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.
Essentially at the end, when I run my notebook, I want it to ask the user for the following inputs:
Period of Day (i.e. Morning, Afternoon, Evening). InputVariable1 InputVariable2
Once they input these, the predict function should be applied and the output should be printed.
CodePudding user response:
You can take the input from user then use the stored dict of mapping between the input to list to generate the required list format
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))
CodePudding user response:
You can use if elif and else statements like this.
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]]))