import%20marimo%0A%0A__generated_with%20%3D%20%220.16.0%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20seaborn%20as%20sns%0A%20%20%20%20return%20mo%2C%20np%2C%20pd%2C%20plt%2C%20sns%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Machine%20Learning%20Zoomcamp%0A%0A%20%20%20%20%23%23%20Module%203%3A%20**Classification**%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(pd)%3A%0A%20%20%20%20repository_root%20%3D%20%22https%3A%2F%2Fgithub.com%2FDataTalksClub%2Fmachine-learning-zoomcamp%2Fblob%2Fmaster%2F%22%0A%0A%20%20%20%20chapters%20%3D%20pd.DataFrame(%5B%0A%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Churn%20Prediction%20Project%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%220Zw04wdeTQo%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F01-churn-project.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Data%20Preparation%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22VSGGU9gYvdg%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F02-data-preparation.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Setting%20up%20the%20Validation%20Framework%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22_lwz34sOnSE%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F03-validation.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Exporatory%20Data%20Analysis%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22BNF1wjBwTQA%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F04-eda.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Feature%20Importance%3A%20Churn%20Rate%20and%20Risk%20Ratio%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22fzdzPLlvs40%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F05-risk.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Feature%20Importance%3A%20Mutual%20Information%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22_u2YaGT6RN0%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F06-mutual-info.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Feature%20importance%3A%20Correlation%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22mz1707QVxiY%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F07-correlation.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22One-hot%20Encoding%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22L-mjQFN5aR0%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F08-ohe.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Logistic%20Regression%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%227KFE2ltnBAg%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F09-logistic-regression.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Training%20Logistic%20Regression%20with%20Scikit-Learn%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22hae_jXe2fN0%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F10-training-log-reg.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Model%20Interpretation%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22OUrlxnUAAEA%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F11-log-reg-interpretation.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Using%20the%20Model%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22Y-NGmnFpNuM%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F12-using-log-reg.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Summary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22youtube_id%22%3A%20%22Zz6oRGsJkW4%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F13-summary.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22title%22%3A%20%22Explore%20More%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22contents%22%3A%20repository_root%2B%2203-classification%2F14-explore-more.md%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%5D)%0A%0A%20%20%20%20chapters.insert(loc%3D0%2C%20column%3D%22snapshot%22%2C%20value%3D%22https%3A%2F%2Fimg.youtube.com%2Fvi%2F%22%2Bchapters.youtube_id.astype(str)%2B%22%2Fhqdefault.jpg%22)%0A%20%20%20%20chapters.insert(loc%3D2%2C%20column%3D%22youtube%22%2C%20value%3D%22https%3A%2F%2Fyoutube.com%2Fwatch%3Fv%3D%22%2Bchapters.youtube_id.astype(str))%0A%0A%20%20%20%20videos%20%3D%20chapters%5Bchapters%5B%22youtube_id%22%5D.notnull()%5D%0A%20%20%20%20videos%5B%5B%22snapshot%22%2C%20%22title%22%2C%20%22youtube%22%5D%5D%0A%20%20%20%20return%20(chapters%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(chapters)%3A%0A%20%20%20%20contents%20%3D%20chapters%5Bchapters%5B%22contents%22%5D.notnull()%5D%0A%20%20%20%20contents%5B%5B%22title%22%2C%20%22contents%22%5D%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Churn%20Prediction%20Project%0A%0A%20%20%20%20We'll%20be%20working%20with%20the%20%5BTelco%20Customer%20Churn%5D(https%3A%2F%2Fwww.kaggle.com%2Fdatasets%2Fblastchar%2Ftelco-customer-churn)%20dataset%20from%20Kaggle%2C%20with%20the%20goal%20of%20implementing%20a%20model%20that's%20able%20to%20predict%20if%20a%20customer%20is%20likely%20to%20%22churn%22%20(stop%20using%20the%20service).%0A%0A%20%20%20%20%23%23%23%20The%20Dataset%0A%0A%20%20%20%20The%20raw%20data%20contains%207043%20rows%20(customers)%20and%2021%20columns%20(features).%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(pd)%3A%0A%20%20%20%20pd.DataFrame(%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22customerID%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Customer%20ID%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22gender%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20is%20a%20male%20or%20a%20female%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22SeniorCitizen%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20is%20a%20senior%20citizen%20or%20not%20(1%2C%200)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22Partner%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20a%20partner%20or%20not%20(Yes%2C%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22Dependents%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20dependents%20or%20not%20(Yes%2C%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22tenure%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Number%20of%20months%20the%20customer%20has%20stayed%20with%20the%20company%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22PhoneService%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20a%20phone%20service%20or%20not%20(Yes%2C%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22MultipleLines%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20multiple%20lines%20or%20not%20(Yes%2C%20No%2C%20No%20phone%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22InternetService%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Customer%E2%80%99s%20internet%20service%20provider%20(DSL%2C%20Fiber%20optic%2C%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22OnlineSecurity%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20online%20security%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22OnlineBackup%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20online%20backup%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22DeviceProtection%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20device%20protection%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22TechSupport%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20tech%20support%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22StreamingTV%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20streaming%20TV%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%20%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22StreamingMovies%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20streaming%20movies%20or%20not%20(Yes%2C%20No%2C%20No%20internet%20service)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22Contract%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22The%20contract%20term%20of%20the%20customer%20(Month-to-month%2C%20One%20year%2C%20Two%20year)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22PaperlessBilling%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20has%20paperless%20billing%20or%20not%20(Yes%2C%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22PaymentMethod%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22The%20customer%E2%80%99s%20payment%20method%20(Electronic%20check%2C%20Mailed%20check%2C%20Bank%20transfer%20(automatic)%2C%20Credit%20card%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22MonthlyCharges%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22The%20amount%20charged%20to%20the%20customer%20monthly%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22TotalCharges%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22The%20total%20amount%20charged%20to%20the%20customer%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22column%22%3A%20%22Churn%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Whether%20the%20customer%20churned%20or%20not%20(Yes%20or%20No)%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%2F%2F%2F%20admonition%20%7C%20Local%20Dataset%20Path%0A%0A%20%20%20%20For%20convenience%2C%20the%20dataset%20has%20already%20been%20downloaded%20into%20%5Bmodule-3%2Fdata%2Fcustomer-churn.csv%5D(module-3%2Fdata%2Fcustomer-churn.csv).%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pd)%3A%0A%20%20%20%20df%20%3D%20pd.read_csv(%22module-3%2Fdata%2Fcustomer-churn.csv%22)%0A%0A%20%20%20%20df.head()%0A%20%20%20%20return%20(df%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20The%20Goal%0A%0A%20%20%20%20What%20we'll%20try%20to%20do%20is%20to%20predict%20the%20**Churn**%20column%2C%20which%20will%20be%20our%20target%20variable%20and%20represents%20the%20customers%20who%20actually%20left%20the%20service.%0A%0A%20%20%20%20%23%23%23%20The%20Method%0A%0A%20%20%20%20We'll%20train%20a%20binary%20classification%20model%20that%20will%20attempt%20to%20classify%20customers%20in%20two%20groups%2C%20the%20ones%20that%20are%20right%20about%20to%20churn%20and%20the%20ones%20who%20are%20not.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Data%20Preparation%0A%0A%20%20%20%20%23%23%23%20Histograms%20of%20Numeric%20Columns%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20plt%2C%20sns)%3A%0A%20%20%20%20fig%2C%20axes%20%3D%20plt.subplots(1%2C%203%2C%20figsize%3D(15%2C%204))%0A%0A%20%20%20%20sns.histplot(df.SeniorCitizen%2C%20bins%3D15%2C%20ax%3Daxes%5B0%5D)%0A%20%20%20%20axes%5B0%5D.set_title('Senior%20Citizen')%0A%0A%20%20%20%20sns.histplot(df.tenure%2C%20bins%3D15%2C%20ax%3Daxes%5B1%5D)%0A%20%20%20%20axes%5B1%5D.set_title('Tenure')%0A%0A%20%20%20%20sns.histplot(df.MonthlyCharges%2C%20bins%3D15%2C%20ax%3Daxes%5B2%5D)%0A%20%20%20%20axes%5B2%5D.set_title('Monthly%20Charges')%0A%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Standardize%20Column%20Names%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20pd)%3A%0A%20%20%20%20def%20standardize_column_names(dataframe%3A%20pd.DataFrame)%20-%3E%20pd.DataFrame%3A%0A%20%20%20%20%20%20%20%20standardized%20%3D%20dataframe.copy()%0A%20%20%20%20%20%20%20%20standardized.columns%20%3D%20standardized.columns.str.lower().str.replace('%20'%2C%20'_')%0A%0A%20%20%20%20%20%20%20%20return%20standardized%0A%0A%20%20%20%20standardize_column_names(df)%0A%20%20%20%20return%20(standardize_column_names%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Standardize%20Column%20Values%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20pd)%3A%0A%20%20%20%20def%20get_cateogorical_columns(dataframe%3A%20pd.DataFrame)%20-%3E%20list%5Bstr%5D%3A%0A%20%20%20%20%20%20%20%20return%20list(list(dataframe.dtypes%5Bdataframe.dtypes%20%3D%3D%20'object'%5D.index))%0A%0A%20%20%20%20def%20standardize_categorical_values(dataframe%3A%20pd.DataFrame)%20-%3E%20pd.DataFrame%3A%0A%20%20%20%20%20%20%20%20standardized%20%3D%20dataframe.copy()%0A%0A%20%20%20%20%20%20%20%20for%20column%20in%20get_cateogorical_columns(standardized)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20standardized%5Bcolumn%5D%20%3D%20standardized%5Bcolumn%5D.str.lower().str.replace('%20'%2C%20'_')%0A%0A%20%20%20%20%20%20%20%20return%20standardized%0A%0A%20%20%20%20standardize_categorical_values(df)%0A%20%20%20%20return%20(standardize_categorical_values%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Prepare%20a%20Standardized%20Dataset%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df%2C%20standardize_categorical_values%2C%20standardize_column_names)%3A%0A%20%20%20%20df_standardized%20%3D%20standardize_column_names(df)%0A%20%20%20%20df_standardized%20%3D%20standardize_categorical_values(df_standardized)%0A%0A%20%20%20%20df_standardized%0A%20%20%20%20return%20(df_standardized%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Fix%20Column%20Data%20Types%0A%0A%20%20%20%20%23%23%23%23%20Total%20Charges%0A%0A%20%20%20%20First%20we'll%20convert%20the%20%60totalcharges%60%20column%20to%20numeric%20coercing%20(setting%20to%20null)%20the%20values%20that%20cannot%20be%20converted%20to%20numeric.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_standardized%2C%20pd)%3A%0A%20%20%20%20totalcharges%20%3D%20pd.to_numeric(df_standardized.totalcharges%2C%20errors%3D'coerce')%0A%0A%20%20%20%20totalcharges%0A%20%20%20%20return%20(totalcharges%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Now%2C%20we'll%20check%20what%20values%20were%20lost%20during%20the%20transformation.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_standardized%2C%20totalcharges)%3A%0A%20%20%20%20df_standardized%5Btotalcharges.isnull()%5D%5B%5B%22customerid%22%2C%20%22totalcharges%22%5D%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Finally%2C%20we'll%20fill%20the%20empty%20values%20with%20zeroes.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(df_standardized%2C%20sns%2C%20totalcharges)%3A%0A%20%20%20%20df_standardized.totalcharges%20%3D%20totalcharges.fillna(0)%0A%0A%20%20%20%20sns.histplot(df_standardized.totalcharges%2C%20bins%3D25)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Churn%0A%0A%0A%20%20%20%20Rather%20than%20a%20boolean%20column%2C%20the%20%60churn%60%20column%20contains%20strings%20with%20the%20values%20**yes**%20or%20**no**.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_standardized)%3A%0A%20%20%20%20df_standardized.churn.unique()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Let's%20fix%20it!%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_standardized)%3A%0A%20%20%20%20df_standardized.churn%20%3D%20(df_standardized.churn%20%3D%3D%20'yes').astype(int)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Setting%20up%20the%20Validation%20Framework%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_standardized%2C%20pd)%3A%0A%20%20%20%20from%20sklearn.model_selection%20import%20train_test_split%0A%0A%20%20%20%20def%20split_dataframe(dataframe%3A%20pd.DataFrame)%20-%3E%20pd.DataFrame%3A%0A%20%20%20%20%20%20%20%20full_train%2C%20test%20%3D%20train_test_split(dataframe%2C%20test_size%3D0.2%2C%20random_state%3D1)%0A%20%20%20%20%20%20%20%20train%2C%20val%20%3D%20train_test_split(full_train%2C%20test_size%3D0.25%2C%20random_state%3D1)%0A%0A%20%20%20%20%20%20%20%20return%20train%2C%20val%2C%20test%2C%20full_train%0A%0A%20%20%20%20df_train%2C%20df_val%2C%20df_test%2C%20df_full%20%3D%20split_dataframe(df_standardized)%0A%0A%20%20%20%20df_train%20%3D%20df_train.reset_index(drop%3DTrue)%0A%20%20%20%20df_val%20%3D%20df_val.reset_index(drop%3DTrue)%0A%20%20%20%20df_test%20%3D%20df_test.reset_index(drop%3DTrue)%0A%20%20%20%20df_full%20%3D%20df_full.reset_index(drop%3DTrue)%0A%20%20%20%20return%20df_full%2C%20df_test%2C%20df_train%2C%20df_val%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Check%20the%20Size%20of%20the%20Splits%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full%2C%20df_test%2C%20df_train%2C%20df_val)%3A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22train%22%3A%20len(df_train)%2C%0A%20%20%20%20%20%20%20%20%22val%22%3A%20len(df_val)%2C%0A%20%20%20%20%20%20%20%20%22test%22%3A%20len(df_test)%2C%0A%20%20%20%20%20%20%20%20%22full%22%3A%20len(df_full)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Exploratory%20Data%20Analysis%0A%0A%20%20%20%20%23%23%23%20Check%20for%20Missing%20Values%0A%0A%20%20%20%20After%20a%20quick%20check%20we%20see%20that%20there%20are%20no%20missing%20values.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20df_full.isnull().sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Look%20at%20the%20Target%20Variable%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20df_full.churn.value_counts()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Get%20the%20global%20average%20churn.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20df_full.churn.mean().round(2)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Display%20the%20Numerical%20Features%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20numerical_columns%20%3D%20%5B%22tenure%22%2C%20%22monthlycharges%22%2C%20%22totalcharges%22%5D%0A%0A%20%20%20%20df_full%5B%5B%22customerid%22%5D%20%2B%20numerical_columns%5D%0A%20%20%20%20return%20(numerical_columns%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Look%20at%20the%20Categorical%20Variables%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20df_full.dtypes%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%23%20Count%20the%20Different%20Values%20for%20Each%20Categorical%20Value%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20categorical_columns%20%3D%20%5B%0A%20%20%20%20%20%20%20%20'gender'%2C%20'seniorcitizen'%2C%20'partner'%2C%20'dependents'%2C%0A%20%20%20%20%20%20%20%20'phoneservice'%2C%20'multiplelines'%2C%20'internetservice'%2C%20'onlinesecurity'%2C%0A%20%20%20%20%20%20%20%20'onlinebackup'%2C%20'deviceprotection'%2C%20'techsupport'%2C%20'streamingtv'%2C%0A%20%20%20%20%20%20%20%20'streamingmovies'%2C%20'contract'%2C%20'paperlessbilling'%2C%20'paymentmethod'%0A%20%20%20%20%5D%0A%0A%20%20%20%20df_full%5Bcategorical_columns%5D.nunique()%0A%20%20%20%20return%20(categorical_columns%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Feature%20Importance%3A%20Churn%20Rate%20and%20Risk%20Ratio%0A%0A%20%20%20%20%23%23%23%20Churn%20Rate%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%23%20Check%20the%20Churn%20Rate%20for%20Each%20Gender%0A%0A%20%20%20%20As%20the%20mean%20of%20the%20churn%20for%20each%20gender%20is%20almost%20equal%20to%20the%20general%20mean%2C%20we%20can%20start%20guessing%20that%20gender%20is%20not%20going%20to%20be%20a%20very%20important%20feature%20when%20trying%20to%20predict%20the%20churn.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22churn_female%22%3A%20df_full%5Bdf_full.gender%20%3D%3D%20%22female%22%5D.churn.mean().round(2)%2C%0A%20%20%20%20%20%20%20%20%22churn_male%22%3A%20df_full%5Bdf_full.gender%20%3D%3D%20%22male%22%5D.churn.mean().round(2)%2C%0A%20%20%20%20%20%20%20%20%22churn_general%22%3A%20df_full.churn.mean().round(2)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%23%20Check%20the%20Churn%20Rate%20for%20Each%20Partner%0A%0A%20%20%20%20As%20the%20mean%20of%20the%20churn%20changes%20significantly%20depending%20on%20whether%20the%20client%20has%20a%20partner%20or%20not%2C%20we%20can%20guess%20that%20this%20column%20will%20have%20a%20bigger%20impact%20when%20trying%20to%20predict%20the%20churn.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22churn_partner%22%3A%20df_full%5Bdf_full.partner%20%3D%3D%20%22yes%22%5D.churn.mean().round(2)%2C%0A%20%20%20%20%20%20%20%20%22churn_no_partner%22%3A%20df_full%5Bdf_full.partner%20%3D%3D%20%22no%22%5D.churn.mean().round(2)%2C%0A%20%20%20%20%20%20%20%20%22churn_general%22%3A%20df_full.churn.mean().round(2)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full%2C%20pd)%3A%0A%20%20%20%20def%20check_importance(column_name%3A%20str%2C%20dataframe%3A%20pd.DataFrame)%20-%3E%20pd.DataFrame%3A%0A%20%20%20%20%20%20%20%20group%20%3D%20dataframe.groupby(column_name).churn.agg(%5B%22mean%22%2C%20%22count%22%5D).round(2)%0A%20%20%20%20%20%20%20%20group%5B%22diff%22%5D%20%3D%20(group%5B%22mean%22%5D%20-%20dataframe.churn.mean()).round(2)%0A%20%20%20%20%20%20%20%20group%5B%22risk%22%5D%20%3D%20(group%5B%22mean%22%5D%20%2F%20dataframe.churn.mean()).round(2)%0A%0A%20%20%20%20%20%20%20%20return%20group%0A%0A%20%20%20%20check_importance(%22gender%22%2C%20df_full)%0A%20%20%20%20return%20(check_importance%2C)%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20check_importance%2C%20df_full%2C%20pd)%3A%0A%20%20%20%20def%20check_importances(dataframe%3A%20pd.DataFrame)%20-%3E%20list%5Bpd.DataFrame%5D%3A%0A%20%20%20%20%20%20%20%20importances%20%3D%20%5B%5D%0A%0A%20%20%20%20%20%20%20%20for%20categorical_column%20in%20categorical_columns%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20importances.append(check_importance(categorical_column%2C%20dataframe))%0A%0A%20%20%20%20%20%20%20%20return%20importances%0A%0A%20%20%20%20check_importances(df_full)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Feature%20Importance%3A%20Mutual%20Information%0A%0A%20%20%20%20The%20mutual%20information%20metric%20tells%20us%20how%20much%20we%20know%20a%20variable%20through%20another%20variable.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20from%20sklearn.metrics%20import%20mutual_info_score%0A%0A%20%20%20%20mutual_info_score(df_full.churn%2C%20df_full.contract)%0A%20%20%20%20return%20(mutual_info_score%2C)%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20df_full%2C%20mutual_info_score%2C%20pd)%3A%0A%20%20%20%20def%20check_churn_importance(series%3A%20pd.Series)%20-%3E%20list%5Bpd.Series%5D%3A%0A%20%20%20%20%20%20%20%20return%20round(mutual_info_score(df_full.churn%2C%20series)%2C%203)%0A%0A%20%20%20%20df_full%5Bcategorical_columns%5D.apply(check_churn_importance).sort_values(ascending%3DFalse)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Feature%20Importance%3A%20Correlation%0A%0A%20%20%20%20We'll%20now%20consider%20correlation%20metrics%20between%20our%20variables.%20In%20particular%2C%20we'll%20use%20the%20%5BPearson%20correlation%20coefficient%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPearson_correlation_coefficient).%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full%2C%20numerical_columns)%3A%0A%20%20%20%20df_full%5Bnumerical_columns%5D.corrwith(df_full.churn).abs()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Now%2C%20we'll%20check%20that%20as%20tenure%20increases%2C%20churn%20decreases.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20churn_by_tenure%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22to_2%22%3A%20df_full%5Bdf_full.tenure%20%3C%202%5D.churn.mean()%2C%0A%20%20%20%20%20%20%20%20%22from_2_to_12%22%3A%20df_full%5B(df_full.tenure%20%3E%3D%202)%20%26%20(df_full.tenure%20%3C%2012)%5D.churn.mean()%2C%0A%20%20%20%20%20%20%20%20%22from_12%22%3A%20df_full%5Bdf_full.tenure%20%3E%3D%2012%5D.churn.mean()%2C%0A%20%20%20%20%7D%0A%0A%20%20%20%20churn_by_tenure%0A%20%20%20%20return%20(churn_by_tenure%2C)%0A%0A%0A%40app.cell%0Adef%20_(churn_by_tenure%2C%20sns)%3A%0A%20%20%20%20sns.barplot(x%3D%5B%22x%20%3C%202%22%2C%20%222%20%3C%3D%20x%20%3C%2012%22%2C%20%22x%20%3E%3D%2012%22%5D%2C%20y%3Dchurn_by_tenure.values())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Finally%2C%20we'll%20check%20that%20as%20monthly%20charges%20increase%2C%20churn%20also%20increases.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(df_full)%3A%0A%20%20%20%20churn_by_monthly_charges%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22to_30%22%3A%20df_full%5Bdf_full.monthlycharges%20%3C%2030%5D.churn.mean()%2C%0A%20%20%20%20%20%20%20%20%22from_30_to_80%22%3A%20df_full%5B(df_full.monthlycharges%20%3E%3D%2030)%20%26%20(df_full.monthlycharges%20%3C%2080)%5D.churn.mean()%2C%0A%20%20%20%20%20%20%20%20%22from_80%22%3A%20df_full%5Bdf_full.monthlycharges%20%3E%3D%2080%5D.churn.mean()%2C%0A%20%20%20%20%7D%0A%0A%20%20%20%20churn_by_monthly_charges%0A%20%20%20%20return%20(churn_by_monthly_charges%2C)%0A%0A%0A%40app.cell%0Adef%20_(churn_by_monthly_charges%2C%20sns)%3A%0A%20%20%20%20sns.barplot(x%3D%5B%22x%20%3C%2030%22%2C%20%2230%20%3C%3D%20x%20%3C%2080%22%2C%20%22x%20%3E%3D%2080%22%5D%2C%20y%3Dchurn_by_monthly_charges.values())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20One-hot%20Encoding%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20sklearn.feature_extraction%20import%20DictVectorizer%0A%20%20%20%20return%20(DictVectorizer%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22First%20we%20define%20a%20dictionary%20vectorizer%20and%20fit%20it%20with%20our%20full%20train%20dataframe.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(DictVectorizer%2C%20categorical_columns%2C%20df_full%2C%20numerical_columns%2C%20pd)%3A%0A%20%20%20%20def%20get_trained_vectorizer(dataframe%3A%20pd.DataFrame)%20-%3E%20list%5Bdict%5D%3A%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Bnumerical_columns%20%2B%20categorical_columns%5D.to_dict(orient%3D%22records%22)%0A%0A%20%20%20%20%20%20%20%20dict_vectorizer%20%3D%20DictVectorizer(sparse%3DFalse)%0A%20%20%20%20%20%20%20%20dict_vectorizer.fit(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer%2C%20dictionary%0A%0A%20%20%20%20dict_vectorizer%2C%20dictionary%20%3D%20get_trained_vectorizer(df_full)%0A%20%20%20%20return%20dict_vectorizer%2C%20get_trained_vectorizer%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Now%2C%20let's%20test%20it%20with%20the%20first%20rows.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20df_full%2C%20dict_vectorizer)%3A%0A%20%20%20%20dict_vectorizer.transform(df_full%5Bcategorical_columns%5D.iloc%5B%3A3%5D.to_dict(orient%3D%22records%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Finally%2C%20let's%20check%20the%20list%20of%20columns%20for%20each%20of%20the%20generated%20features.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dict_vectorizer)%3A%0A%20%20%20%20list(dict_vectorizer.get_feature_names_out())%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Prepare%20our%20Feature%20Matrices%20and%20Target%20Vectors%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20DictVectorizer%2C%0A%20%20%20%20categorical_columns%2C%0A%20%20%20%20df_train%2C%0A%20%20%20%20df_val%2C%0A%20%20%20%20get_trained_vectorizer%2C%0A%20%20%20%20numerical_columns%2C%0A%20%20%20%20pd%2C%0A)%3A%0A%20%20%20%20def%20get_features_and_target(dataframe%3A%20pd.DataFrame%2C%20dict_vectorizer%3A%20DictVectorizer%2C%20dictionary)%3A%0A%20%20%20%20%20%20%20%20X%20%3D%20dict_vectorizer_train.transform(dictionary)%0A%20%20%20%20%20%20%20%20y%20%3D%20dataframe.churn%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%0A%20%20%20%20dict_vectorizer_train%2C%20dictionary_train%20%3D%20get_trained_vectorizer(df_train)%0A%20%20%20%20X_train%2C%20y_train%20%3D%20get_features_and_target(df_train%2C%20dict_vectorizer_train%2C%20dictionary_train)%0A%0A%20%20%20%20dictionary_val%20%3D%20df_val%5Bnumerical_columns%20%2B%20categorical_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20X_val%2C%20y_val%20%3D%20get_features_and_target(df_val%2C%20dict_vectorizer_train%2C%20dictionary_val)%0A%20%20%20%20return%20X_train%2C%20X_val%2C%20y_train%2C%20y_val%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Logistic%20Regression%0A%0A%20%20%20%20In%20logistic%20regresion%2C%20our%20target%20variable%20can%20only%20have%20two%20values%3A%0A%0A%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%5Cbold%20y_i%20%3D%20%5C%7B0%2C%201%5C%7D%0A%20%20%20%20%5C%5D%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Similarity%20with%20Linear%20Regression%0A%0A%20%20%20%20As%20a%20recall%2C%20in%20linear%20regression%20we%20used%20this%20formula%20for%20our%20estimator%20function%3A%0A%0A%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20g(%5Cbold%20x_i)%20%3D%20w_0%20%2B%20%5Cbold%20w%5ET%20%5Cbold%20x_i%0A%20%20%20%20%5C%5D%0A%0A%20%20%20%20Which%20was%20a%20function%20that%20had%20an%20image%20that%20could%20take%20any%20value%20between%20%24-%5Cinfty%24%20and%20%24%5Cinfty%24.%0A%0A%20%20%20%20In%20other%20words%2C%20%24g(%5Cbold%20x_i)%20%5Cin%20%5Cmathbb%7BR%7D%24.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Sigmoid%0A%0A%20%20%20%20The%20difference%20with%20linear%20regresion%20is%20that%20in%20the%20case%20of%20the%20logistic%20regression%2C%20we'll%20use%20a%20sigmoid%20function%20that%20will%20keep%20the%20values%20constrained%20between%20%240%24%20and%20%241%24%3A%0A%0A%20%20%20%20%5C%5B%0A%20%20%20%20%20%20%20%20g(%5Cbold%20x_i)%20%3D%20sigmoid(w_0%20%2B%20%5Cbold%20w%5ET%20%5Cbold%20x_i)%0A%20%20%20%20%5C%5D%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20sns)%3A%0A%20%20%20%20def%20sigmoid(z)%3A%0A%20%20%20%20%20%20%20%20return%201%20%2F%20(1%20%2B%20np.exp(-z))%0A%0A%20%20%20%20def%20plot_sigmoid()%3A%0A%20%20%20%20%20%20%20%20z%20%3D%20np.linspace(-15%2C%2015%2C%20500)%0A%20%20%20%20%20%20%20%20y%20%3D%20sigmoid(z)%0A%0A%20%20%20%20%20%20%20%20return%20sns.lineplot(x%3Dz%2C%20y%3Dy)%0A%0A%20%20%20%20plot_sigmoid()%0A%20%20%20%20return%20(sigmoid%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22As%20a%20quick%20recall%20of%20previous%20chapters%2C%20this%20is%20how%20linear%20regression%20looks%20like%3A%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.function%0Adef%20linear_regression(xi%2C%20w0%2C%20wi)%3A%0A%20%20%20%20result%20%3D%20w0%0A%0A%20%20%20%20for%20x%2C%20w%20in%20zip(xi%2C%20wi)%3A%0A%20%20%20%20%20%20%20%20result%20%2B%3D%20x%20*%20w%0A%0A%20%20%20%20return%20result%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22With%20that%20in%20mind%2C%20it's%20quite%20easy%20to%20implement%20the%20logistic%20regression.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(sigmoid)%3A%0A%20%20%20%20def%20logistic_regression(xi%2C%20w0%2C%20wi)%3A%0A%20%20%20%20%20%20%20%20z%20%3D%20linear_regression(xi%2C%20w0%2C%20wi)%0A%0A%20%20%20%20%20%20%20%20return%20sigmoid(z)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Training%20Logistic%20Regression%20with%20Scikit-Learn%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_train%2C%20y_train)%3A%0A%20%20%20%20from%20sklearn.linear_model%20import%20LogisticRegression%0A%0A%20%20%20%20model%20%3D%20LogisticRegression(max_iter%3D5000)%0A%20%20%20%20model.fit(X_train%2C%20y_train)%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22coefficients%22%3A%20model.coef_%5B0%5D.round(3)%2C%0A%20%20%20%20%20%20%20%20%22bias%22%3A%20model.intercept_%5B0%5D.round(3)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20LogisticRegression%2C%20model%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Use%20the%20Model%0A%0A%20%20%20%20First%2C%20we'll%20use%20the%20model%20to%20create%20some%20**hard%20predictions**%20for%20us.%20In%20other%20words%2C%20we'll%20force%20the%20model%20to%20generate%20booleans%20for%20us.%20We'll%20also%20take%20a%20look%20at%20the%20corresponding%20estimated%20**probabilities**%20and%20we'll%20compare%20all%20that%20with%20the%20real%20values.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_val%2C%20model%2C%20y_val)%3A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22hard_predictions%22%3A%20model.predict(X_val%5B0%3A5%5D).astype(bool)%2C%0A%20%20%20%20%20%20%20%20%22probabilities%22%3A%20model.predict_proba(X_val%5B0%3A5%5D)%5B%3A%2C1%5D.round(3)%2C%0A%20%20%20%20%20%20%20%20%22references%22%3A%20y_val%5B0%3A5%5D.values.astype(bool)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22By%20setting%20a%20manual%20**cut**%20point%20we%20can%20obtain%20a%20different%20set%20of%20predictions.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_val%2C%20model)%3A%0A%20%20%20%20cut%20%3D%200.5%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22soft_predictions%22%3A%20model.predict_proba(X_val%5B0%3A5%5D)%5B%3A%2C1%5D%20%3E%20cut%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(cut%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Finally%2C%20let's%20do%20a%20quick%20evaluation%20of%20our%20model.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_val%2C%20cut%2C%20model%2C%20y_val)%3A%0A%20%20%20%20predicted_churn%20%3D%20model.predict_proba(X_val)%5B%3A%2C1%5D%20%3E%20cut%0A%0A%20%20%20%20(predicted_churn%20%3D%3D%20y_val).mean().round(3)%0A%20%20%20%20return%20(predicted_churn%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Inspect%20the%20Correct%20and%20Wrong%20Predictions%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_val%2C%20model%2C%20pd%2C%20predicted_churn%2C%20y_val)%3A%0A%20%20%20%20def%20inspect_predictions()%3A%0A%20%20%20%20%20%20%20%20dataframe%20%3D%20pd.DataFrame()%0A%20%20%20%20%20%20%20%20dataframe%5B%22probability%22%5D%20%3D%20model.predict_proba(X_val)%5B%3A%2C1%5D.round(2)%0A%20%20%20%20%20%20%20%20dataframe%5B%22prediction%22%5D%20%3D%20predicted_churn.astype(int)%0A%20%20%20%20%20%20%20%20dataframe%5B%22reference%22%5D%20%3D%20y_val.astype(int)%0A%20%20%20%20%20%20%20%20dataframe%5B%22correct%22%5D%20%3D%20dataframe%5B%22prediction%22%5D%20%3D%3D%20dataframe%5B%22reference%22%5D%0A%0A%20%20%20%20%20%20%20%20return%20dataframe%0A%0A%20%20%20%20inspect_predictions()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Model%20Interpretation%0A%0A%20%20%20%20Our%20model%20has%20too%20many%20coefficients%20to%20study%20them%20one%20by%20one.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dict_vectorizer%2C%20model)%3A%0A%20%20%20%20list(zip(dict_vectorizer.get_feature_names_out()%2C%20model.coef_%5B0%5D.round(3)))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22So%20we'll%20create%20a%20small%20version%20of%20it.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(DictVectorizer%2C%20df_train%2C%20pd)%3A%0A%20%20%20%20small_feature_set%20%3D%20%5B%22contract%22%2C%20%22monthlycharges%22%2C%20%22tenure%22%5D%0A%0A%20%20%20%20def%20get_small_trained_vectorizer(dataframe%3A%20pd.DataFrame)%20-%3E%20list%5Bdict%5D%3A%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Bsmall_feature_set%5D.to_dict(orient%3D%22records%22)%0A%0A%20%20%20%20%20%20%20%20dict_vectorizer%20%3D%20DictVectorizer(sparse%3DFalse)%0A%20%20%20%20%20%20%20%20dict_vectorizer.fit(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer%2C%20dictionary%0A%0A%20%20%20%20def%20get_small_dataset()%3A%0A%20%20%20%20%20%20%20%20return%20df_train%5Bsmall_feature_set%20%2B%20%5B%22churn%22%5D%5D%0A%0A%20%20%20%20def%20get_small_features_and_target(dataframe%3A%20pd.DataFrame%2C%20dict_vectorizer%3A%20DictVectorizer%2C%20dictionary)%3A%0A%20%20%20%20%20%20%20%20X%20%3D%20dict_vectorizer.transform(dictionary)%0A%20%20%20%20%20%20%20%20y%20%3D%20dataframe.churn%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%0A%20%20%20%20df_small%20%3D%20get_small_dataset()%0A%20%20%20%20dict_vectorizer_small%2C%20dictionary_small%20%3D%20get_small_trained_vectorizer(df_small)%0A%20%20%20%20X_small%2C%20y_small%20%3D%20get_small_features_and_target(df_small%2C%20dict_vectorizer_small%2C%20dictionary_small)%0A%20%20%20%20return%20X_small%2C%20dict_vectorizer_small%2C%20y_small%0A%0A%0A%40app.cell%0Adef%20_(LogisticRegression%2C%20X_small%2C%20dict_vectorizer_small%2C%20y_small)%3A%0A%20%20%20%20model_small%20%3D%20LogisticRegression(max_iter%3D5000)%0A%20%20%20%20model_small.fit(X_small%2C%20y_small)%0A%0A%20%20%20%20coefficients%20%3D%20dict(zip(dict_vectorizer_small.get_feature_names_out()%2C%20model_small.coef_%5B0%5D.round(3)))%0A%20%20%20%20coefficients%0A%20%20%20%20return%20coefficients%2C%20model_small%0A%0A%0A%40app.cell%0Adef%20_(model_small)%3A%0A%20%20%20%20bias_small%20%3D%20model_small.intercept_%5B0%5D.round(3)%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22bias%22%3A%20bias_small%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20(bias_small%2C)%0A%0A%0A%40app.cell%0Adef%20_(X_small%2C%20bias_small%2C%20coefficients%2C%20sigmoid)%3A%0A%20%20%20%20def%20evaluate_row(row_number%3A%20int)%3A%0A%20%20%20%20%20%20%20%20x%20%3D%20X_small%5Brow_number%5D%0A%0A%20%20%20%20%20%20%20%20return%20sigmoid(%0A%20%20%20%20%20%20%20%20%20%20%20%20bias_small%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%5B%22contract%3Dmonth-to-month%22%5D%20*%20x%5B0%5D%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%5B%22contract%3Done_year%22%5D%20*%20x%5B1%5D%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%5B%22contract%3Dtwo_year%22%5D%20*%20x%5B2%5D%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%5B%22monthlycharges%22%5D%20*%20x%5B3%5D%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20coefficients%5B%22tenure%22%5D%20*%20x%5B4%5D%0A%20%20%20%20%20%20%20%20).round(2)%0A%0A%20%20%20%20%5Bevaluate_row(row_number)%20for%20row_number%20in%20range(10)%5D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Using%20the%20Model%0A%0A%20%20%20%20%23%23%23%20Train%20a%20Model%20on%20the%20Full%20Dataset%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(DictVectorizer%2C%20df_full%2C%20pd)%3A%0A%20%20%20%20def%20get_full_trained_vectorizer(dataframe%3A%20pd.DataFrame)%20-%3E%20list%5Bdict%5D%3A%0A%20%20%20%20%20%20%20%20copy%20%3D%20dataframe.copy()%0A%20%20%20%20%20%20%20%20del%20copy%5B%22churn%22%5D%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20copy.to_dict(orient%3D%22records%22)%0A%0A%20%20%20%20%20%20%20%20dict_vectorizer%20%3D%20DictVectorizer(sparse%3DFalse)%0A%20%20%20%20%20%20%20%20dict_vectorizer.fit(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer%2C%20dictionary%0A%0A%20%20%20%20def%20get_full_features_and_target(dataframe%3A%20pd.DataFrame%2C%20dict_vectorizer%3A%20DictVectorizer%2C%20dictionary)%3A%0A%20%20%20%20%20%20%20%20X%20%3D%20dict_vectorizer.transform(dictionary)%0A%20%20%20%20%20%20%20%20y%20%3D%20dataframe.churn%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%0A%20%20%20%20dict_vectorizer_full%2C%20dictionary_full%20%3D%20get_full_trained_vectorizer(df_full)%0A%20%20%20%20X_full%2C%20y_full%20%3D%20get_full_features_and_target(df_full%2C%20dict_vectorizer_full%2C%20dictionary_full)%0A%20%20%20%20return%20X_full%2C%20dict_vectorizer_full%2C%20get_full_features_and_target%2C%20y_full%0A%0A%0A%40app.cell%0Adef%20_(LogisticRegression%2C%20X_full%2C%20y_full)%3A%0A%20%20%20%20model_full%20%3D%20LogisticRegression(max_iter%3D5000)%0A%20%20%20%20model_full.fit(X_full%2C%20y_full)%0A%20%20%20%20return%20(model_full%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Evaluate%20the%20Model%20on%20the%20Test%20Dataset%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20categorical_columns%2C%0A%20%20%20%20df_test%2C%0A%20%20%20%20dict_vectorizer_full%2C%0A%20%20%20%20get_full_features_and_target%2C%0A%20%20%20%20numerical_columns%2C%0A)%3A%0A%20%20%20%20dictionary_test%20%3D%20df_test%5Bnumerical_columns%20%2B%20categorical_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20X_test%2C%20y_test%20%3D%20get_full_features_and_target(df_test%2C%20dict_vectorizer_full%2C%20dictionary_test)%0A%0A%20%20%20%20y_test%5By_test.values%20%3D%3D%201%5D.sum()%20%2F%20y_test.count()%0A%20%20%20%20return%20X_test%2C%20dictionary_test%2C%20y_test%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20model_full%2C%20pd)%3A%0A%20%20%20%20def%20predict_full(X)%3A%0A%20%20%20%20%20%20%20%20predictions%20%3D%20pd.DataFrame()%0A%20%20%20%20%20%20%20%20predictions%5B%22probability%22%5D%20%3D%20model_full.predict_proba(X)%5B%3A%2C%201%5D%0A%20%20%20%20%20%20%20%20predictions%5B%22prediction%22%5D%20%3D%20predictions%5B%22probability%22%5D%20%3E%200.5%0A%0A%20%20%20%20%20%20%20%20return%20predictions%0A%0A%20%20%20%20y_pred%20%3D%20predict_full(X_test)%0A%20%20%20%20y_pred%0A%20%20%20%20return%20predict_full%2C%20y_pred%0A%0A%0A%40app.cell%0Adef%20_(y_pred)%3A%0A%20%20%20%20(y_pred.prediction%20%3D%3D%20True).sum()%20%2F%20len(y_pred)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(X_test%2C%20predict_full%2C%20y_test)%3A%0A%20%20%20%20def%20evaluate_full(X%2C%20y)%3A%0A%20%20%20%20%20%20%20%20y_pred%20%3D%20predict_full(X)%0A%0A%20%20%20%20%20%20%20%20return%20(y%20%3D%3D%20y_pred.prediction).mean()%0A%0A%20%20%20%20evaluate_full(X_test%2C%20y_test)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Use%20the%20Model%20with%20Data%20from%20some%20Random%20Customer%20Records%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dictionary_test)%3A%0A%20%20%20%20from%20random%20import%20randrange%0A%0A%20%20%20%20def%20get_random_customer_ids(n)%3A%0A%20%20%20%20%20%20%20%20test_records%20%3D%20len(dictionary_test)%0A%0A%20%20%20%20%20%20%20%20return%20%5Brandrange(1%2C%20test_records)%20for%20_%20in%20range(n)%5D%0A%0A%20%20%20%20get_random_customer_ids(10)%0A%20%20%20%20return%20(get_random_customer_ids%2C)%0A%0A%0A%40app.cell%0Adef%20_(dict_vectorizer_full%2C%20dictionary_test%2C%20get_random_customer_ids%2C%20np)%3A%0A%20%20%20%20def%20get_random_customers(n)%3A%0A%20%20%20%20%20%20%20%20random_customer_ids%20%3D%20get_random_customer_ids(n)%0A%20%20%20%20%20%20%20%20dictionary_items%20%3D%20np.array(dictionary_test)%5Brandom_customer_ids%5D%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer_full.transform(dictionary_items)%0A%0A%20%20%20%20X_random_test%20%3D%20get_random_customers(10)%0A%20%20%20%20X_random_test%0A%20%20%20%20return%20(X_random_test%2C)%0A%0A%0A%40app.cell%0Adef%20_(X_random_test%2C%20predict_full)%3A%0A%20%20%20%20predict_full(X_random_test)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
edbf49d49430725cf578e603b5d3cd3a2225468c57a1258682e5034ba15d9579