[{"data":1,"prerenderedAt":117},["ShallowReactive",2],{"term-o\u002Fone-hot-encoding":3,"related-o\u002Fone-hot-encoding":102},{"id":4,"title":5,"acronym":6,"body":7,"category":84,"description":85,"difficulty":86,"extension":87,"letter":88,"meta":89,"navigation":53,"path":90,"related":91,"seo":96,"sitemap":97,"stem":100,"subcategory":6,"__hash__":101},"terms\u002Fterms\u002Fo\u002Fone-hot-encoding.md","One-Hot Encoding",null,{"type":8,"value":9,"toc":78},"minimark",[10,15,19,23,26,30,67,71,74],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 - The Vibe Check",[16,17,18],"p",{},"Models are bad at math with words, so if a column says red, blue, or green, you can't just feed that in directly. One-hot encoding turns that single column into three new columns, is_red, is_blue, is_green, each a simple 1 or 0, so the model sees clean numbers instead of a category it has no idea how to compare.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"One-hot encoding converts a categorical variable with n possible values into n binary columns, where exactly one column is set to 1 for each row and the rest are 0, avoiding the false sense of numeric order that would be implied by simply assigning integers to categories. It's a standard preprocessing step for algorithms that expect numeric input and can't natively interpret categorical features, though it can balloon the number of columns when a category has very high cardinality.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-python shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import pandas as pd\n\ndf = pd.get_dummies(df, columns=['color'], prefix='color')\n# color_red, color_blue, color_green columns, each 0 or 1\n","python","",[38,39,40,48,55,61],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,47],{},"import pandas as pd\n",[41,49,51],{"class":43,"line":50},2,[41,52,54],{"emptyLinePlaceholder":53},true,"\n",[41,56,58],{"class":43,"line":57},3,[41,59,60],{},"df = pd.get_dummies(df, columns=['color'], prefix='color')\n",[41,62,64],{"class":43,"line":63},4,[41,65,66],{},"# color_red, color_blue, color_green columns, each 0 or 1\n",[11,68,70],{"id":69},"when-youll-hear-this","When You'll Hear This",[16,72,73],{},"\"Don't just assign 1, 2, 3 to the categories, that implies an order that doesn't exist, one-hot encode it.\" \u002F \"This column has 40,000 unique values, one-hot encoding it would blow up the feature space.\"",[75,76,77],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":50,"depth":50,"links":79},[80,81,82,83],{"id":13,"depth":50,"text":14},{"id":21,"depth":50,"text":22},{"id":28,"depth":50,"text":29},{"id":69,"depth":50,"text":70},"ai","Models are bad at math with words, so if a column says red, blue, or green, you can't just feed that in directly.","beginner","md","o",{},"\u002Fterms\u002Fo\u002Fone-hot-encoding",[92,93,94,95],"Feature Engineering","Pandas","Random Forest","Machine Learning",{"title":5,"description":85},{"changefreq":98,"priority":99},"weekly",0.7,"terms\u002Fo\u002Fone-hot-encoding","Yp0fSDQN_ABu0iQUCGtVZ42w_kK9grVKbmuH6ELxYFk",[103,107,111,114],{"title":92,"path":104,"acronym":6,"category":84,"difficulty":105,"description":106},"\u002Fterms\u002Ff\u002Ffeature-engineering","intermediate","Feature engineering is the unglamorous, hugely important work of turning raw, messy real-world data into the specific columns a model can actually learn fr...",{"title":95,"path":108,"acronym":109,"category":84,"difficulty":86,"description":110},"\u002Fterms\u002Fm\u002Fmachine-learning","ML","Machine Learning is teaching a computer by showing it thousands of examples instead of writing out every rule.",{"title":93,"path":112,"acronym":6,"category":84,"difficulty":86,"description":113},"\u002Fterms\u002Fp\u002Fpandas","Pandas is the Python library that turns a spreadsheet-shaped pile of data into something your code can actually filter, group, join, and reshape in a coupl...",{"title":94,"path":115,"acronym":6,"category":84,"difficulty":105,"description":116},"\u002Fterms\u002Fr\u002Frandom-forest","A random forest is what you get when you refuse to trust a single decision tree's opinion and instead grow hundreds of slightly different trees, each train...",1792528104805]