2024-12-16 21:34:48 -05:00
<!doctype html> < html lang = en dir = ltr class = "blog-wrapper blog-post-page plugin-blog plugin-id-default" data-has-hydrated = false > < meta charset = UTF-8 > < meta name = generator content = "Docusaurus v3.6.1" > < title data-rh = true > Predicting Santander customer happiness | The Old Speice Guy< / title > < meta data-rh = true name = viewport content = "width=device-width,initial-scale=1.0" > < meta data-rh = true name = twitter:card content = summary_large_image > < meta data-rh = true property = og:url content = https://speice.io/2016/03/predicting-santander-customer-happiness > < meta data-rh = true property = og:locale content = en > < meta data-rh = true name = docusaurus_locale content = en > < meta data-rh = true name = docusaurus_tag content = default > < meta data-rh = true name = docsearch:language content = en > < meta data-rh = true name = docsearch:docusaurus_tag content = default > < meta data-rh = true property = og:title content = "Predicting Santander customer happiness | The Old Speice Guy" > < meta data-rh = true name = description content = "My first Kaggle competition." > < meta data-rh = true property = og:description content = "My first Kaggle competition." > < meta data-rh = true property = og:type content = article > < meta data-rh = true property = article:published_time content = 2016-03-05T12:00:00.000Z > < link data-rh = true rel = icon href = /img/favicon.ico > < link data-rh = true rel = canonical href = https://speice.io/2016/03/predicting-santander-customer-happiness > < link data-rh = true rel = alternate href = https://speice.io/2016/03/predicting-santander-customer-happiness hreflang = en > < link data-rh = true rel = alternate href = https://speice.io/2016/03/predicting-santander-customer-happiness hreflang = x-default > < script data-rh = true type = application/ld+json > { "@context" : "https://schema.org" , "@id" : "https://speice.io/2016/03/predicting-santander-customer-happiness" , "@type" : "BlogPosting" , "author" : { "@type" : "Person" , "name" : "Bradlee Speice" } , "dateModified" : "2024-11-06T03:32:56.000Z" , "datePublished" : "2016-03-05T12:00:00.000Z" , "description" : "My first Kaggle competition." , "headline" : "Predicting Santander customer happiness" , "isPartOf" : { "@id" : "https://speice.io/" , "@type" : "Blog" , "name" : "Blog" } , "keywords" : [ ] , "mainEntityOfPage" : "https://speice.io/2016/03/predicting-santander-customer-happiness" , "name" : "Predicting Santander customer happiness" , "url" : "https://speice.io/2016/03/predicting-santander-customer-happiness" } < / script > < link rel = alternate type = application/rss+xml href = /rss.xml title = "The Old Speice Guy RSS Feed" > < link rel = alternate type = application/atom+xml href = /atom.xml title = "The Old Speice Guy Atom Feed" > < link rel = stylesheet href = /katex/katex.min.css > < link rel = stylesheet href = /assets/css/styles.16c3428d.css > < script src = /assets/js/runtime~main.29a27dcf.js defer > < / script > < script src = /assets/js/main.d461af80.js defer > < / script > < body class = navigation-with-keyboard > < script > ! function ( ) { var t , e = function ( ) { try { return new URLSearchParams ( window . location . search ) . get ( "docusaurus-theme" ) } catch ( t ) { } } ( ) || function ( ) { try { return window . localStorage . getItem ( "theme" ) } catch ( t ) { } } ( ) ; t = null !== e ? e : "light" , document . documentElement . setAttribute ( "data-theme" , t ) } ( ) , function ( ) { try { for ( var [ t , e ] of new URLSearchParams ( window . location . search ) . entries ( ) ) if ( t . startsWith ( "docusaurus-data-" ) ) { var a = t . replace ( "docusaurus-data-" , "data-" ) ; document . documentElement . setAttribute ( a , e ) } } catch ( t ) { } } ( ) < / script > < div id = __docusaurus > < div role = region aria-label = "Skip to main content" > < a class = skipToContent_fXgn href = #__docusaurus_skipToContent_fallback > Skip to main content< / a > < / div > < nav aria-label = Main class = "navbar navbar--fixed-top" > < div class = navbar__inner > < div class = navbar__items > < button aria-label = "Toggle navigation bar" aria-expanded = false class = "navbar__toggle clean-btn" type = button > < svg width = 30 height = 30 viewBox = "0 0 30 30" aria-hidden = true > < path stroke = currentColor stroke-linecap = round stroke-miterlimit = 10 stroke-width = 2 d = "M4 7h22M4 15h22M4 23h22" / > < / svg > < / button > < a class = navbar__brand href = / > < div class = navbar__logo > < img src = /img/logo.svg alt = "Sierpinski Gasket" class = "themedComponent_mlkZ themedComponent--light_NVdE" > < img src = /img/logo-dark.svg alt = "Sierpinski Gasket" class = "themedComponent_ml
2024-11-10 16:43:02 -05:00
< p > It's time! After embarking on a Machine Learning class this semester, and with a Saturday in which I don't have much planned, I wanted to put this class and training to work. It's my first competition submission. I want to walk you guys through how I'm approaching this problem, because I thought it would be really neat. The competition is Banco Santander's < a href = https://www.kaggle.com/c/santander-customer-satisfaction target = _blank rel = "noopener noreferrer" > Santander Customer Satisfaction< / a > competition. It seemed like an easy enough problem I could actually make decent progress on it.< / p >
< h2 class = "anchor anchorWithStickyNavbar_LWe7" id = data-exploration > Data Exploration< a href = #data-exploration class = hash-link aria-label = "Direct link to Data Exploration" title = "Direct link to Data Exploration" > < / a > < / h2 >
< p > First up: we need to load our data and do some exploratory work. Because we're going to be using this data for model selection prior to testing, we need to make a further split. I've already gone ahead and done this work, please see the code in the < a href = #appendix > appendix below< / a > .< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > pandas < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > as< / span > < span class = "token plain" > pd< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > numpy < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > as< / span > < span class = "token plain" > np< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > matplotlib< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > pyplot < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > as< / span > < span class = "token plain" > plt< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > %< / span > < span class = "token plain" > matplotlib inline< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token comment" style = "color:hsl(230, 4%, 64%)" > # Record how long it takes to run the notebook - I'm curious.< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > from< / span > < span class = "token plain" > datetime < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > datetime< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > start < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > datetime< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > now< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > dataset < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > pd< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > read_csv< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > 'split_train.csv'< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > dataset< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > index < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > dataset< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > ID< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > X < / span > < sp
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > unique< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< div class = "codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-text codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > array([0, 1], dtype=int64)< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > columns< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< div class = "codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-text codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > 369< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< p > Okay, so there are only < a href = https://www.kaggle.com/c/santander-customer-satisfaction/data target = _blank rel = "noopener noreferrer" > two classes we're predicting< / a > : 1 for unsatisfied customers, 0 for satisfied customers. I would have preferred this to be something more like a regression, or predicting multiple classes: maybe the customer isn't the most happy, but is nowhere near closing their accounts. For now though, that's just the data we're working with.< / p >
< p > Now, I'd like to make a scatter matrix of everything going on. Unfortunately as noted above, we have 369 different features. There's no way I can graphically make sense of that much data to start with.< / p >
< p > We're also not told what the data actually represents: Are these survey results? Average time between contact with a customer care person? Frequency of contacting a customer care person? The idea is that I need to reduce the number of dimensions we're predicting across.< / p >
< h3 class = "anchor anchorWithStickyNavbar_LWe7" id = dimensionality-reduction-pt-1---binary-classifiers > Dimensionality Reduction pt. 1 - Binary Classifiers< a href = #dimensionality-reduction-pt-1---binary-classifiers class = hash-link aria-label = "Direct link to Dimensionality Reduction pt. 1 - Binary Classifiers" title = "Direct link to Dimensionality Reduction pt. 1 - Binary Classifiers" > < / a > < / h3 >
< p > My first attempt to reduce the data dimensionality is to find all the binary classifiers in the dataset (i.e. 0 or 1 values) and see if any of those are good (or anti-good) predictors of the final data.< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > cols < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > columns< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > b_class < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > < / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > for< / span > < span class = "token plain" > c < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > in< / span > < span class = "token plain" > cols< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > :< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > if< / span > < span class = "token plain" > < / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token plain" > c< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > unique< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > ==< / span > < span class = "token plain" > < / span > < span class = "token number" style = "color:hsl(35, 99%, 36%)" > 2< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > :< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > b_class< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > append< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > c< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > b_class< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L
< div class = "codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-text codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > 111< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< p > So there are 111 features in the dataset that are a binary label. Let's see if any of them are good at predicting the users satisfaction!< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token comment" style = "color:hsl(230, 4%, 64%)" > # First we need to `binarize` the data to 0-1; some of the labels are {0, 1},< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token comment" style = "color:hsl(230, 4%, 64%)" > # some are {0, 3}, etc.< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > from< / span > < span class = "token plain" > sklearn< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > preprocessing < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > binarize< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > X_bin < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > binarize< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token plain" > b_class< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > accuracy < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > < / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token plain" > np< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > mean< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X_bin< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > :< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > i< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token plain" > < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > ==< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > for< / span > < span class = "token plain" > i < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > in< / span > < span class = "token plain" > < / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > range< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token number" style = "color:hsl(35, 99%, 36%)" > 0< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > < / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > b_class< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token plain" > < / span > < br >
< div > < table > < thead > < tr > < th > < th > Accuracy< tbody > < tr > < th > count< td > 111.000000< tr > < th > mean< td > 0.905159< tr > < th > std< td > 0.180602< tr > < th > min< td > 0.043598< tr > < th > 25%< td > 0.937329< tr > < th > 50%< td > 0.959372< tr > < th > 75%< td > 0.960837< tr > < th > max< td > 0.960837< / table > < / div >
< p > Wow! Looks like we've got some incredibly predictive features! So much so that we should be a bit concerned. My initial guess for what's happening is that we have a sparsity issue: so many of the values are 0, and these likely happen to line up with satisfied customers.< / p >
< p > So the question we must now answer, which I likely should have asked long before now: What exactly is the distribution of un/satisfied customers?< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > unsat < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > [< / span > < span class = "token plain" > y < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > ==< / span > < span class = "token plain" > < / span > < span class = "token number" style = "color:hsl(35, 99%, 36%)" > 1< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ]< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > count< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > print< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > "Satisfied customers: {}; Unsatisfied customers: {}"< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > format< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > -< / span > < span class = "token plain" > unsat< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > unsat< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > naive_guess < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > np< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > mean< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > y < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > ==< / span > < span class = "token plain" > np< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > zeros< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > len< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > print< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > "Naive guess accuracy: {}"< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token builtin" style = "color:hsl(119, 3
< div class = "codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-text codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > Satisfied customers: 51131; Unsatisfied customers: 2083< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > Naive guess accuracy: 0.9608561656706882< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< p > This is a bit discouraging. A naive guess of "always satisfied" performs as well as our best individual binary classifier. What this tells me then, is that these data columns aren't incredibly helpful in prediction. I'd be interested in a polynomial expansion of this data-set, but for now, that's more computation than I want to take on.< / p >
< h3 class = "anchor anchorWithStickyNavbar_LWe7" id = dimensionality-reduction-pt-2---lda > Dimensionality Reduction pt. 2 - LDA< a href = #dimensionality-reduction-pt-2---lda class = hash-link aria-label = "Direct link to Dimensionality Reduction pt. 2 - LDA" title = "Direct link to Dimensionality Reduction pt. 2 - LDA" > < / a > < / h3 >
< p > Knowing that our naive guess performs so well is a blessing and a curse:< / p >
< ul >
< li > Curse: The threshold for performance is incredibly high: We can only "improve" over the naive guess by 4%< / li >
< li > Blessing: All the binary classification features we just discovered are worthless on their own. We can throw them out and reduce the data dimensionality from 369 to 111.< / li >
< / ul >
< p > Now, in removing these features from the dataset, I'm not saying that there is no "information" contained within them. There might be. But the only way we'd know is through a polynomial expansion, and I'm not going to take that on within this post.< / p >
< p > My initial thought for a "next guess" is to use the < a href = http://scikit-learn.org/stable/modules/lda_qda.html target = _blank rel = "noopener noreferrer" > LDA< / a > model for dimensionality reduction. However, it can only reduce dimensions to < span class = katex > < span class = katex-mathml > < math > < semantics > < mrow > < mn > 1< / mn > < mo > − < / mo > < mi > p< / mi > < / mrow > < annotation encoding = application/x-tex > 1 - p< / annotation > < / semantics > < / math > < / span > < span class = katex-html aria-hidden = true > < span class = base > < span class = strut style = height:0.7278em;vertical-align:-0.0833em > < / span > < span class = mord > 1< / span > < span class = mspace style = margin-right:0.2222em > < / span > < span class = mbin > − < / span > < span class = mspace style = margin-right:0.2222em > < / span > < / span > < span class = base > < span class = strut style = height:0.625em;vertical-align:-0.1944em > < / span > < span class = "mord mathnormal" > p< / span > < / span > < / span > < / span > , with < span class = katex > < span class = katex-mathml > < math > < semantics > < mrow > < mi > p< / mi > < / mrow > < annotation encoding = application/x-tex > p< / annotation > < / semantics > < / math > < / span > < span class = katex-html aria-hidden = true > < span class = base > < span class = strut style = height:0.625em;vertical-align:-0.1944em > < / span > < span class = "mord mathnormal" > p< / span > < / span > < / span > < / span > being the number of classes. Since this is a binary classification, every LDA model that I try will have dimensionality one; when I actually try this, the predictor ends up being slightly less accurate than the naive guess.< / p >
< p > Instead, let's take a different approach to dimensionality reduction: < a href = http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html target = _blank rel = "noopener noreferrer" > principle components analysis< / a > . This allows us to perform the dimensionality reduction without worrying about the number of classes. Then, we'll use a < a href = http://scikit-learn.org/stable/modules/naive_bayes.html#gaussian-naive-bayes target = _blank rel = "noopener noreferrer" > Gaussian Naive Bayes< / a > model to actually do the prediction. This model is chosen simply because it doesn't take a long time to fit and compute; because PCA will take so long, I just want a prediction at the end of this. We can worry about using a more sophisticated LDA/QDA/SVM model later.< / p >
< p > Now into the actual process: We're going to test out PCA dimensionality reduction from 1 - 20 dimensions, and then predict using a Gaussian Naive Bayes model. The 20 dimensions upper limit was selected because the accuracy never improves after you get beyond that (I found out by running it myself). Hopefully, we'll find that we can create a model better than the naive guess.< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > from< / span > < span class = "token plain" > sklearn< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > naive_bayes < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > GaussianNB< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > from< / span > < span class = "token plain" > sklearn< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > decomposition < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > PCA< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > X_no_bin < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > drop< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > b_class< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > < / span > < span class = "token number" style = "color:hsl(35, 99%, 36%)" > 1< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > def< / span > < span class = "token plain" > < / span > < span class = "token function" style = "color:hsl(221, 87%, 60%)" > evaluate_gnb< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > dims< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > :< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > pca < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > PCA< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > n_components< / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > dims< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > X_xform < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > pca< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > fit_transform< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X_no_bin< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > gnb < / span > < span class = "token operator"
< p > < img decoding = async loading = lazy alt = png src = /assets/images/_notebook_11_0-2d0fe64b876b1c32a095f2d74b128f3c.png width = 710 height = 368 class = img_ev3q > < / p >
< p > < strong > sigh...< / strong > After all the effort and computational power, we're still at square one: we have yet to beat out the naive guess threshold. With PCA in play we end up performing terribly, but not terribly enough that we can guess against ourselves.< / p >
< p > Let's try one last-ditch attempt using the entire data set:< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > def< / span > < span class = "token plain" > < / span > < span class = "token function" style = "color:hsl(221, 87%, 60%)" > evaluate_gnb_full< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > dims< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > :< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > pca < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > PCA< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > n_components< / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > dims< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > X_xform < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > pca< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > fit_transform< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > gnb < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > GaussianNB< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > gnb< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > fit< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X_xform< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > return< / span > < span class = "token plain" > gnb< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > score< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > X_xform< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > y< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > dim_range < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > np< / span > < span class = "token punctuation" style = "color:hsl(119, 34 % , 47
< p > < img decoding = async loading = lazy alt = png src = /assets/images/_notebook_13_0-2d0fe64b876b1c32a095f2d74b128f3c.png width = 710 height = 368 class = img_ev3q > < / p >
< p > Nothing. It is interesting to note that the graphs are almost exactly the same: This would imply again that the variables we removed earlier (all the binary classifiers) indeed have almost no predictive power. It seems this problem is high-dimensional, but with almost no data that can actually inform our decisions.< / p >
< h2 class = "anchor anchorWithStickyNavbar_LWe7" id = summary-for-day-1 > Summary for Day 1< a href = #summary-for-day-1 class = hash-link aria-label = "Direct link to Summary for Day 1" title = "Direct link to Summary for Day 1" > < / a > < / h2 >
< p > After spending a couple hours with this dataset, there seems to be a fundamental issue in play: We have very high-dimensional data, and it has no bearing on our ability to actually predict customer satisfaction. This can be a huge issue: it implies that < strong > no matter what model we use, we fundamentally can't perform well.< / strong > I'm sure most of this is because I'm not an experienced data scientist. Even so, we have yet to develop a strategy that can actually beat out the village idiot; < strong > so far, the bank is best off just assuming all its customers are satisfied.< / strong > Hopefully more to come soon.< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > end < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > datetime< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > now< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > print< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > "Running time: {}"< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token builtin" style = "color:hsl(119, 34%, 47%)" > format< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > end < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > -< / span > < span class = "token plain" > start< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< div class = "codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-text codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > Running time: 0:00:58.715714< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true > < svg viewBox = "0 0 24 24" class = copyButtonIcon_y97N > < path fill = currentColor d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" / > < / svg > < svg viewBox = "0 0 24 24" class = copyButtonSuccessIcon_LjdS > < path fill = currentColor d = M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z / > < / svg > < / span > < / button > < / div > < / div > < / div >
< h2 class = "anchor anchorWithStickyNavbar_LWe7" id = appendix > Appendix< a href = #appendix class = hash-link aria-label = "Direct link to Appendix" title = "Direct link to Appendix" > < / a > < / h2 >
< p > Code used to split the initial training data:< / p >
< div class = "language-python codeBlockContainer_Ckt0 theme-code-block" style = "--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)" > < div class = codeBlockContent_biex > < pre tabindex = 0 class = "prism-code language-python codeBlock_bY9V thin-scrollbar" style = "background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)" > < code class = codeBlockLines_e6Vv > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > from< / span > < span class = "token plain" > sklearn< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > cross_validation < / span > < span class = "token keyword" style = "color:hsl(301, 63%, 40%)" > import< / span > < span class = "token plain" > train_test_split< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > pd< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > read_csv< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > 'train.csv'< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > index < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > data< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > ID< / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data_train< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > data_validate < / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token plain" > train_test_split< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > ,< / span > < span class = "token plain" > train_size< / span > < span class = "token operator" style = "color:hsl(221, 87%, 60%)" > =< / span > < span class = "token number" style = "color:hsl(35, 99%, 36%)" > .7< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" style = display:inline-block > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data_train< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > to_csv< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > 'split_train.csv'< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < span class = "token plain" > < / span > < br > < / span > < span class = token-line style = "color:hsl(230, 8%, 24%)" > < span class = "token plain" > data_validate< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > .< / span > < span class = "token plain" > to_csv< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > (< / span > < span class = "token string" style = "color:hsl(119, 34%, 47%)" > 'split_validate.csv'< / span > < span class = "token punctuation" style = "color:hsl(119, 34%, 47%)" > )< / span > < br > < / span > < / code > < / pre > < div class = buttonGroup__atx > < button type = button aria-label = "Copy code to clipboard" title = Copy class = clean-btn > < span class = copyButtonIcons_eSgA aria-hidden = true >