{"id":839,"date":"2018-04-11T09:00:44","date_gmt":"2018-04-11T09:00:44","guid":{"rendered":"https:\/\/lucient.com\/en\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/"},"modified":"2020-09-28T13:54:31","modified_gmt":"2020-09-28T13:54:31","slug":"python-for-sql-server-specialists-part-3-graphs-and-machine-learning","status":"publish","type":"post","link":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/","title":{"rendered":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">After learning about Python fundamentals and basics about working with data, it is time to start with more exciting parts of this <strong>Python for SQL Server Specialists<\/strong> series.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article you will learn about the <strong>most important libraries<\/strong> for advanced graphing, namely <strong>matplotlib <\/strong>and <strong>seaborn<\/strong>, and about the most popular data science library, the <strong>scikit-learn<\/strong> library.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2a0c994c192\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2a0c994c192\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#Creating_Graphs\" >Creating Graphs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#Graphing_SQL_Server_Data\" >Graphing SQL Server Data<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#Machine_Learning_with_Scikit-Learn\" >Machine Learning with Scikit-Learn<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_Graphs\"><\/span>Creating Graphs<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You will learn how to do graphs with two Python libraries: matplotlib and seaborn. Matplotlib is a mature well-tested, and cross-platform graphics engine. In order to work with it, you need to import it. However, you need also to import an interface to it. Matplotlib is the whole library, and matplotlib.pyplot is a module in matplotlib. Pyplot as the interface to the underlying plotting library that knows how automatically create the figure and axes and other necessary elements to create the desired plot. Seaborn is a visualization library built on matplotlib, adding additional enhanced graphing options, and making work with pandas data frames easy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anyway, without further talking, let\u2019s start developing. First, let\u2019s import all necessary packages for this section.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\">import numpy as np\nimport pandas as pd\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport seaborn as sns<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The next step is to create sample data. An array of 100 evenly distributed numbers between 0 and 10 is the data for the independent variable, and then the following code creates two dependent variables, one as the sinus of the independent one, and the second as the natural logarithm of the independent one.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Creating data and functions\nx = np.linspace(0.1, 10, 100)\ny = np.sin(x)\nz = np.log(x)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following code defines the style to use for the graph and then plots two lines, one for each function. The plt.show() command is needed to show the graph interactively.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Basic graph\nplt.style.use('classic')\nplt.plot(x, y)\nplt.plot(x, z)\nplt.show()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you execute the code above in Visual Studio 2017, you should get a pop-up window with the desired graph. I am not showing the graph yet; before showing it, I want to make some enhancements and besides showing it also save it to a file. The following code uses the plt.figure() function to create an object that will store the graph. Then for each function defines the line style, line width, line color, and label. The plt.axis() line redefines the axes range. The next three lines define the axes titles and the title of the graph and define font size for the text. The plt.legend() line draws the legend. The last two lines show the graph interactively and save it to a file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Enhanced graph\nf = plt.figure()\nplt.plot(x, y, color = 'blue', linestyle = 'solid',\n         linewidth = 4, label = 'sin')\nplt.plot(x, z, color = 'red', linestyle = 'dashdot',\n         linewidth = 4, label = 'log')\nplt.axis([-1, 11, -2, 3.5])\nplt.xlabel(\"X\", fontsize = 16)\nplt.ylabel(\"sin(x) &amp; log(x)\", fontsize = 16)\nplt.title(\"Enhanced Line Plot\", fontsize = 25)\nplt.legend(fontsize = 16)\nplt.show()\nf.savefig('C:\\\\PythonSolidQ\\\\SinLog.png')<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the result of the code above \u2013 the first nice graph.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png\" alt=\"\" class=\"img-fluid wp-image-36589\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Graphing_SQL_Server_Data\"><\/span>Graphing SQL Server Data<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now it\u2019s time to switch to some more realistic examples. First, let\u2019s import the dbo.vTargetMail data from the AdventureWorksDW2016 demo database in a pandas data frame.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Connecting and reading the data\nimport pyodbc\ncon = pyodbc.connect('DSN=AWDW;UID=RUser;PWD=Pa$$w0rd')\nquery = \"\"\"SELECT CustomerKey, \n             TotalChildren, NumberChildrenAtHome,\n             HouseOwnerFlag, NumberCarsOwned,\n             EnglishEducation as Education,\n             YearlyIncome, Age, BikeBuyer\n           FROM dbo.vTargetMail;\"\"\"\nTM = pd.read_sql(query, con)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The next graph you can create is a scatterplot. The following code plots YearlyIncome over Age. Note that the code creates a smaller data frame with first hundred rows only, in order to get less cluttered graph for the demo. Again, for the sake of brevity, I am not showing this graph.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Scatterplot\nTM1 = TM.head(100)\nplt.scatter(TM1['Age'], TM1['YearlyIncome'])\nplt.xlabel(\"Age\", fontsize = 16)\nplt.ylabel(\"YearlyIncome\", fontsize = 16)\nplt.title(\"YearlyIncome over Age\", fontsize = 25)\nplt.show()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For categorical variables, you usually create bar charts for a quick overview of the distribution. You can do it with the countplot() function from the seaborn package. Let\u2019s try to plot counts for the BikeBuyer variable in the classes of the Education variable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Bar chart\nsns.countplot(x=\"Education\", hue=\"BikeBuyer\", data=TM);\nplt.show()\n# Note the wrong order of Education<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you executed the previous code, you should have noticed that the Education variable is not sorted correctly. You need to inform Python about the intrinsic order of a categorial or nominal variable. The following code defines that the Education variable is categorical and then shows the categories,<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Define Education as categorical\nTM['Education'] = TM['Education'].astype('category')\nTM['Education']<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the next step, the code defines the correct order.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\">&nbsp;#&nbsp;Proper&nbsp;order \nTM['Education'].cat.reorder_categories( \n&nbsp;&nbsp;&nbsp;&nbsp;[\"Partial&nbsp;High&nbsp;School\",&nbsp; \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"High&nbsp;School\",\"Partial&nbsp;College\",&nbsp; \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"Bachelors\",&nbsp;\"Graduate&nbsp;Degree\"],&nbsp;inplace=True)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now it is time to create the bar chart again. This time, I am also saving it to a file, and showing it here.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Correct graph\nf = plt.figure()\nsns.countplot(x=\"Education\", hue=\"BikeBuyer\", data=TM);\nplt.show()\nf.savefig('C:\\\\PythonSolidQ\\\\EducationBikeBuyer.png')<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So here is the bar chart.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/bar-chart.png\" alt=\"\" class=\"img-fluid wp-image-36592\"\/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Machine_Learning_with_Scikit-Learn\"><\/span>Machine Learning with Scikit-Learn<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">You can find many different libraries for statistics, data mining and machine learning in Python. Probably the best-known one is the scikit-learn package. It provides most of the commonly used algorithms, and also tools for data preparation and model evaluation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In scikit-learn, you work with data in a tabular representation by using pandas data frames. The input table (actually a two-dimensional array, not a table in the relational sense) has columns used to train the model. Columns, or attributes, represent some features, and therefore this table is also called the features matrix. There is no prescribed naming convention; however, in most of the Python code, you will note that this features matrix is stored in variable X.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have a directed, or supervised algorithm, then you also need the target variable. This is represented as a vector or one-dimensional target array. Commonly, this target array is stored in a variable named y.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without further hesitation, let\u2019s create some mining models. First, the following code imports all necessary libraries for this section.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># sklear imports\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.mixture import GaussianMixture<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Next step is to prepare the features matrix and the target array. The following code also checks the shape of both.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Preparing the data for Naive Bayes\nX = TM[['TotalChildren', 'NumberChildrenAtHome',\n        'HouseOwnerFlag', 'NumberCarsOwned',\n        'YearlyIncome', 'Age']]\nX.shape\ny = TM['BikeBuyer']\ny.shape<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first model will be a supervised one, using the Na\u00efve Bayes classification. For testing the accuracy of the model, you need to split the data into the training and the test set. You can use the train_test_split() function from the scikit-learn library for this task.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Split to the treining and test sets\nXtrain, Xtest, ytrain, ytest = train_test_split(\n    X, y, random_state = 0, train_size = 0.7)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the code above puts 70% of the data into the training set and 30% into the test set. The next step is to initialize and train the model with the training data set.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Initialize and train the model\nmodel = GaussianNB()\nmodel.fit(Xtrain, ytrain)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it. The model is prepared and trained. You can start using it for making predictions. You can use the test set for predictions and evaluate the model. A very well-known measure is the accuracy. The accuracy is the proportion of the total number of predictions that were correct, defined as the sum of true positive and true negative predictions with the total number of cases predicted. The following code uses the test set for the predictions and then measures the accuracy.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Predictions and accuracy\nymodel = model.predict(Xtest)\naccuracy_score(ytest, ymodel)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can see that you can do quite advanced analyses with just few lines of code. Let\u2019s make another model, this time an undirected one, using the clustering algorithm. For this one, you don\u2019t need training and test sets, and also not the target array. The only thing you need to prepare is the features matrix.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Preparing the data for Clustering\nX = TM[['TotalChildren', 'NumberChildrenAtHome',\n        'HouseOwnerFlag', 'NumberCarsOwned',\n        'YearlyIncome', 'Age', 'BikeBuyer']]<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Again, you need to initialize and fit the model. Note the following code tries to group cases in two clusters.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Initialize and train the model\nmodel = GaussianMixture(n_components = 2, covariance_type = 'full')\nmodel.fit(X)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The predict() function for the clustering model creates the cluster information for each case in the form of a resulting vector. The following code creates this vector and shows it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Predictions\nymodel = model.predict(X)\nymodel<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can add the cluster information to the input feature matrix.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Add the cluster membership to the source data\nX['Cluster'] = ymodel\nX.head()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you need to understand the clusters. You can get this understanding graphically. The following code shows how you can use the seaborn lmplot() function to create scatterplot showing the cluster membership of the cases spread over income and age.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted EnlighterJSRAW\"># Analyze the clusters\nsns.set(font_scale = 3)\nlm = sns.lmplot(x = 'YearlyIncome', y = 'Age', \n                hue = 'Cluster',  markers = ['o', 'x'],\n                palette = [\"orange\", \"blue\"], scatter_kws={\"s\": 200},\n                data = X, fit_reg = False,\n                sharex = False, legend = True)\naxes = lm.axes\naxes[0,0].set_xlim(0, 190000)\nplt.show(lm)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The following figure shows the result. You can see that in cluster 0 there are older people with less income, while cluster 1 consists of younger people, with not so distinctively higher income only.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/yearly-income-1024x629.png\" alt=\"Python for SQL Server 3\" class=\"img-fluid wp-image-36595\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now this was something, right? With couple of lines of code, we succeeded to create very nice graphs and perform quite advanced analyses. We analyzed SQL Server data. However, we did not use neither the scalable Microsoft machine learning libraries nor Python code inside SQL Server yet. Stay tuned &#8211; this is left for the last article in this series.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Click&nbsp;<a href=\"https:\/\/blogs.solidq.com\/wp-content\/uploads\/2018\/04\/PySQL_Part3.zip\">here to download the code<\/a><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Read the whole series:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><a class=\"row-title\" href=\"\/?p=36194\" aria-label=\"\u201cPython for SQL Server Specialists Part 1: Introducing Python\u201d (Edit)\">Python for SQL Server Specialists Part 1: Introducing Python<\/a><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><a class=\"row-title\" href=\"\/?p=36316\" aria-label=\"\u201cPython for SQL Server Specialists Part 2: Working with Data\u201d (Edit)\">Python for SQL Server Specialists Part 2: Working with Data<\/a><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><a class=\"row-title\" href=\"\/?p=36679\" aria-label=\"\u201cPython for SQL Server Specialists Part 4: Python and SQL Server\u201d (Edit)\">Python for SQL Server Specialists Part 4: Python and SQL Server<\/a><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is just an introduction, for more on starting with data science in SQL Server please refer to the book &#8220;Data Science with SQL Server Quick Start Guide&#8221; (<a href=\"https:\/\/www.packtpub.com\/big-data-and-business-intelligence\/data-science-sql-server-quick-start-guide\">https:\/\/www.packtpub.com\/big-data-and-business-intelligence\/data-science-sql-server-quick-start-guide<\/a>), where you will learn about tools and methods not just in Python, but also R and T-SQL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After learning about Python fundamentals and basics about working with data, it is time to start with more exciting parts of this Python for SQL Server Specialists series. In this article you will learn about the most important libraries for advanced graphing, namely matplotlib and seaborn, and about the most popular data science library, the [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[8],"tags":[16],"class_list":["post-839","post","type-post","status-publish","format-standard","hentry","category-technical","tag-data-analytics-for-developers"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America\" \/>\n<meta property=\"og:description\" content=\"After learning about Python fundamentals and basics about working with data, it is time to start with more exciting parts of this Python for SQL Server Specialists series. In this article you will learn about the most important libraries for advanced graphing, namely matplotlib and seaborn, and about the most popular data science library, the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/\" \/>\n<meta property=\"og:site_name\" content=\"Lucient - North America\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/LucientData\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-11T09:00:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-28T13:54:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png\" \/>\n<meta name=\"author\" content=\"dsarka\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lucient_data\" \/>\n<meta name=\"twitter:site\" content=\"@lucient_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"dsarka\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/\"},\"author\":{\"name\":\"dsarka\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#\\\/schema\\\/person\\\/abd50575df3732f3d3191fa1878f3cf8\"},\"headline\":\"Python for SQL Server Specialists Part 3: Graphs and Machine Learning\",\"datePublished\":\"2018-04-11T09:00:44+00:00\",\"dateModified\":\"2020-09-28T13:54:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/\"},\"wordCount\":1333,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/lucient.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2020\\\/09\\\/enhaced-line-plot.png\",\"keywords\":[\"Data Analytics for Developers\"],\"articleSection\":[\"Technical\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/\",\"url\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/\",\"name\":\"Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/lucient.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2020\\\/09\\\/enhaced-line-plot.png\",\"datePublished\":\"2018-04-11T09:00:44+00:00\",\"dateModified\":\"2020-09-28T13:54:31+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#primaryimage\",\"url\":\"https:\\\/\\\/lucient.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2020\\\/09\\\/enhaced-line-plot.png\",\"contentUrl\":\"https:\\\/\\\/lucient.com\\\/en\\\/wp-content\\\/uploads\\\/sites\\\/7\\\/2020\\\/09\\\/enhaced-line-plot.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/lucient.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python for SQL Server Specialists Part 3: Graphs and Machine Learning\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/lucient.com\\\/en\\\/\",\"name\":\"Lucient - North America\",\"description\":\"Empowering businesses with data analytics\",\"publisher\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/lucient.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#organization\",\"name\":\"Lucient\",\"url\":\"https:\\\/\\\/lucient.com\\\/en\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/lucient.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Lucient-Logo-Pos-RGB.png\",\"contentUrl\":\"https:\\\/\\\/lucient.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/Lucient-Logo-Pos-RGB.png\",\"width\":2540,\"height\":568,\"caption\":\"Lucient\"},\"image\":{\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/LucientData\",\"https:\\\/\\\/x.com\\\/lucient_data\",\"https:\\\/\\\/instagra.com\\\/lucient_data\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/lucientdata\",\"https:\\\/\\\/youtube.com\\\/channel\\\/UCLr1d81OFqPo13IQ9-htVWQ\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/lucient.com\\\/en\\\/#\\\/schema\\\/person\\\/abd50575df3732f3d3191fa1878f3cf8\",\"name\":\"dsarka\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g\",\"caption\":\"dsarka\"},\"url\":\"https:\\\/\\\/lucient.com\\\/en\\\/blog\\\/author\\\/dsarka\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/","og_locale":"en_US","og_type":"article","og_title":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America","og_description":"After learning about Python fundamentals and basics about working with data, it is time to start with more exciting parts of this Python for SQL Server Specialists series. In this article you will learn about the most important libraries for advanced graphing, namely matplotlib and seaborn, and about the most popular data science library, the [&hellip;]","og_url":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/","og_site_name":"Lucient - North America","article_publisher":"https:\/\/www.facebook.com\/LucientData","article_published_time":"2018-04-11T09:00:44+00:00","article_modified_time":"2020-09-28T13:54:31+00:00","og_image":[{"url":"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png","type":"","width":"","height":""}],"author":"dsarka","twitter_card":"summary_large_image","twitter_creator":"@lucient_data","twitter_site":"@lucient_data","twitter_misc":{"Written by":"dsarka","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#article","isPartOf":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/"},"author":{"name":"dsarka","@id":"https:\/\/lucient.com\/en\/#\/schema\/person\/abd50575df3732f3d3191fa1878f3cf8"},"headline":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning","datePublished":"2018-04-11T09:00:44+00:00","dateModified":"2020-09-28T13:54:31+00:00","mainEntityOfPage":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/"},"wordCount":1333,"commentCount":0,"publisher":{"@id":"https:\/\/lucient.com\/en\/#organization"},"image":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png","keywords":["Data Analytics for Developers"],"articleSection":["Technical"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/","url":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/","name":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning - Lucient - North America","isPartOf":{"@id":"https:\/\/lucient.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#primaryimage"},"image":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#primaryimage"},"thumbnailUrl":"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png","datePublished":"2018-04-11T09:00:44+00:00","dateModified":"2020-09-28T13:54:31+00:00","breadcrumb":{"@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#primaryimage","url":"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png","contentUrl":"https:\/\/lucient.com\/en\/wp-content\/uploads\/sites\/7\/2020\/09\/enhaced-line-plot.png"},{"@type":"BreadcrumbList","@id":"https:\/\/lucient.com\/en\/blog\/python-for-sql-server-specialists-part-3-graphs-and-machine-learning\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lucient.com\/en\/"},{"@type":"ListItem","position":2,"name":"Python for SQL Server Specialists Part 3: Graphs and Machine Learning"}]},{"@type":"WebSite","@id":"https:\/\/lucient.com\/en\/#website","url":"https:\/\/lucient.com\/en\/","name":"Lucient - North America","description":"Empowering businesses with data analytics","publisher":{"@id":"https:\/\/lucient.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lucient.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/lucient.com\/en\/#organization","name":"Lucient","url":"https:\/\/lucient.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lucient.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/lucient.com\/wp-content\/uploads\/2021\/02\/Lucient-Logo-Pos-RGB.png","contentUrl":"https:\/\/lucient.com\/wp-content\/uploads\/2021\/02\/Lucient-Logo-Pos-RGB.png","width":2540,"height":568,"caption":"Lucient"},"image":{"@id":"https:\/\/lucient.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/LucientData","https:\/\/x.com\/lucient_data","https:\/\/instagra.com\/lucient_data","https:\/\/www.linkedin.com\/company\/lucientdata","https:\/\/youtube.com\/channel\/UCLr1d81OFqPo13IQ9-htVWQ"]},{"@type":"Person","@id":"https:\/\/lucient.com\/en\/#\/schema\/person\/abd50575df3732f3d3191fa1878f3cf8","name":"dsarka","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4a8af2b240a5f32db136e340c424195adbc5b560b0833c0723dfa87fab9963c6?s=96&d=mm&r=g","caption":"dsarka"},"url":"https:\/\/lucient.com\/en\/blog\/author\/dsarka\/"}]}},"_links":{"self":[{"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/posts\/839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/comments?post=839"}],"version-history":[{"count":0,"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/posts\/839\/revisions"}],"wp:attachment":[{"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/media?parent=839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/categories?post=839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lucient.com\/en\/wp-json\/wp\/v2\/tags?post=839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}