print(__doc__) # Import the necessary modules and libraries import numpy as np import time from sklearn.tree import DecisionTreeClassifier import matplotlib.pyplot as plt import math from sklearn.metrics import precision_recall_curve from sklearn.metrics import classification_report from sklearn import tree #set depth and node method for decision tree def depthAndNode(dataSet): n = np.shape(dataSet)[0] depth = 6 node = 1000 if n >= 1000000000: depth = 20 elif n >= 1000000 and n < 1000000000: depth = math.floor(math.log(n / 1000, 2)) elif n < 1000000: depth_1 = math.log(n / 250, 2) depth_2 = math.log(n / 1000, 2) depth_min = math.floor(min(depth_1, depth_2)) node = 250 if depth_min < 6: depth = 6
sklearn决策树 DecisionTreeClassifier建立模型, 导出模型, 读取
最新推荐文章于 2024-03-20 19:30:28 发布
本文演示了如何使用sklearn的DecisionTreeClassifier建立决策树模型,通过调整参数如最大深度和节点数。然后,模型被训练并保存为.dot文件和pickle文件,以便后续使用。此外,还展示了如何加载模型并进行预测,验证了模型的准确性。
摘要由CSDN通过智能技术生成