{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ransaka Ravihara",
  "title_listed": "Machine Learning on Snowflake",
  "keywords": "Snowflake,Snowpark,ML",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/machine-learning-on-snowflake-ea6c559af2d/",
  "publish_date": "2022-12",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "63c7f9f88b5a",
  "collected_at": "2026-10-01T23:34:52",
  "title": "Machine Learning on Snowflake | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Machine Learning on Snowflake\nsnowflake is one of the leading data platforms out there. In this article, we will explore the capabilities of its' snowpark python...\n[Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\nDecember 26, 20229 min read\n# How to Build Machine Learning Models on Snowflake\n### Snowflake is one of the leading data platforms out there. In this article, we will explore the capabilities of its' snowpark Python library\n![Photo by Aaron Burden on Unsplash](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/0ceNRNk7_QSHaS2ol-scaled.jpg)\nPhoto by [Aaron Burden](https://unsplash.com/@aaronburden?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)\nThroughout this article, you will learn how to use,\n  1. snowpark-python functionalities for primary data preprocessing\n  2. Train and deploy machine learning models in Snowflake\n  3. Define UDFs in a pythonic way and deploy them in snowflake\n\n\n![Topics covered in this article | Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1zOTKNeFOfEDF48XAIwR4YA.png)\nTopics covered in this article | Image by author\nIf you are willing to follow along with the tutorial, you should have an [Anaconda integration-enabled snowflake account](https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages.html#using-third-party-packages-from-anaconda). Otherwise, you must sign up for a free [snowflake trial account](https://signup.snowflake.com/) and configure it as described [here](https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages.html#using-third-party-packages-from-anaconda).\nAt first glance, snowpark is a machine learning and data science framework that offers the power of SQL within Python flexibility. Sometimes, this is similar to the Apache spark framework. However, this provides a pervasive framework for our machine learning and data science projects. Before trying anything in this article, you should establish a connection between python and Snowflake. You can refer to [my code repo](https://github.com/Ransaka/ML-on-Snowflake) for code samples. Let's create a database connection.\npython\n\n```\nfrom snowflake.snowpark.session import Session\n\naccountname = \"********\" # your accountname\nusername = \"**********\" #your snowflake username\npassword = \"*************\" #snowflake password\n\nconnection_parameters = {\n    \"account\": accountname,\n    \"user\": username,\n    \"password\": password,\n    \"role\": \"ACCOUNTADMIN\"\n}\n\ndef snowflake_connector():\n    try:\n        session = Session.builder.configs(connection_parameters).create()\n        print(\"connection successful!\")\n    except:\n        raise ValueError(\"error while connecting with db\")\n    return session\n\n#define a session\nsession = snowflake_connector()\n```\n\nNow we can start the primary data preprocessing part. Instead of preprocessing with Pandas DataFrame, I will do this with the snowpark side. Here I'm going to use the [COVID-19](https://www.kaggle.com/datasets/meirnizri/covid19-dataset) Dataset, which is available in the Kaggle under [CC0: Public Domain](https://creativecommons.org/publicdomain/zero/1.0/). I have already loaded this Dataset as a Snowflake table. Since it's not the primary goal of this article, I'm skipping that part. You can load the Dataset as described in this [article's GitHub repo](https://github.com/Ransaka/ML-on-Snowflake). Let's read the table.\npython\n\n```\nsnowpark_df = session.table(\"COVID19_RECORDS\")\n\nprint(type(snowpark_df) # snowflake.snowpark.table.Table\nprint(f\"Size of the table object: {(sys.getsizeof(snowpark_df)/1e6)} MB\")\n#'Size of the table object: 4.8e-05 MB'\n```\n\nAbove `snowpark_df` is a lazily-evaluated table; hence It won't consume much memory like pandas data frames. But we can apply any transformations aggregations and much more as we did with pandas.\npython\n\n```\nsnowpark_df.schema.fields\n\n# [StructField('USMER', LongType(), nullable=True),\n#  StructField('MEDICAL_UNIT', LongType(), nullable=True),\n#  StructField('SEX', LongType(), nullable=True),\n#  StructField('PATIENT_TYPE', LongType(), nullable=True),\n#  StructField('DATE_DIED', StringType(), nullable=True),\n#  StructField('INTUBED', LongType(), nullable=True),\n#  StructField('PNEUMONIA', LongType(), nullable=True),\n#  StructField('AGE', LongType(), nullable=True),\n#  StructField('PREGNANT', LongType(), nullable=True),\n#  StructField('DIABETES', LongType(), nullable=True),\n#  StructField('COPD', LongType(), nullable=True),\n#  StructField('ASTHMA', LongType(), nullable=True),\n#  StructField('INMSUPR', LongType(), nullable=True),\n#  StructField('HIPERTENSION', LongType(), nullable=True),\n#  StructField('OTHER_DISEASE', LongType(), nullable=True),\n#  StructField('CARDIOVASCULAR', LongType(), nullable=True),\n#  StructField('OBESITY', LongType(), nullable=True),\n#  StructField('RENAL_CHRONIC', LongType(), nullable=True),\n#  StructField('TOBACCO', LongType(), nullable=True),\n#  StructField('CLASIFFICATION_FINAL', LongType(), nullable=True),\n#  StructField('ICU', LongType(), nullable=True)]\n```\n\nThere are 1,048,575 unique records and 21 columns in the Dataset. Let's do some fundamental analysis. First, let's define the target variable as follow. As per the description of the Dataset, the 1,2, and 3 values in `CLASSIFICATION_FINAL` the column represent the positive cases, and the rest represent the negative cases. Let's define a new column called `TARGET` by applying the above logic. The equivalent SQL logic will be,\nsql\n\n```\nSELECT\n    \"USMER\",\n    \"MEDICAL_UNIT\",\n    \"SEX\",\n    \"PATIENT_TYPE\",\n    \"DATE_DIED\",\n    \"INTUBED\",\n    \"PNEUMONIA\",\n    \"AGE\",\n    \"PREGNANT\",\n    \"DIABETES\",\n    \"COPD\",\n    \"ASTHMA\",\n    \"INMSUPR\",\n    \"HIPERTENSION\",\n    \"OTHER_DISEASE\",\n    \"CARDIOVASCULAR\",\n    \"OBESITY\",\n    \"RENAL_CHRONIC\",\n    \"TOBACCO\",\n    \"CLASIFFICATION_FINAL\",\n    \"ICU\",\n    CASE\n        WHEN (\"CLASIFFICATION_FINAL\" < 4 :: INT) THEN 1 :: INT\n        ELSE 0 :: INT\n    END AS \"TARGET\"\nFROM\n    COVID19_RECORDS\n```\n\nSince we are working with snowpark API, let's create this with snowpark.\npython\n\n```\nimport snowflake.snowpark.functions as F\n\nsnowpark_df.with_column('TARGET', F.when(F.col('CLASIFFICATION_FINAL')\n                        < 4, 1).otherwise(0))\n```\n\nLet's see our target distribution.\nscss\n\n```\nsnowpark_df\n.group_by(\"TARGET\").count().to_pandas().set_index(\"TARGET\")\n.plot.bar()\n\nplt.title(\"Target distribution\",fontweight='semibold')\nplt.show()\n```\n\n![Target Distribution | Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1soGMsladnT8HxaSLFCgIrA.png)\nTarget Distribution | Image by author\nLet's create one more plot.\nscss\n\n```\nsnowpark_df\n.select('AGE').to_pandas()\n.plot.hist(bins=100,alpha=0.5)\n\nplt.title(\"Age distribution\",fontweight='semibold')\nplt.show()\n```\n\n![Age Distribution | Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1zEq0762fLVascp54cE0rmg.png)\nAge Distribution | Image by author\nLet's find the relationship between the Age variable and the target variable.\npython\n\n```\nsnowpark_df = snowpark_df.with_column(\n    \"AGE_BKT\",\n    F.when(F.col(\"AGE\") < 21, \"YOUNG\").otherwise(\n        F.when(F.col(\"AGE\") < 49, \"ADULT\").otherwise(\"OLD ADULT\")\n    ),\n)\n\nage_bkt_df = snowpark_df.select(\n    F.col(\"AGE_BKT\"),\n    F.when((F.col(\"AGE_BKT\")=='YOUNG') &amp; (F.col(\"TARGET\")==1),1).otherwise(0).as_(\"YOUNG_\"),\n    F.when((F.col(\"AGE_BKT\")=='ADULT') &amp; (F.col(\"TARGET\")==1),1).otherwise(0).as_(\"ADULT_\"),\n    F.when((F.col(\"AGE_BKT\")=='OLD ADULT') &amp; (F.col(\"TARGET\")==1),1).otherwise(0).as_(\"OLD_ADULT_\")\n)\n\nage_bkt_df.group_by(F.col(\"AGE_BKT\")).count().show()\n\n# -----------------------\n# |\"AGE_BKT\"  |\"COUNT\"  |\n# -----------------------\n# |OLD ADULT  |342413   |\n# |ADULT      |628554   |\n# |YOUNG      |77608    |\n# -----------------------\n\nage_bkt_df.select(\n    ((F.sum(\"YOUNG_\") * 100 ) / F.count(\"YOUNG_\")).as_(\"YOUNG % OF CASES\"),\n    ((F.sum(\"ADULT_\") * 100) / F.count(\"ADULT_\")).as_(\"ADULT % OF CASES\"),\n    ((F.sum(\"OLD_ADULT_\") * 100) / F.count(\"OLD_ADULT_\")).as_(\"OLD_ADULT % OF CASES\")\n).show()\n\n# --------------------------------------------------------------------\n# |\"YOUNG % OF CASES\"  |\"ADULT % OF CASES\"  |\"OLD_ADULT % OF CASES\"  |\n# --------------------------------------------------------------------\n# |1.534463            |20.877858           |14.969745               |\n# --------------------------------------------------------------------\n```\n\nAfter completing our analysis, we can save the transformed Dataset as a new Snowflake table using the following way.\npython\n\n```\nsnowpark_df.write.save_as_table(\n    table_name='COVID19_RECORDS_PROCESSED',\n    mode='overwrite'\n)\n```\n\nAlright, now we have preprocessed Dataset. Let's start the model training phase.\npython\n\n```\n# read the table \ntrain_data = session.table(\"COVID19_RECORDS_PROCESSED\")\n\n#create the stage for storing the ML models\nsession.sql('CREATE OR REPLACE STAGE ML_MODELS').show()\n```\n\nWe can use two different approaches to train and deploy models in Snowflake.\n  1. We can train the model locally, upload it to a stage and load it from the stage when the UDF is called.\n  2. We can define SPROC, which can train the model and save the trained model into the Snowflake stage when the SPROC is called. Here we'll need a separate UDF for the inferencing part.\n\n\nIn this article, we will explore both methods above.\n### Train the model locally, upload it to a stage and load it from the stage\n![Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1swC4aXf4M_hgkUT7Fe7r2Q.png)\nImage by author\nFirst, we have to define the function for training the model locally.\npython\n\n```\ndef train_model_locally(train:snowflake.snowpark.table.Table):\n    from sklearn.tree import DecisionTreeClassifier\n\n    #convert into pd dataframes\n\n    train = train.to_pandas()\n\n    xtrain,ytrain = train.drop('TARGET',axis=1),train['TARGET']\n\n    model = DecisionTreeClassifier()\n    model.fit(xtrain,ytrain)\n\n    return model\n\n#let's train the DT model\nmodel = train_model_locally(train_data_sf)\n\n#save the model\nimport joblib\njoblib.dump(model, 'predict_risk_score.joblib')\n\n#upload into the ML_MODELS SNowfla\nsession.file.put(\n    \"predict_risk_score.joblib\", \"@ML_MODELS\", auto_compress=False, overwrite=True\n)\n```\n\nSimilar to other machine learning pipelines, we need to define library dependencies.\npython\n\n```\nsession.clear_imports()\nsession.clear_packages()\n\n#Register above uploded model as import of UDF\nsession.add_import(\"@ML_MODELS/predict_risk_score.joblib\")\n\n#map packege dependancies\nsession.add_packages(\"joblib==1.1.0\", \"scikit-learn==1.1.1\", \"pandas==1.3.2\")\n```\n\nLet's define the UDF. Inside the UDF, it should load the model from the stage and then use it for the inferencing.\npython\n\n```\nfrom snowflake.snowpark.types import PandasSeries, PandasDataFrame\n\ndef read_file(filename):\n    import joblib\n    import sys\n    import os\n\n    #where all imports located at\n    import_dir = sys._xoptions.get(\"snowflake_import_directory\")\n\n    if import_dir:\n        with open(os.path.join(import_dir, filename), 'rb') as file:\n            m = joblib.load(file)\n            return m\n\n#register UDF\n@F.udf(name = 'predict_risk_score', is_permanent = True, replace = True, stage_location = '@ML_MODELS')\ndef predict_risk_score(ds: PandasSeries[dict]) -> PandasSeries[float]:\n\n    # later we will input train data as JSON object\n    # hance, we have to convert JSON object as pandas DF\n    df = pd.io.json.json_normalize(ds)[feature_cols]\n    pipeline = read_file('predict_risk_score.joblib')\n    return pipeline.predict_proba(df)[:,1]\n```\n\nNow we have successfully registered our UDF in Snowflake. You can verify it using the following way.\npython\n\n```\nsession.sql(\"DESC FUNCTION PREDICT_RISK_SCORE()\").show()\n\n# ------------------------------------------------------------------------\n# |\"property\"       |\"value\"                                             |\n# ------------------------------------------------------------------------\n# |signature        |()                                                  |\n# |returns          |FLOAT                                               |\n# |language         |PYTHON                                              |\n# |null handling    |CALLED ON NULL INPUT                                |\n# |volatility       |VOLATILE                                            |\n# |body             |                                                    |\n# |                 |import pickle                                       |\n# |                 |                                                    |\n# |                 |func = pickle.loads(bytes.fromhex('800595050400...  |\n# |                 |# The following comment contains the UDF source...  |\n# |                 |# import pandas as pd                               |\n# |                 |# def read_file(filename):                          |\n# |                 |#     import joblib                                 |\n# |                 |#     import sys                                    |\n# |                 |#     import os                                     |\n# |                 |#                                                   |\n# |                 |#     import_dir = sys._xoptions.get(\"snowflake...  |\n# |                 |#     if import_dir:                                |\n# |                 |#         with open(os.path.join(import_dir, fi...  |\n# |                 |#             m = joblib.load(file)                 |\n# |                 |#             return m                              |\n# |                 |# @F.udf(name = 'predict_risk_score', is_perman...  |\n# |                 |# def predict_risk_score(*args) -> PandasSeries...  |\n# |                 |#     df = pd.DataFrame([args])                     |\n# |                 |#     pipeline = read_file('predict_risk_score....  |\n# |                 |#     return pipeline.predict_proba(df)[:,1]        |\n# |                 |#                                                   |\n# |                 |# func = predict_risk_score                         |\n# |                 |#                                                   |\n# |                 | *********RESULTS TRUNCATED**************           |\n# ------------------------------------------------------------------------\n```\n\nLet's use UDF for inferencing.\npython\n\n```\n# `test_data_sf` is a fraction of `train_data`\ntest_data_sf.with_column(\n    'PREDICTION', \n    predict_risk_score(F.object_construct('*')))\n.select(\"TARGET\",\"PREDICTION\").show(20)\n\n# ---------------------------------\n# |\"TARGET\"  |\"PREDICTION\"        |\n# ---------------------------------\n# |1         |0.8333333333333334  |\n# |1         |0.0                 |\n# |1         |1.0                 |\n# |1         |1.0                 |\n# |1         |0.3333333333333333  |\n# |0         |0.0                 |\n# |1         |0.4                 |\n# |0         |0.5                 |\n# |1         |0.421875            |\n# ---------------------------------\n\n#similary, you can use below SQL as well.\n\nselect\n    target,\n    predict_risk_score(object_construct(*)) as predictions\nfrom\n    COVID19_RECORDS_PROCESSED\nlimit\n    100;\n```\n\n### Define train and inferencing procs/UDFs\nThis method will create a stored procedure for training the model and UDF for inferencing the model. You may refer to the diagram below for more insights.\n![Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1KIEhq0KvXT8wBjOcdI6zQQ.png)\nImage by author\nLet's define the stored procedure. At first, we will implement the Python function, and we can convert it to the Snowflake stored procedure in later steps.\npython\n\n```\ndef train_dt_procedure(\n    session: Session,\n    training_table: str,\n    feature_cols: list,\n    target_col: str,\n    model_name: str,\n) -> T.Variant:\n\n    \"\"\"\n    This will be our training procedure. Later we will register this as snowflake procedure.\n\n    training_table: snowflake table name to be used for training task\n    feature_cols: list of columns to be used in training\n    target_col: target column to be used\n    model_name: model name to used for model saving purpose\n\n    \"\"\"\n\n    #convert as pandas DF, rest of the steps similar to the local model training and saving.\n    local_training_data = session.table(training_table).to_pandas()\n\n    from sklearn.tree import DecisionTreeClassifier\n\n    X = local_training_data[feature_cols]\n    y = local_training_data[target_col]\n\n    model = DecisionTreeClassifier()\n    model.fit(X, y)\n\n    #do what ever you want to do with model, even the hyperparameter tuning..\n    # here I'll get feature importance\n    feat_importance = pd.DataFrame(\n        model.feature_importances_, feature_cols, columns=[\"FeatImportance\"]\n    ).to_dict()\n\n    from joblib import dump\n\n    dump(model, \"/tmp/\" + model_name)\n    session.file.put(\n        \"/tmp/\" + model_name, \"@ML_MODELS\", auto_compress=False, overwrite=True\n    )\n    return feat_importance\n```\n\nLet's register the above Python function as a stored procedure.\npython\n\n```\nsproc_train_dt_model = session.sproc.register(\n                    func=train_dt_procedure, \n                    name='sproc_train_dt_model', \n                    is_permanent=True, \n                    replace=True, \n                    stage_location='@ML_MODELS', \n                    packages=[\n                        'snowflake-snowpark-python',\n                        'scikit-learn',\n                        'joblib']\n)\n```\n\nNow we can use the procedure`SPROC_TRAIN_DT_MODEL()` as follows.\npython\n\n```\ntrain_data = session.table(\"COVID19_RECORDS_PROCESSED\")\n\n#create train and test dataframes\ntrain_data_pd,test_data_pd = train_test_split(\n                                        train_data_pd,\n                                        stratify=train_data_pd['TARGET'],\n                                        test_size=0.1\n)\n\n# writing as tempoary tables for mode training and inferencing part\nsession.write_pandas(\n    train_data_pd,\n    table_name=\"TRAIN_DATA_TMP\",\n    auto_create_table=True,\n    table_type=\"temporary\",\n)\nsession.write_pandas(\n    test_data_pd,\n    table_name=\"TEST_DATA_TMP\",\n    auto_create_table=True,\n    table_type=\"temporary\",\n)\n\ntrain_data_pd = train_data.to_pandas()\n\nfeature_cols = train_data.columns\nfeature_cols.remove('TARGET')\ntarget_col = 'TARGET'\nmodel_name = 'decisiontree.model' # How model should be saved in stage\n\nmodel_response = sproc_train_dt_model('TRAIN_DATA_TMP', \n                                            feature_cols, \n                                            target_col,\n                                            model_name, \n                                            session=session\n                                           )\n\nprint(model_response)\n\n# {\n#   \"FeatImportance\": {\n#     \"AGE\": 0.4543249401305732,\n#     \"ASTHMA\": 0.029003830541684678,\n#     \"CARDIOVASCULAR\": 0.025649097586968667,\n#     \"COPD\": 0.019300936592021863,\n#     \"DIABETES\": 0.059273293874405074,\n#     \"HIPERTENSION\": 0.05885196748765571,\n#     \"INMSUPR\": 0.0232534703448427,\n#     \"INTUBED\": 0.026365011429648998,\n#     \"MEDICAL_UNIT\": 0.08804779552309593,\n#     \"OBESITY\": 0.02991724846285235,\n#     \"OTHER_DISEASE\": 0.026840169399286344,\n#     \"PATIENT_TYPE\": 0,\n#     \"PNEUMONIA\": 0.04225497414608237,\n#     \"PREGNANT\": 0.012929499812685114,\n#     \"RENAL_CHRONIC\": 0.015894267526361774,\n#     \"SEX\": 0,\n#     \"TOBACCO\": 0.028563364646896985,\n#     \"USMER\": 0.059530132494938236\n#   }\n# }\n\n#plot feature importance\nfeature_coefficients = pd.DataFrame(eval(model_response))\n\nfeature_coefficients\n.sort_values(by='FeatImportance',ascending=False)\n.plot\n.bar(y='FeatImportance', figsize=(12,5))\nplt.show()\n```\n\n![Feature Importance | Image by author](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1sJY5i5mVl2inFLRwxE6XHg.png)\nFeature Importance | Image by author\nWe can define the UDF as follows. This function is similar to the previous one.\npython\n\n```\ndef udf_predict_risk_score(*args) -> float:\n    import os\n    import sys\n    from joblib import load\n\n    IMPORT_DIRECTORY_NAME = \"snowflake_import_directory\"\n    import_dir = sys._xoptions[IMPORT_DIRECTORY_NAME]\n    model_name = 'decisiontree.model'\n    model = load(import_dir+model_name)\n\n    #unlike previous JSON object, this will be a array, hence no need to\n    # decode the input\n    scored_data = model.predict(pd.DataFrame([args]))[0]\n\n    return scored_data\n```\n\nFinally, registering the UDF.\npython\n\n```\nudf_risk_score_model = session.udf.register(\n                            func=udf_predict_risk_score, \n                            name=\"udf_risk_score_model\", \n                            stage_location='@ML_MODELS',\n                            input_types=[T.FloatType()]*len(feature_cols),\n                            return_type = T.FloatType(),\n                            replace=True, \n                            is_permanent=True, \n                            imports=['@ML_MODELS/decisiontree.model'],\n                            packages=['scikit-learn==1.1.1','pandas','joblib'], \n                            session=session\n)\n```\n\nAlright, it's time to get predictions for our validation dataset. Here I am doing it with Snowflake editor.\nsql\n\n```\nSELECT\n    \"TARGET\",\n    udf_risk_score_model(\n        \"USMER\",\n        \"MEDICAL_UNIT\",\n        \"SEX\",\n        \"PATIENT_TYPE\",\n        \"INTUBED\",\n        \"PNEUMONIA\",\n        \"AGE\",\n        \"PREGNANT\",\n        \"DIABETES\",\n        \"COPD\",\n        \"ASTHMA\",\n        \"INMSUPR\",\n        \"HIPERTENSION\",\n        \"OTHER_DISEASE\",\n        \"CARDIOVASCULAR\",\n        \"OBESITY\",\n        \"RENAL_CHRONIC\",\n        \"TOBACCO\"\n    ) AS \"PREDICTION\"\nFROM\n    COVID19_RECORDS_PROCESSED limit 100;\n```\n\n### Conclusion\nWhile snowpark offers a comprehensive platform for our machine learning tasks, it has a [few issues](https://docs.snowflake.com/en/developer-guide/snowpark/python/python-snowpark-training-ml.html#limitations-and-known-issues) at the time of writing this article. As an example, PyTorch still needs to be supported by a snowpark. Also, only selected packages are available in conda; if we want to use other packages, such as catboost, we must import them manually into our environment as described [here](https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-udfs.html#reading-files-from-a-udf).\nThanks for reading! Connect with me on [LinkedIn](https://www.linkedin.com/in/ransaka/).\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657265628_qm714e.jpeg)\nWritten By\n## [Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\n[See all from Ransaka Ravihara](https://towardsdatascience.com/author/ransakaravihara/)\n[Data Science](https://towardsdatascience.com/tag/data-science/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Snowflake](https://towardsdatascience.com/tag/snowflake/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F&title=Machine%20Learning%20on%20Snowflake)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F&title=Machine%20Learning%20on%20Snowflake)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F&text=Machine%20Learning%20on%20Snowflake)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/01/0sj2elQnsgJHydrFp-scaled.jpg)](https://towardsdatascience.com/ridge-regression-a-robust-path-to-reliable-predictions-851290bed579/)\n## [Ridge Regression: A Robust Path to Reliable Predictions](https://towardsdatascience.com/ridge-regression-a-robust-path-to-reliable-predictions-851290bed579/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLearn how regularization reduces overfitting and improves model stability in linear regression.\n[Niklas Lang](https://towardsdatascience.com/author/niklas_lang/)\nJanuary 30, 202510 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/1n97707zKau5I5libJWl_XQ.png)](https://towardsdatascience.com/17-types-of-similarity-and-dissimilarity-measures-used-in-data-science-3eb914d2681/)\n## [17 types of similarity and dissimilarity measures used in data science.](https://towardsdatascience.com/17-types-of-similarity-and-dissimilarity-measures-used-in-data-science-3eb914d2681/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nThe following article explains various methods for computing distances and showing their instances in our daily lives. Additionally, it...\n[Mahmoud Harmouch](https://towardsdatascience.com/author/wiseai/)\nMarch 13, 202125 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1smojS8b-AcM9zE7uFRJdTA-scaled.jpeg)](https://towardsdatascience.com/application-of-machine-learning-algorithms-in-modeling-the-role-of-the-microbiome-in-the-colorectal-2c222ea6ba0/)\n## [Application of Machine Learning Algorithms in Modeling the Role of the Microbiome in Colorectal...](https://towardsdatascience.com/application-of-machine-learning-algorithms-in-modeling-the-role-of-the-microbiome-in-the-colorectal-2c222ea6ba0/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBioinformatics Framework design and Methodology - Machine Learning Modelling Results for understanding the colorectal cancer carcinogenesis\n[Miodrag Cekikj](https://towardsdatascience.com/author/cekikjmiodrag/)\nDecember 27, 20225 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/0HPIz-PHAQ5VhtZgb-scaled.jpg)](https://towardsdatascience.com/to-guarantee-impartial-ai-decisions-lady-justice-needs-to-blink-2992167b2591/)\n## [To Guarantee Impartial AI Decisions, Lady Justice Needs to Blink](https://towardsdatascience.com/to-guarantee-impartial-ai-decisions-lady-justice-needs-to-blink-2992167b2591/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nWhy is deleting the sensitive attributes not a simple solution to AI fairness?\n[Boris Ruf](https://towardsdatascience.com/author/boris-ruf/)\nFebruary 10, 20236 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2018/08/1LBjL30zbtPN6mTtwTUHn_w-scaled.jpeg)](https://towardsdatascience.com/data-science-career-advice-to-my-younger-self-4c37fac65184/)\n## [Data science career advice to my younger self](https://towardsdatascience.com/data-science-career-advice-to-my-younger-self-4c37fac65184/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nI don't know if any of these ideas would have benefited a younger me. I think they would have.\n[Schaun Wheeler](https://towardsdatascience.com/author/schaun.wheeler/)\nAugust 28, 201812 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0ygui9URrkuLN_ijt-scaled.jpg)](https://towardsdatascience.com/four-common-pitfalls-to-avoid-in-exploratory-data-analysis-85d822dd5e34/)\n## [Four common pitfalls to avoid in Exploratory Data Analysis](https://towardsdatascience.com/four-common-pitfalls-to-avoid-in-exploratory-data-analysis-85d822dd5e34/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nTelling actionable stories with data\n[Abiodun Olaoye](https://towardsdatascience.com/author/aolaoye/)\nOctober 20, 20223 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1KBlN4D0McUa9LOCop25YyA.jpeg)](https://towardsdatascience.com/applied-python-chronicles-a-gentle-intro-to-pydantic-a630f797e933/)\n## [Applied Python Chronicles: A Gentle Intro to Pydantic](https://towardsdatascience.com/applied-python-chronicles-a-gentle-intro-to-pydantic-a630f797e933/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nWhether you are a Data Engineer, Machine Learning Engineer or Web developer, you ought to get used to this tool.\n[Ilija Lazarevic](https://towardsdatascience.com/author/ilija.lazarevic/)\nJuly 25, 202412 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/19GzS_dW6HcDfzpW3cDpQOw-scaled.jpeg)](https://towardsdatascience.com/probabilistic-cusum-for-change-point-detection-121f793ab3a1/)\n## [Probabilistic CUSUM for change point detection](https://towardsdatascience.com/probabilistic-cusum-for-change-point-detection-121f793ab3a1/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nCUSUM is arguably the simplest algorithm for change point detection problems as in IoT or finance applications.\n[Sarem Seitz](https://towardsdatascience.com/author/sarem-seitz/)\nAugust 4, 20225 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/1lzv5zRutA3s6-HrQw17Fyg.jpeg)](https://towardsdatascience.com/building-an-ai-8-ball-with-roberta-2bfbf6f5519b/)\n## [Building an AI 8-Ball with RoBERTa](https://towardsdatascience.com/building-an-ai-8-ball-with-roberta-2bfbf6f5519b/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nCan an Artificial Neural Network answer yes/no questions? Signs point to yes.\n[Robert A. Gonsalves](https://towardsdatascience.com/author/robgon/)\nNovember 1, 20208 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607631/image?etag=1781543525510&width=500&height=500) Critical Mistakes Companies Make When Integrating AI/ML into Their Processes ](https://towardsdatascience.com/critical-mistakes-companies-make-when-integrating-ai-ml-into-their-processes/ \"Critical Mistakes Companies Make When Integrating AI/ML into Their Processes\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n\n\n",
  "metadata": {
    "title": "Machine Learning on Snowflake | Towards Data Science",
    "description": "snowflake is one of the leading data platforms out there. In this article, we will explore the capabilities of its' snowpark python...",
    "keywords": null,
    "author": "Ransaka Ravihara",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Machine Learning on Snowflake",
    "og:description": "snowflake is one of the leading data platforms out there. In this article, we will explore the capabilities of its' snowpark python...",
    "og:url": "https://towardsdatascience.com/machine-learning-on-snowflake-ea6c559af2d/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/0ceNRNk7_QSHaS2ol-scaled.jpg",
    "og:image:width": "2560",
    "og:image:height": "1932",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Ransaka Ravihara",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "9 min read",
    "article:published_time": "2022-12-26T06:53:42.000Z",
    "article:modified_time": "2022-12-26T06:53:42.000Z",
    "article:author": "https://towardsdatascience.com/author/ransakaravihara/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_000.txt",
      "chars": 612
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_001.txt",
      "chars": 219
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_002.txt",
      "chars": 1198
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_003.txt",
      "chars": 496
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_004.txt",
      "chars": 159
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_005.txt",
      "chars": 151
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_006.txt",
      "chars": 134
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_007.txt",
      "chars": 1394
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_008.txt",
      "chars": 100
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_009.txt",
      "chars": 175
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_010.txt",
      "chars": 617
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_011.txt",
      "chars": 261
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_012.txt",
      "chars": 834
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_013.txt",
      "chars": 2608
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_014.txt",
      "chars": 822
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_015.txt",
      "chars": 1299
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_016.txt",
      "chars": 428
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_017.txt",
      "chars": 2142
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_018.txt",
      "chars": 469
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_019.txt",
      "chars": 639
    },
    {
      "language": "txt",
      "file": "attachments/63c7f9f88b5a/code/block_020.txt",
      "chars": 480
    }
  ],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/0ceNRNk7_QSHaS2ol-scaled.jpg",
      "alt": "Photo by Aaron Burden on Unsplash",
      "local_path": "attachments/63c7f9f88b5a/images/000.jpg",
      "bytes": 513270,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1zOTKNeFOfEDF48XAIwR4YA.png",
      "alt": "Topics covered in this article | Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/001.png",
      "bytes": 16270,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1soGMsladnT8HxaSLFCgIrA.png",
      "alt": "Target Distribution | Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/002.png",
      "bytes": 5122,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1zEq0762fLVascp54cE0rmg.png",
      "alt": "Age Distribution | Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/003.png",
      "bytes": 6704,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1swC4aXf4M_hgkUT7Fe7r2Q.png",
      "alt": "Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/004.png",
      "bytes": 15845,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1KIEhq0KvXT8wBjOcdI6zQQ.png",
      "alt": "Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/005.png",
      "bytes": 21393,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1sJY5i5mVl2inFLRwxE6XHg.png",
      "alt": "Feature Importance | Image by author",
      "local_path": "attachments/63c7f9f88b5a/images/006.png",
      "bytes": 19951,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/01/0sj2elQnsgJHydrFp-scaled.jpg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/007.jpg",
      "bytes": 429087,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/03/1n97707zKau5I5libJWl_XQ.png",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/008.png",
      "bytes": 1655552,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1smojS8b-AcM9zE7uFRJdTA-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/009.jpeg",
      "bytes": 287513,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/0HPIz-PHAQ5VhtZgb-scaled.jpg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/010.jpg",
      "bytes": 747926,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2018/08/1LBjL30zbtPN6mTtwTUHn_w-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/011.jpeg",
      "bytes": 638519,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/10/0ygui9URrkuLN_ijt-scaled.jpg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/012.jpg",
      "bytes": 545952,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2024/07/1KBlN4D0McUa9LOCop25YyA.jpeg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/013.jpeg",
      "bytes": 224132,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/19GzS_dW6HcDfzpW3cDpQOw-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/014.jpeg",
      "bytes": 290721,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/1lzv5zRutA3s6-HrQw17Fyg.jpeg",
      "alt": "",
      "local_path": "attachments/63c7f9f88b5a/images/015.jpeg",
      "bytes": 193392,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://www.youtube.com/c/TowardsDataScience",
      "quality": "unavailable",
      "local_path": "",
      "note": "无1080p且无720p，未交付更低清晰度"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ransakaravihara/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/snowflake/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/ridge-regression-a-robust-path-to-reliable-predictions-851290bed579/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/niklas_lang/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/17-types-of-similarity-and-dissimilarity-measures-used-in-data-science-3eb914d2681/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/wiseai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/application-of-machine-learning-algorithms-in-modeling-the-role-of-the-microbiome-in-the-colorectal-2c222ea6ba0/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/cekikjmiodrag/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/to-guarantee-impartial-ai-decisions-lady-justice-needs-to-blink-2992167b2591/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/boris-ruf/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://unsplash.com/@aaronburden"
    },
    {
      "type": "external",
      "href": "https://unsplash.com"
    },
    {
      "type": "external",
      "href": "https://docs.snowflake.com/en/developer-guide/udf/python/udf-python-packages.html"
    },
    {
      "type": "external",
      "href": "https://signup.snowflake.com/"
    },
    {
      "type": "external",
      "href": "https://github.com/Ransaka/ML-on-Snowflake"
    },
    {
      "type": "external",
      "href": "https://www.kaggle.com/datasets/meirnizri/covid19-dataset"
    },
    {
      "type": "external",
      "href": "https://creativecommons.org/publicdomain/zero/1.0/"
    },
    {
      "type": "external",
      "href": "https://docs.snowflake.com/en/developer-guide/snowpark/python/python-snowpark-training-ml.html"
    },
    {
      "type": "external",
      "href": "https://docs.snowflake.com/en/developer-guide/snowpark/python/creating-udfs.html"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/in/ransaka/"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Machine+Learning+on+Snowflake&u=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Machine+Learning+on+Snowflake&url=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Machine+Learning+on+Snowflake&url=https%3A%2F%2Ftowardsdatascience.com%2Fmachine-learning-on-snowflake-ea6c559af2d%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:49Z",
  "source_url": "https://towardsdatascience.com/machine-learning-on-snowflake-ea6c559af2d/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}