{"id":16840,"date":"2021-09-23T18:15:30","date_gmt":"2021-09-23T12:45:30","guid":{"rendered":"http:\/\/ismiletechnologies.com\/?p=16840"},"modified":"2021-10-26T21:29:42","modified_gmt":"2021-10-26T15:59:42","slug":"automating-machine-learning-workflows-with-sklearn-pandas","status":"publish","type":"post","link":"https:\/\/ismiletechnologies.com\/en_us\/machine-learning\/automating-machine-learning-workflows-with-sklearn-pandas\/","title":{"rendered":"Automating Machine Learning workflows with SkLearn-Pandas"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u202f<\/strong><strong>Automating Machine Learning workflows with&nbsp;SkLearn-Pandas.<\/strong>&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Machine learning workflows include all the steps required to build machine learning models from raw data. These processes can be divided into the transformation and the training stages.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The transformation stage&nbsp;include&nbsp;the processes required to transform the raw data to features (feature engineering) while the training stage encapsulate the processes of using the features to build machine learning models.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The messiness of actual-world data typically makes feature engineering the most challenging and&nbsp;critical step in Machine Learning, especially when working with huge volumes of data streams from diverse sources. Feature engineering processes in such cases may include multiple, repetitive and distinct steps of mapping diverse raw data to machine learning features. An efficient way of dealing with such tasks is the use of feature pipelines.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feature pipelines are frameworks that are utilized to automate the application of multiple, repetitive, and distinct feature engineering processes to raw data, sequentially and continuously.\u202f&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When feature pipelines are designed, they can then be merged with machine learning algorithms to create Machine Learning pipelines which automates the machine learning workflows; from transforming the data to building estimators.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We would be using a simple dataset for an introductory example before having a more detailed example using the Titanic Dataset to practicalize how pipelines are utilized to efficiently and easily use raw data to build estimators.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will be using&nbsp;an&nbsp;hypothetical \u201c<a href=\"https:\/\/github.com\/Chiebukar\/dataset%22%20\/t%20%22_blank\" target=\"_blank\" rel=\"noreferrer noopener\">income<\/a>\u201d&nbsp;dataset&nbsp;that contains the ages, job titles, highest educational qualification and annual income of employees to demonstrate how pipelines are utilized to efficiently and easily transform raw data to build estimators. Our aim is to design and execute a machine learning pipeline to automate the data transformation and building processes using the&nbsp;SkLearn-Pandas&nbsp;library.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, let\u2019s take a look at the dataset.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"885\" height=\"176\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-115.png\" alt=\"Automating Machine Learning workflows with SkLearn-Pandas\" class=\"wp-image-16849\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-115.png 885w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-115-300x60.png 300w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-115-768x153.png 768w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"515\" height=\"495\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-116.png\" alt=\"Automating Machine Learning workflows with SkLearn-Pandas\" class=\"wp-image-16850\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-116.png 515w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-116-300x288.png 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Table 1.&nbsp;Sample data of ages,&nbsp;job_title&nbsp;and qualification of employees.\u202f&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We will need to apply certain transformations to this data before feeding it to an algorithm for training. The table below describes the required processes to build a model with this data.&nbsp;&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-117.png\" alt=\"Automating Machine Learning workflows with SkLearn-Pandas\" class=\"wp-image-16851\" width=\"574\" height=\"277\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-117.png 863w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-117-300x145.png 300w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-117-768x372.png 768w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Table&nbsp;2.&nbsp;showing transformations to be applied to the data.\u202f&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next,&nbsp;We&nbsp;will define a machine learning pipeline to automate the application of these processes to the data. We will do this using&nbsp;<a href=\"https:\/\/pypi.org\/project\/sklearn-pandas\/1.5.0\/%22%20\/t%20%22_blank\" target=\"_blank\" rel=\"noreferrer noopener\">SkLearn-Pandas\u2019<\/a>&nbsp;<a href=\"https:\/\/dunyaoguz.github.io\/my-blog\/dataframemapper.html%22%20\/t%20%22_blank\" target=\"_blank\" rel=\"noreferrer noopener\">DataFrameMapper<\/a>&nbsp;and&nbsp;Sklearn\u2019s&nbsp;preprocessing methods.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"533\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-120.png\" alt=\"Automating Machine Learning workflows with SkLearn-Pandas\" class=\"wp-image-16854\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-120.png 883w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-120-300x181.png 300w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-120-768x464.png 768w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The defined pipeline can then be utilized to train the algorithm using the feature and target variables.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"213\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-119.png\" alt=\"Automating Machine Learning workflows with SkLearn-Pandas\" class=\"wp-image-16853\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-119.png 902w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-119-300x71.png 300w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-119-768x181.png 768w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"33\" src=\"http:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-118.png\" alt=\"\" class=\"wp-image-16852\" srcset=\"https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-118.png 385w, https:\/\/ismiletechnologies.com\/wp-content\/uploads\/2021\/09\/image-118-300x26.png 300w\" sizes=\"(max-width: 385px) 100vw, 385px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We have successfully developed a pipeline to automate the machine learning workflow such that it can also be used to transform other data streams with similar structures. You could also pass the pipeline to&nbsp;RandomSearchCV&nbsp;or&nbsp;GridSearchCV&nbsp;for hyperparameter tuning.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Summary<\/strong>:&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Machine Learning pipelines are useful for automating the iterative processes of data transformation and building estimators. The pipelines offer efficient methods to automatically apply specific or diverse transformations to particular or numerous input features. Python libraries such as&nbsp;Sklearn&nbsp;and&nbsp;SkLearn-Pandas provide convenient methods to define and execute Machine Learning pipelines.\u202f&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>By Samuel&nbsp;Ozechi&nbsp;<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u202fAutomating Machine Learning workflows with&nbsp;SkLearn-Pandas.&nbsp; Machine learning workflows include all the steps required to build machine learning models from raw data. These processes can be divided into the transformation and the training stages.&nbsp; The transformation stage&nbsp;include&nbsp;the processes required to transform the raw data to features (feature engineering) while the training stage encapsulate the processes of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":16910,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-16840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning"],"_links":{"self":[{"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/posts\/16840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/comments?post=16840"}],"version-history":[{"count":4,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/posts\/16840\/revisions"}],"predecessor-version":[{"id":19885,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/posts\/16840\/revisions\/19885"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/media\/16910"}],"wp:attachment":[{"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/media?parent=16840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/categories?post=16840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ismiletechnologies.com\/en_us\/wp-json\/wp\/v2\/tags?post=16840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}