0

I'm using Streamlit to build a machine learning model to predict the price of a car. After splitting the data into train and test and choosing the best model, I need to predict the price of a car based on the user input

ax1,ax2 = st.columns(2)
with ax1:
    year = st.slider('Year The Car Manufatured', 1996,2020,1996)
    model = st.selectbox('model',('Fiesta'  ,'Focus','Kuga','EcoSport','C-MAX','Ka+','Mondeo','B-MAX','S-MAX','Grand C-MAX','Galaxy','Edge','KA','Puma','Tourneo Custom','Grand Tourneo Connect','Mustang','Tourneo Connect','Fusion','Streetka','Ranger','Transit Tourneo','Escort','Focus','Transit Tourneo'))
    transmission = st.selectbox('transmission', ('Manual','Automatic','Semi-Auto'))
    
    mileage = st.slider('How many mileage?', 0, 18000) 
with ax2:
    fuelType= st.selectbox('fuelType', ('Petrol','Diesel','Hybrid','Electric','Other'))
    tax= st.slider('Tax Amount', 0, 600)
    mpg = st.slider('MPG', 0, 250)
    engineSize =  st.slider('engineSize', 0, 5)
    
data = {'year':[year],'model':[model],'transmission':[transmission], 
            'fuelType':[fuelType],'mileage':[mileage],'mpg':[mpg],'engineSize':[engineSize], 
            'tax':[tax],}
features = pd.DataFrame(data)
cars = pd.read_csv("ford.csv")
cars.columns = cars.columns.str.strip()

cars.fillna(0, inplace=True)
cars = cars.drop(columns=['price'])

df = pd.concat([features,cars],axis=0)

df.columns = df.columns.str.strip()
df = pd.get_dummies(df, columns =  ['model','transmission', 'fuelType'],drop_first=True)

df = df[:1]
df.fillna(0, inplace=True)

def RFR():
    RFR= RandomForestRegressor(n_estimators=10, min_samples_leaf=0.05)
    RFR= RFR.fit(x, y)

prediction = RFR().predict(df)

i'm getting the below error:

ValueError: could not convert string to float: ' Fiesta'

Any Idea what might be the problem ?

Nour H
  • 1
  • 1
  • Is this issue occurred while model prediction or model fitting? – Nanthakumar J J May 22 '22 at 07:56
  • It was working perfectly fine on the train/test but somehow crashes while applying it on the user input i've found the below question : https://stackoverflow.com/questions/56319021/error-converting-string-to-float-when-using-model-predict it has the same issue but couldn't figure out how to solve it – Nour H May 22 '22 at 07:57
  • What are the headers in the `ford.csv`? Could you print the df in `predict(df)`? – ferdy May 22 '22 at 11:54

1 Answers1

0

The problem is you are trying to convert a string into a float because a float is a decimal for e.x (x.0) and a string is in Apostrophe '' / ""

smokey
  • 21
  • 2