[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-118036-en":3,"doc-seo-118036-105":30,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":4,"is_deleted":4,"is_public":20,"is_downloadable":20,"audit_status":20,"page_count":21,"language":22,"language_code":23,"site_id":24,"html_lang":23,"table_of_contents":25,"faqs":26,"seo_title":27,"seo_description":14,"update_tm":28,"read_time":29},118036,549758252649,"Ivy","https://ap-avatar.wpscdn.com/avatar/8000253669c5317157?_k=1778319167496531819",6,"Technology","Machine learning using Stata/Python - Hyperparameter tuning via K-fold cross-validation","The paper introduces two Stata/Python commands, r_ml_stata_cv and c_ml_stata_cv, designed to fit widely used machine learning models in both regression and classification settings. Built on the Stata 16 Stata/Python integration API, the commands use the Python Scikit-learn interface to run K-fold cross-validation and perform outcome or label prediction. Hyperparameters are optimally tuned through grid search over user-relevant parameters, improving the bias–variance trade-off while returning standardized Stata results and generated variables for downstream workflows.","The World's Largest Open Access Agricultural &Applied Economics Digital Library  \nThis document is discoverable and free to researchers across theglobe due to the work of AgEcon Search.  \nHelp ensure our sustainability.  \nGive to AgEcon Search  \nAgEcon Searchhttp://ageconsearch.umn.eduaesearch@umn.edu  \nPapers downloaded from AgEcon Search may be used for non-commercial purposes and personal study only.No other use,including posting to another Internet site,is permitted without permission from the copyrightowner(not AgEcon Search),or as allowed under the provisions of Fair Use,U.S.Copyright Act,Title 17U.S.C.  \nNo endorsement of AgEcon Search or its fundraising activities by the author(s)of the following work or theiremployer(s)is intended orimplied.  \nMachine learning using Stata/Python  \nGiovanni Cerulli  \nIRCrES-CNRRome,Italygiovanni.cerulli@ircres.cnr.it  \nAbstract.I present two related commands,r_ml_stata_cv and c_ml_stata_cv,for fitting popular machine learning methods in both a regression and a classi-fication setting.Using the recent Stata/Python integration platform introducedin Stata 16,these commands provide hyperparameters'optimal tuning via K-foldcross-validation using grid search.More specifically,they use the Python Scikit-learn application programming interface to carry out both cross-validation andoutcome/label prediction.  \nKeywords:pr0076,r_ml_stata_cv,c_ml_stata_cv,get_test_train,machinelearning,Python,optimal tuning  \n# 1 Introduction\n\nMachine learning(ML)(also known as statistical learning¹)has emerged as a leadingdata-science approach in many fields,including business,engineering,medicine,adver-tising,and scientific research.Placing itself in the intersection of statistics,computerscience,and artificial intelligence,ML's main objective is turning information into valu-able knowledge by\"letting the data speak”,limiting the model's prior assumptions,and promoting a model-free philosophy.Relying on algorithms and computational tech-niques,more than on analytic solutions,ML targets big data and complexity reduction,although sometimes at the expense of results'interpretability(Hastie,Tibshirani,andFriedman 2009;Varian 2014).  \nUnlike other software,such as R,Python,MATLAB,and SAS,Stata does not havededicated built-in packages for fitting ML algorithms,if one excludes the Lasso packageof Stata 16.Recently,however,the Stata community has developed some popularML routines that Stata users can suitably exploit.Among them,I mention Schonlau(2005)implementing a boosting Stata plugin;Guenther and Schonlau(2016)providing  \nG.Cerulli  \na command fitting support vector machines(SVM);Ahrens,Hansen,and Schaffer(2020)setting out the lassopack,a set of commands for model selection and prediction withregularized regression;and Schonlau and Zou(2020)providing a command for therandom forests algorithm.All of these are valuable packages for executing popular MLalgorithms within Stata.  \nThe absence of an integrated Stata package for carrying out ML algorithms also pre-vents uniformity and comparability of these methods.To pursue generality,uniformity,and comparability,one should rely on a software platform able to suitably integratemost of the mainstream ML methods.For example,Python has powerful platforms tocarry out both ML and deep-learning algorithms(Raschka and Mirjalili 2019).Amongthem,the most popular are Scikit-learn for fitting many ML methods,and TensorFlowand Keras for more generally fitting neural network and deep-learning techniques.Thesemake Python,which is freeware,probably the most effective and complete software forML and deep-learning available within the community.  \nThe Stata 16 release introduced a useful Stata/Python application programminginterface(API).The Stata Function Interface(sfi)module allows users to interactPython's capabilities with core features of Stata.The command can be used interac-tively or in do-files and ado-files.  \nTaking advantage of the new Stata/Python integration interface,Droste(","cbCaipYuyS6wYfMa","https://ap.wps.com/l/cbCaipYuyS6wYfMa","pdf",14023261,1,40,"English","en",105,"# 1 Introduction\n## Machine learning background and software gap\n## Stata/Python integration and related tools\n## Proposed commands and their advantages","[{\"question\":\"What do r_ml_stata_cv and c_ml_stata_cv do?\",\"answer\":\"They fit popular machine learning methods in regression and classification settings, respectively. Both commands also generate outcomes/labels and support hyperparameter tuning through cross-validation.\"},{\"question\":\"How is hyperparameter tuning implemented in these commands?\",\"answer\":\"They use K-fold cross-validation combined with grid search to tune hyperparameters. The grid can be customized to cover parameters relevant to the prediction bias–variance trade-off.\"},{\"question\":\"Why are these commands useful for Stata users?\",\"answer\":\"They let Stata users apply machine learning without investing time in learning other software. They also provide standard Stata returns and generated variables that integrate smoothly into existing do-files.\"}]","Machine learning using Stata/Python - Hyperparameter tuning via K-fold cross-validation | PDF",1785680930,101,{"code":4,"msg":31,"data":32},"ok",{"site_id":24,"language":23,"slug":33,"title":13,"keywords":34,"description":14,"schema_data":35,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":28},"machine-learning-using-statapython-hyperparameter-tuning-via-k-fold-cross-validation","",{"@graph":36,"@context":85},[37,54,68],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,48,51],{"item":41,"name":42,"@type":43,"position":20},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":47},"https://docshare.wps.com/document/","Document",2,{"item":49,"name":12,"@type":43,"position":50},"https://docshare.wps.com/document/technology/",3,{"item":52,"name":13,"@type":43,"position":53},"https://docshare.wps.com/document/machine-learning-using-statapython-hyperparameter-tuning-via-k-fold-cross-validation/118036/",4,{"url":52,"name":13,"@type":55,"author":56,"headline":13,"publisher":58,"fileFormat":61,"inLanguage":23,"description":14,"dateModified":62,"datePublished":62,"encodingFormat":61,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":57},"Person",{"url":41,"name":59,"@type":60},"DocShare","Organization","application/pdf","2026-08-02",true,{"@type":65,"interactionType":66,"userInteractionCount":4},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What do r_ml_stata_cv and c_ml_stata_cv do?","Question",{"text":75,"@type":76},"They fit popular machine learning methods in regression and classification settings, respectively. Both commands also generate outcomes/labels and support hyperparameter tuning through cross-validation.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How is hyperparameter tuning implemented in these commands?",{"text":80,"@type":76},"They use K-fold cross-validation combined with grid search to tune hyperparameters. The grid can be customized to cover parameters relevant to the prediction bias–variance trade-off.",{"name":82,"@type":73,"acceptedAnswer":83},"Why are these commands useful for Stata users?",{"text":84,"@type":76},"They let Stata users apply machine learning without investing time in learning other software. They also provide standard Stata returns and generated variables that integrate smoothly into existing do-files.","https://schema.org",{"og:url":52,"og:type":87,"og:title":13,"og:site_name":59,"og:description":14},"article",{"robots":89,"canonical":52},"index,follow",{"doc_id":7,"site_id":24},{"code":4,"msg":5,"data":92},[93,97,101,105,110,113,117,122,127,130,134],{"id":20,"doc_module":4,"doc_module_name":46,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":47,"doc_module":4,"doc_module_name":46,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":53,"doc_module":4,"doc_module_name":46,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":46,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":11,"doc_module":4,"doc_module_name":46,"category_name":12,"show_sort_weight":111,"slug":112},50,"technology",{"id":114,"doc_module":4,"doc_module_name":46,"category_name":115,"show_sort_weight":21,"slug":116},7,"Healthcare","healthcare",{"id":118,"doc_module":4,"doc_module_name":46,"category_name":119,"show_sort_weight":120,"slug":121},8,"Research & Report",30,"research-report",{"id":123,"doc_module":4,"doc_module_name":46,"category_name":124,"show_sort_weight":125,"slug":126},9,"Religion & Spirituality",20,"religion-spirituality",{"id":125,"doc_module":4,"doc_module_name":46,"category_name":128,"show_sort_weight":125,"slug":129},"World Cup","world-cup",{"id":131,"doc_module":4,"doc_module_name":46,"category_name":132,"show_sort_weight":131,"slug":133},10,"Lifestyle","lifestyle",{"id":135,"doc_module":4,"doc_module_name":46,"category_name":136,"show_sort_weight":106,"slug":137},19,"General","general"]