简体   繁体   中英

"AttributeError: 'str' object has no attribute 'predict'". I am developing a car price predictor using Linear Regression model

Error : AttributeError: 'str' object has no attribute 'predict'".

maker=input('Maker:')
model=input('Model:') 
mileage=int(input('Mileage:')) 
manufacture_year= int(input('Manufacture Year:')) 
engine_hp= int(input('Engine_Hp:')) 
transmission= input('Transmission:') 
door_count= int(input('Door count:')) 
seat_count= int(input('Seat count:')) 
fuel_type= input('Fuel type:')  
outcome=model.predict(maker,model,mileage,manufacture_year,engine_hp,transmission,door_count,seat_count,fuel_type)
print('Price Of Car Should be approx: ',outcome)

I hope you already found your answer, anyway, if you are using keras(tensorflow) then model.predict() expects the first parameter to be a numpy array.

model.predict(x, batch_size=None, verbose=0, steps=None, callbacks=None)

where x: is input samples. Can be a NumPy array or a TensorFlow tensor.

After taking inputs you need to do some data processing and prepare them to feed your model and after compiling/training of your model use the processed data to make some predictions.

There is a chance you get this error if you are loading the saved model from path. Try using "model=load_model(modelFile)" in modelfile place give the path to your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM