In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to share with you the relevant knowledge points about how to achieve Python classification prediction based on decision tree algorithm. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.
First, the characteristics of decision tree 1. Advantages
With good explanation, the model can generate rules that can be understood.
The importance of the feature can be found.
The computational complexity of the model is low.
two。 Shortcoming
The model is easy to be over-fitted and needs to be treated by branch reduction technique.
Can not make good use of continuous features.
The prediction ability is limited and can not achieve the effect of other strong supervision models.
The variance is high, and the slight change of data distribution can easily lead to a completely different tree structure.
Second, the applicable scenarios of the decision tree
Decision tree model is mostly used to deal with the nonlinear relationship between independent variables and dependent variables.
Advanced integrated models such as gradient lifting tree (GBDT), XGBoost and LightGBM all use decision tree as the basis model. (multi-grain linked forest model)
Decision trees are widely used in scenarios where interpretable or extracted classification rules are clearly needed. In order to make it convenient for professionals to find errors in the medical assistant system, the decision tree algorithm is often used to assist disease detection.
3. Demo#%%demo## basic function library import import numpy as np # # Import picture library import matplotlib.pyplot as pltimport seaborn as sns## import decision tree model function from sklearn.tree import DecisionTreeClassifierfrom sklearn import treeimport pydotplus from IPython.display import Image##Demo demo DecisionTree classification # # construct dataset x_fearures = np.array ([[- 1,-2], [- 2,-1], [- 3,-2], [1, 3], [2] 1], [3,2]) y_label = np.array ([0,1,0,1,0,1]) # # call decision tree regression model tree_clf = DecisionTreeClassifier () # # call data set constructed by decision tree model fitting tree_clf = tree_clf.fit (x_fearures, y_label) # # visually constructed data sample point plt.figure () plt.scatter (x_fearures [:, 0], x_fearures [:, 1] C=y_label, Dataset' 50, cmap='viridis') plt.title ('Dataset') plt.show () # # Visual decision tree import graphvizdot_data = tree.export_graphviz (tree_clf, out_file=None) graph = pydotplus.graph_from_dot_data (dot_data) graph.write_pdf ("D:\ Python\ ML\ DecisionTree.pdf") # Model Forecast # # create a new sample x_fearures_new1 = np.array ([[0]) -1]]) x_fearures_new2 = np.array ([[2,1]]) # # Distribution on the training set and test set using the trained model to predict y_label_new1_predict = tree_clf.predict (x_fearures_new1) y_label_new2_predict = tree_clf.predict (x_fearures_new2) print ('The New point 1 predict class:\ nSynergistic labelial new1traint) print (' The New point 2 predict class:\ n') Y_label_new2_predict)
Running result
Training set decision tree
These are all the contents of the article "how to realize Python classification prediction based on decision tree algorithm". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.