{"id":1516,"date":"2017-11-23T02:09:36","date_gmt":"2017-11-23T02:09:36","guid":{"rendered":"http:\/\/intelligentonlinetools.com\/blog\/?p=1516"},"modified":"2017-11-30T01:57:25","modified_gmt":"2017-11-30T01:57:25","slug":"regression-and-classification-decision-trees-building-with-python-and-running-online","status":"publish","type":"post","link":"http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/","title":{"rendered":"Regression and Classification Decision Trees &#8211; Building with Python and Running Online"},"content":{"rendered":"<p>According to survey [1] <b>Decision Trees<\/b> constitute one of the 10 most popular data mining algorithms.<br \/>\nDecision trees used in data mining are of two main types:<br \/>\n<b>Classification tree<\/b> analysis is when the predicted outcome is the class to which the data belongs.<br \/>\n<b>Regression tree<\/b> analysis is when the predicted outcome can be considered a real number (e.g. the price of a house, or a patient&#8217;s length of stay in a hospital).[2]<\/p>\n<p>In the previous posts I already covered how to create Regression Decision Trees with python:<\/p>\n<p><a href=http:\/\/intelligentonlinetools.com\/blog\/2017\/02\/18\/building-decision-trees-in-python\/ target=\"_blank\">Building Decision Trees in Python<\/a><br \/>\n<a href=http:\/\/intelligentonlinetools.com\/blog\/2017\/02\/18\/building-decision-trees-in-python-handling-categorical-data\/ target=\"_blank\">Building Decision Trees in Python \u2013 Handling Categorical Data<\/a><\/p>\n<p>In this post you will find more simplified python code for classification and regression decision trees. <b>Online link<\/b> to run decision tree also will be provided. This is very useful if you want see results immediately without coding. <\/p>\n<p>To <strong>run the code<\/strong> provided here you need just change file path to file containing data. The Decision Trees in this post are tested on simple artificial dataset that was motivated by doing feature selection for blog data: <\/p>\n<p><a href=http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/13\/getting-data-driven-insights-from-blog-data-analysis-with-feature-selection\/ target=\"_blank\">Getting Data-Driven Insights from Blog Data Analysis with Feature Selection<\/a><\/p>\n<p><strong>Dataset<\/strong><br \/>\nOur <strong>dataset<\/strong> consists of 3 columns in csv file and shown below. It has 2 independent variables (features or X columns)  &#8211; categorical and numerical, and dependent numerical variable (target or Y column).  The script is assuming that the target column is the last column. Below is the dataset that is used in this post:<\/p>\n<pre><code>\r\nX1\tX2\tY\r\nred\t1\t100\r\nred\t2\t99\r\nred\t1\t85\r\nred\t2\t100\r\nred\t1\t79\r\nred\t2\t100\r\nred\t1\t100\r\nred\t1\t85\r\nred\t2\t100\r\nred\t1\t79\r\nblue\t2\t22\r\nblue\t1\t20\r\nblue\t2\t21\r\nblue\t1\t13\r\nblue\t2\t10\r\nblue\t1\t22\r\nblue\t2\t20\r\nblue\t1\t21\r\nblue\t2\t13\r\nblue\t1\t10\r\nblue\t1\t22\r\nblue\t2\t20\r\nblue\t1\t21\r\nblue\t2\t13\r\nblue\t1\t10\r\nblue\t2\t22\r\nblue\t1\t20\r\nblue\t2\t21\r\nblue\t1\t13\r\ngreen\t2\t10\r\ngreen\t1\t22\r\ngreen\t2\t20\r\ngreen\t1\t21\r\ngreen\t2\t13\r\ngreen\t1\t10\r\ngreen\t2\t22\r\ngreen\t1\t20\r\ngreen\t1\t13\r\ngreen\t2\t22\r\ngreen\t1\t20\r\ngreen\t2\t21\r\ngreen\t1\t13\r\ngreen\t2\t10\r\n<\/code><\/pre>\n<p>You can use dataset with different number of columns for independent variables without changing the code.<\/p>\n<p>For <strong>converting categorical variable to numerical<\/strong> we use here <em>pd.get_dummies(dataframe)<\/em> method from pandas library. Here dataframe is our input data. So the column with &#8220;green&#8221;, &#8220;red&#8221;, &#8220;yellow&#8221; will be transformed in 3 columns with 0,1 values in each (one hot encoding scheme).  Below are the few first rows after converting:<\/p>\n<pre><code>\r\nN   X2  X1_blue  X1_green  X1_red    Y\r\n0    1      0.0       0.0     1.0  100\r\n1    2      0.0       0.0     1.0   99\r\n2    1      0.0       0.0     1.0   85\r\n3    2      0.0       0.0     1.0  100\r\n<\/code><\/pre>\n<p><strong>Python Code<\/strong><br \/>\nTwo scripts are provided here &#8211; <strong>regressor<\/strong> and <strong>classifier<\/strong>.  For classifier the target variable should be  categorical.  We use however same dataset but convert numerical continuous variable to classes with labels (A,B,C) within the script based on inputted  bin ranges ([15,50,100] which means bins 0-15, 15.001-50, 50.001-100). We use this after applying <em>get_dummies<\/em>   <\/p>\n<p>What if you have categorical target?  Calling <em>get_dummies<\/em> will convert it to numerical too but we do not want this. In this case you need specify explicitly what columns need to be converted via parameter <strong>columns<\/strong> As per the documentation:<br \/>\n<strong>columns<\/strong> : list-like, default None. This is column names in the DataFrame to be encoded. If columns is None then all the columns with object or category dtype will be converted. [3]<br \/>\nIn our example we would need to do specify column X1 like this:<br \/>\n<em>dataframe=pd.get_dummies(dataframe, columns=[&#8220;X1&#8221;])<\/em><\/p>\n<p>The results of running scripts are decision trees shown below:<br \/>\n<strong>Decision Tree Regression<\/strong><br \/>\n<img data-attachment-id=\"1542\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/decision_tree_11_2017\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017.png\" data-orig-size=\"791,746\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"decision_tree_11_2017\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-300x283.png\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017.png\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-300x283.png\" alt=\"\" width=\"300\" height=\"283\" class=\"alignnone size-medium wp-image-1542\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-300x283.png 300w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-768x724.png 768w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017.png 791w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><strong>Decision Tree Classification<\/strong><br \/>\n<img data-attachment-id=\"1541\" data-permalink=\"http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/decision_tree_categorical_target_11_2017\/#main\" data-orig-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017.png\" data-orig-size=\"658,699\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"decision_tree_categorical_target_11_2017\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017-282x300.png\" data-large-file=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017.png\" decoding=\"async\" loading=\"lazy\" src=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017-282x300.png\" alt=\"\" width=\"282\" height=\"300\" class=\"alignnone size-medium wp-image-1541\" srcset=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017-282x300.png 282w, http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_categorical_target_11_2017.png 658w\" sizes=\"(max-width: 282px) 100vw, 282px\" \/><\/p>\n<p><strong>Running Decision Trees Online<\/strong><br \/>\nIn case you do not want to play with python code, you can run Decision Tree algorithms online at <a href=\"http:\/\/intelligentonlinetools.com\/cgi-bin\/analytics\/ml.cgi\" target=\"_balnk\"><strong>ML Sandbox<\/strong><\/a><br \/>\nAll that you need is just enter data into the data fields, here are the instructions:<\/p>\n<ol>\n<li>Go to <a href=\"http:\/\/intelligentonlinetools.com\/cgi-bin\/analytics\/ml.cgi\" target=\"_balnk\">ML Sandbox<\/a><\/li>\n<li>Select <em>Decision Classifier<\/em> OR <em>Decision Regressor<\/em> <\/li>\n<li>Enter data (first row should have headers) OR click &#8220;<em>Load Default Values<\/em>&#8221; to load the example data from this post. See screenshot below<\/li>\n<li>Click &#8220;<em>Run Now<\/em>&#8220;.<\/li>\n<li>Click &#8220;<em>View Run Results<\/em>&#8220;<\/li>\n<li>If you do not see yet data wait for a minute or so and click &#8220;<em>Refresh Page<\/em>&#8221; and you will see results<\/li>\n<p><strong>Note<\/strong>: your dependent variable (target variable or Y variable) should be in <strong>most right column<\/strong>. Also do not use space in the words (header and data)   <\/p>\n<p><strong>Conclusion<\/strong><br \/>\nDecision Trees belong to the top 10 machine learning or data mining algorithms and in this post we looked how to build Decision Trees with python. The source code provided is the end of this post. We looked also how do this if one or more columns are <strong>categorical<\/strong>. The source code was tested on simple categorical and numerical example and provided in this post. Alternatively you can run same algorithm <strong>online<\/strong> at  <a href=\"http:\/\/intelligentonlinetools.com\/cgi-bin\/analytics\/ml.cgi\" target=\"_balnk\">ML Sandbox<\/a>  <\/p>\n<p><strong>References<\/strong><\/p>\n<p>1. <a href=https:\/\/www.kdnuggets.com\/2017\/10\/top-10-machine-learning-algorithms-beginners.html target=\"_blank\">Top 10 Machine Learning Algorithms for Beginners<\/a><br \/>\n2. <a href=https:\/\/en.wikipedia.org\/wiki\/Decision_tree_learning target=\"_blank\">Decision Tree Learning<\/a><br \/>\n3. <a href=https:\/\/pandas.pydata.org\/pandas-docs\/stable\/generated\/pandas.get_dummies.html target=\"_blank\">pandas.get_dummies<\/a><\/p>\n<p>Here is the python computer code of the scripts.<br \/>\n<strong>DecisionTreeRegressor<\/strong> <\/p>\n<pre><code>\r\n# -*- coding: utf-8 -*python computer code-\r\n\r\nimport pandas as pd\r\nfrom sklearn.cross_validation import train_test_split\r\nfrom sklearn.tree import DecisionTreeRegressor\r\n\r\n\r\nimport subprocess\r\n\r\nfrom sklearn.tree import  export_graphviz\r\n\r\n\r\ndef visualize_tree(tree, feature_names):\r\n    \r\n    with open(\"dt.dot\", 'w') as f:\r\n        \r\n        export_graphviz(tree, out_file=f, feature_names=feature_names,  filled=True, rounded=True )\r\n\r\n    command = [\"C:\\\\Program Files (x86)\\\\Graphviz2.38\\\\bin\\\\dot.exe\", \"-Tpng\", \"C:\\\\Users\\\\Owner\\\\Desktop\\\\A\\\\Python_2016_A\\\\dt.dot\", \"-o\", \"dt.png\"]\r\n    \r\n        \r\n    try:\r\n        subprocess.check_call(command)\r\n    except:\r\n        exit(\"Could not run dot, ie graphviz, to \"\r\n             \"produce visualization\")\r\n    \r\n\r\n\r\n\r\n\r\nfilename = \"C:\\\\Users\\\\Owner\\\\Desktop\\\\A\\\\Blog Analytics\\\\data1.csv\"\r\ndataframe = pd.read_csv(filename, sep= ',' )\r\n\r\n\r\n\r\n\r\ncols = dataframe.columns.tolist()\r\nlast_col_header = cols[-1]\r\n\r\n\r\ndataframe=pd.get_dummies(dataframe)\r\ncols = dataframe.columns.tolist()\r\n\r\ncols.insert(len(dataframe.columns)-1, cols.pop(cols.index(last_col_header)))\r\ndataframe = dataframe.reindex(columns= cols)\r\n\r\nprint (dataframe)\r\n\r\n\r\n\r\narray = dataframe.values\r\nX = array[:,0:len(dataframe.columns)-1]  \r\nY = array[:,len(dataframe.columns)-1]   \r\nprint (\"--X----\")\r\nprint (X)\r\nprint (\"--Y----\")\r\nprint (Y)\r\n\r\n                       \r\nX_train, X_test, y_train, y_test = train_test_split( X, Y, test_size = 0.3, random_state = 100)                           \r\n                           \r\nclf = DecisionTreeRegressor( random_state = 100,\r\n                               max_depth=3, min_samples_leaf=4)\r\nclf.fit(X_train, y_train)   \r\n\r\nvisualize_tree(clf, dataframe.columns)\r\n<\/code><\/pre>\n<p><strong>DecisionTreeClassifier<\/strong><\/p>\n<pre><code>\r\n# -*- coding: utf-8 -*-\r\n\r\nimport pandas as pd\r\nfrom sklearn.cross_validation import train_test_split\r\nfrom sklearn.tree import DecisionTreeClassifier\r\n\r\nimport subprocess\r\n\r\nfrom sklearn.tree import  export_graphviz\r\n\r\n\r\ndef visualize_tree(tree, feature_names, class_names):\r\n    \r\n    with open(\"dt.dot\", 'w') as f:\r\n        \r\n        export_graphviz(tree, out_file=f, feature_names=feature_names,  filled=True, rounded=True, class_names=class_names )\r\n\r\n    command = [\"C:\\\\Program Files (x86)\\\\Graphviz2.38\\\\bin\\\\dot.exe\", \"-Tpng\", \"C:\\\\Users\\\\Owner\\\\Desktop\\\\A\\\\Python_2016_A\\\\dt.dot\", \"-o\", \"dt.png\"]\r\n    \r\n        \r\n    try:\r\n        subprocess.check_call(command)\r\n    except:\r\n        exit(\"Could not run dot, ie graphviz, to \"\r\n             \"produce visualization\")\r\n    \r\n\r\n\r\n\r\nvalues=[15,50,100]\r\ndef convert_to_label (a):\r\n    count=0\r\n    for v in values:\r\n        if (a <= v) :\r\n            return chr(ord('A') + count)\r\n        else:\r\n            count=count+1\r\n    \r\n    \r\nfilename = \"C:\\\\Users\\\\Owner\\\\Desktop\\\\A\\\\Blog Analytics\\\\data1.csv\"\r\ndataframe = pd.read_csv(filename, sep= ',' )\r\n\r\ncols = dataframe.columns.tolist()\r\nlast_col_header = cols[-1]\r\ndataframe=pd.get_dummies(dataframe)\r\ncols = dataframe.columns.tolist()\r\n\r\n\r\nprint (dataframe)\r\n\r\n\r\nfor index, row in dataframe.iterrows():\r\n       dataframe.loc[index, \"Y\"] = convert_to_label(dataframe.loc[index, \"Y\"])\r\n       \r\n      \r\n\r\ncols.insert(len(dataframe.columns)-1, cols.pop(cols.index('Y')))\r\ndataframe = dataframe.reindex(columns= cols)\r\n\r\nprint (dataframe)\r\n\r\narray = dataframe.values\r\nX = array[:,0:len(dataframe.columns)-1]  \r\nY = array[:,len(dataframe.columns)-1]   \r\nprint (\"--X----\")\r\nprint (X)\r\nprint (\"--Y----\")\r\nprint (Y)\r\n                       \r\nX_train, X_test, y_train, y_test = train_test_split( X, Y, test_size = 0.3, random_state = 100)                           \r\n                           \r\n\r\nclf = DecisionTreeClassifier(criterion = \"gini\", random_state = 100,\r\n                               max_depth=3, min_samples_leaf=4)\r\n\r\n\r\nclf.fit(X_train, y_train)   \r\n\r\nclm=dataframe[last_col_header]\r\nclmvalues = clm.unique()\r\nvisualize_tree(clf, dataframe.columns, clmvalues )\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>According to survey [1] Decision Trees constitute one of the 10 most popular data mining algorithms. Decision trees used in data mining are of two main types: Classification tree analysis is when the predicted outcome is the class to which the data belongs. Regression tree analysis is when the predicted outcome can be considered a &#8230; <a title=\"Regression and Classification Decision Trees &#8211; Building with Python and Running Online\" class=\"read-more\" href=\"http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[2,6,9,10],"tags":[33,32,18,35,27,34],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications<\/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:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications\" \/>\n<meta property=\"og:description\" content=\"According to survey [1] Decision Trees constitute one of the 10 most popular data mining algorithms. Decision trees used in data mining are of two main types: Classification tree analysis is when the predicted outcome is the class to which the data belongs. Regression tree analysis is when the predicted outcome can be considered a ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\" \/>\n<meta property=\"og:site_name\" content=\"Machine Learning Applications\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-23T02:09:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-30T01:57:25+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-300x283.png\" \/>\n<meta name=\"author\" content=\"owygs156\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"owygs156\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\",\"url\":\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\",\"name\":\"Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications\",\"isPartOf\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\"},\"datePublished\":\"2017-11-23T02:09:36+00:00\",\"dateModified\":\"2017-11-30T01:57:25+00:00\",\"author\":{\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478\"},\"breadcrumb\":{\"@id\":\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/intelligentonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Regression and Classification Decision Trees &#8211; Building with Python and Running Online\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#website\",\"url\":\"http:\/\/intelligentonlinetools.com\/blog\/\",\"name\":\"Machine Learning Applications\",\"description\":\"Artificial intelligence, data mining and machine learning for building web based tools and services.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478\",\"name\":\"owygs156\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g\",\"caption\":\"owygs156\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications","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:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/","og_locale":"en_US","og_type":"article","og_title":"Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications","og_description":"According to survey [1] Decision Trees constitute one of the 10 most popular data mining algorithms. Decision trees used in data mining are of two main types: Classification tree analysis is when the predicted outcome is the class to which the data belongs. Regression tree analysis is when the predicted outcome can be considered a ... Read more","og_url":"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/","og_site_name":"Machine Learning Applications","article_published_time":"2017-11-23T02:09:36+00:00","article_modified_time":"2017-11-30T01:57:25+00:00","og_image":[{"url":"http:\/\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/11\/decision_tree_11_2017-300x283.png"}],"author":"owygs156","twitter_card":"summary_large_image","twitter_misc":{"Written by":"owygs156","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/","url":"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/","name":"Regression and Classification Decision Trees - Building with Python and Running Online - Machine Learning Applications","isPartOf":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#website"},"datePublished":"2017-11-23T02:09:36+00:00","dateModified":"2017-11-30T01:57:25+00:00","author":{"@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478"},"breadcrumb":{"@id":"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/intelligentonlinetools.com\/blog\/2017\/11\/23\/regression-and-classification-decision-trees-building-with-python-and-running-online\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/intelligentonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Regression and Classification Decision Trees &#8211; Building with Python and Running Online"}]},{"@type":"WebSite","@id":"http:\/\/intelligentonlinetools.com\/blog\/#website","url":"http:\/\/intelligentonlinetools.com\/blog\/","name":"Machine Learning Applications","description":"Artificial intelligence, data mining and machine learning for building web based tools and services.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/intelligentonlinetools.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/7a886dc5eb9758369af2f6d2cb342478","name":"owygs156","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/intelligentonlinetools.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/b351def598609cb4c0b5bca26497c7e5?s=96&d=mm&r=g","caption":"owygs156"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7h1IJ-os","jetpack-related-posts":[{"id":975,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/02\/18\/building-decision-trees-in-python-handling-categorical-data\/","url_meta":{"origin":1516,"position":0},"title":"Building Decision Trees in Python &#8211; Handling Categorical Data","date":"February 18, 2017","format":false,"excerpt":"In the post Building Decision Trees in Python we looked at the decision tree with numerical continuous dependent variable. This type of decision trees can be called also regression tree. But what if we need to use categorical dependent variable? It is still possible to create decision tree and in\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/02\/dt-235x300.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":966,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/02\/18\/building-decision-trees-in-python\/","url_meta":{"origin":1516,"position":1},"title":"Building Decision Trees in Python","date":"February 18, 2017","format":false,"excerpt":"A decision tree is a decision support tool that uses a tree-like graph or model of decisions and their possible consequences, including chance event outcomes, resource costs, and utility. It is one way to display an algorithm. Decision trees are commonly used in operations research, specifically in decision analysis, to\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"Decision Tree","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2017\/02\/dt_post1_N_CTQ_Cost_regr1-2-use-this-300x103.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":993,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/02\/22\/converting-categorical-text-variable-into-binary-variables\/","url_meta":{"origin":1516,"position":2},"title":"Converting Categorical Text Variable into Binary Variables","date":"February 22, 2017","format":false,"excerpt":"Sometimes we might need convert categorical feature into multiple binary features. Such situation emerged while I was implementing decision tree with independent categorical variable using python sklearn.tree for the post Building Decision Trees in Python - Handling Categorical Data and it turned out that a text independent variable is not\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1446,"url":"http:\/\/intelligentonlinetools.com\/blog\/2017\/11\/06\/10-new-top-resources-on-machine-learning-from-around-the-web\/","url_meta":{"origin":1516,"position":3},"title":"10 New Top Resources on Machine Learning from Around the Web","date":"November 6, 2017","format":false,"excerpt":"For this post I put new and most interesting machine learning resources that I recently found on the web. This is the list of useful resources in such areas like stock market forecasting, text mining, deep learning, neural networks and getting data from Twitter. Hope you enjoy the reading. 1.\u2026","rel":"","context":"In &quot;Machine Learning&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2194,"url":"http:\/\/intelligentonlinetools.com\/blog\/2018\/08\/11\/applied-machine-learning-classification-for-decision-making\/","url_meta":{"origin":1516,"position":4},"title":"Applied Machine Learning Classification for Decision Making","date":"August 11, 2018","format":false,"excerpt":"Making the good decision is the challenge that we often have. So, in this post, we will look at how applied machine learning classification can be used for the process of decision making. The simple and quick approach to make decision is follow our past experience of similar situations. Usually\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"Decision Making","src":"https:\/\/i0.wp.com\/intelligentonlinetools.com\/blog\/wp-content\/uploads\/2018\/08\/signs-1172211_640-e1534384498570.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":621,"url":"http:\/\/intelligentonlinetools.com\/blog\/2016\/10\/09\/online-resources-for-neural-networks-with-python\/","url_meta":{"origin":1516,"position":5},"title":"Online Resources for Neural Networks with Python","date":"October 9, 2016","format":false,"excerpt":"The neural network field enjoys now a resurgence of interest. New training techniques made training deep networks feasible. With deeper networks, more training data and powerful new hardware to make it all work, deep neural networks (or \u201cdeep learning\u201d systems) suddenly began making rapid progress in areas such as speech\u2026","rel":"","context":"In &quot;Artificial Intelligence&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1516"}],"collection":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=1516"}],"version-history":[{"count":26,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1516\/revisions"}],"predecessor-version":[{"id":1562,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1516\/revisions\/1562"}],"wp:attachment":[{"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=1516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/categories?post=1516"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/intelligentonlinetools.com\/blog\/wp-json\/wp\/v2\/tags?post=1516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}