![]() It works in a manner that first statements inside the try block will execute and if it have some error then only except block will be executed. In the loop we have used try and except function which consists of 2 blocks, 'try' and 'except'. We have created a loop which will iterate over the columns from the list 'columnsToEncode'. So, We have created an object for LabelEncoder with no parameters. ![]() classes_ : It is the array of labels or categorical values.There is one attribute and zero parameter for LabelEncoder. So let us have a look on the parameters and the attributes which we need to pass. the columns having data type 'category' or 'object'. Initially in the function, we have created an object 'columnsToEncode' which will make a list of columns that have of categorical values i.e. Now Let us try to understand each statement of the function. In which we will be selecting the columns having categorical values and will perform Label Encoding.ĬolumnsToEncode = list(df.select_dtypes(include=))ĭf = le.fit_transform(df) We have created a function named 'Encoder'. Step 3 - Create a function for LabelEncoder ![]() So these two features are categorical features. We have converted this dataset into a dataframe with its features as columns.Ĭlearly, we can see that the features City_pool and City_Temperature have non numerical values. This is a dataset of city with different features in it like City_level, City_pool, Rating, City_port and City_Temperature. Let us create a simple dataset and convert it to a dataframe. ![]() ![]() Step 2 - Setup the DataĬity_data = ĭf = pd.DataFrame(city_data, columns = ) Here we have imported Pandas and LabelEncoder which will be used to convert the categorical variables into numerical variables. Get Closer To Your Dream of Becoming a Data Scientist with 70+ Solved End-to-End ML Projects Step 1 - Import the library - LabelEncoderįrom sklearn.preprocessing import LabelEncoder ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |