could not convert string to float: 'Skoda Laura' [duplicate]
I am stuck here. I'm trying to make a website which make predictions on machine learning.
car=cars[['name','company','year','car_prices','kms_driven','fuel_type']]
car['name']=car['name'].str.split(' ').str.slice(0,3).str.join(' ')
x=cars.drop(columns='car_prices')
y=cars['car_prices']
from sklearn.model_selection import train_test_split
x_train,y_train,x_test,y_test=train_test_split(x,y,test_size=0.3)
ohe=OneHotEncoder()
ohe.fit(x[['name','company','fuel_type']])
ohe.categories_
column_trans=make_column_transformer((OneHotEncoder(categories=ohe.categories_),['name','company','fuel_type']),remainder="passthrough")
lr=LinearRegression()
pipe=make_pipeline(column_trans,lr)
pipe.fit(x_train,y_train)
ValueError: could not convert string to float: 'Skoda Laura'
ValueError: could not convert string to float: 'Skoda Laura'
`` Also car.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 5512 entries, 0 to 5511 Data columns (total 6 columns):
Column Non-Null Count Dtype
0 car_name 5512 non-null object 1 company 5512 non-null object 2 year 5512 non-null int32 3 car_prices 5512 non-null int32 4 kms_driven 5512 non-null int32 5 fuel_type 5512 non-null object dtypes: int32(3), object(3) memory usage: 193.9+ KB
Comments
Post a Comment