Issue
why this error appears and what does it mean exactly?
It appears on this code (I put only the part of machine learning, because the code is so long):
import numpy as np
from sklearn import neighbors
n_neighbors = 3
if (automatic == 'true'):
# import some data to play with
home = Homes.query.filter_by(device_id = request.args.get('?device_id')).first()
htng_orders = Heating_orders.query.filter_by(home_id = home.id).all()
X_h = [[ho.timeInMinutes, ho.season, ho.ext_temp] for ho in htng_orders]
y_h = [ho.instruction for ho in htng_orders]
clf_h = neighbors.KNeighborsClassifier(n_neighbors, weights='distance')
clf_h.fit(X_h, y_h)
new_time = datetime.datetime.now().time()
new_timeInMinutes = (new_time.hour*60 + new_time.minute)
new_season = get_season(date.today())
new_ext_temp = getExtTemperature(home.city)
new_data_h = np.c_[new_timeInMinutes, new_season, new_ext_temp]
preddiction_h = clf_h.predict(new_data_h)
The error is the following:
[...]
File "C:\[...]\FlaskREST\app.py", line 525, in get
new_data_h = np.c_[new_timeInMinutes, new_season, new_ext_temp]
File "C:\Python\Python36-32\lib\site-packages\numpy\lib\index_tricks.py", line 289, in __getitem__
raise ValueError("special directives must be the "
ValueError: special directives must be the first entry.
Thank you in advance!
Solution
Looking at what the code is doing I don't think you should have np.c_
there at all. The model is trained on a triplets of (TimeInMinutes, season, ext_temp)
, so you'll want to pass that same data format into the .predict
function.
new_data_h
should be
new_data_h = [new_timeInMinutes, new_season, new_ext_temp]
just in case you're curious
https://docs.scipy.org/doc/numpy/reference/generated/numpy.c_.html
Answered By - Matti Lyra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.