Home ยป python

python

Solving “Found unknown categories […] in column” with sklearn OneHotEncoder

  • by
  • 1 min read

In this short blog post, I tackle an error related to a classic problem within machine learning: how to treat unseen categorical values and solve the “found unknown categories” error. Imagine you have a train and a test data set with the following values in a column: Train: [‘green’, ‘red’,… 

Undersampling a Pandas DataFrame

  • by
  • 2 min read

In a previous post, I explained how you can sample two Pandas DataFrame exactly the same way. In this blog post, I want to use that helper function to undersample your predictors and target variable. When you are working with an imbalanced data set, it’s often good practice to under-… 

How to solve SettingWithCopyWarning when using the ‘inplace’ parameter in pandas

  • by
  • 2 min read

The SettingWithCopyWarning message is a confusing warning to many who are new to Pandas. If you’ve ever taken a computer science course, you might be aware of passing/copying by value or by reference. Well, it very much applies to pandas DataFrames too. Let’s go. Basically, when you are slicing a…