billylanchantin
I have a dataset with categorical variables, e.g.:
alias Explorer.DataFrame, as: DF
df = DF.new(%{
age: [1, 5, 3],
animal: ["dog", "cat", "dog"], # categorical
color: ["brown", "black", "brindle"] # categorical
})
I currently have the variables one-hot encoded:
df_one_hot = DF.new(%{
age: [1, 5, 3],
animal_cat_1_of_2: [1, 0, 1], # animal == "dog"
animal_cat_2_of_2: [0, 1, 0], # animal == "cat"
color_cat_1_of_3: [1, 0, 0], # color == "brown"
color_cat_2_of_3: [0, 1, 0], # color == "black"
color_cat_3_of_3: [0, 0, 1], # color == "brindle"
})
Neural nets generally do well with that encoding. Tree-based models, however, may benefit from the original encoding or ordinal encoding. So while experimenting with different models, I found myself needing to undo the one-hot encoding.
I came up with a solution which I’ll post below. But I wanted to see how others would approach the problem. This is a somewhat computationally-intensive operation, and I worry that I’m not taking full advantage of Explorer. In particular, this looked like it may be a job for across, but I couldn’t make it work.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
billylanchantin
My approach for converting to an ordinal encoding:
josevalim
If you can hardcode the fields, then you can do:
If you cannot, then you can port your approach to
mutate_with.mutate_withgives you access to the columns and allow you to dynamically build a query based on the field. Then useSeries.selectto build thecond. Scroll down to find the answer (I added some padding in case you want to try it out by yourself before seeing the solution):billylanchantin
Thanks! That made a huge improvement.
Quick benchmark on a subset of the data (cols: 203, rows: 65,917):
What’s more, your solution works on lazy frames. I needed to call
DF.collectmy dataframe first.This particular dataset had ~80 columns one-hot columns. Hardcoding is do-able, but I’d prefer to avoid it if possible.