zoukankan      html  css  js  c++  java
  • python机器学习-鸢尾花决策树

    决策树API

    • class sklearn.tree.DecisionTreeClassifier(criterion=’gini’, max_depth=None,random_state=None)
      • 决策树分类器
      • criterion:默认是’gini’系数,也可以选择信息增益的熵’entropy’
      • max_depth:树的深度大小
      • random_state:随机数种子
    • 其中会有些超参数:max_depth:树的深度大小
    #鸢尾花决策树
    def decision_iris():
        """
        用决策树对鸢尾花进行分类
        :return:
        """
        #获取数据集
        iris = load_iris()
        #划分数据集
        x_train,x_test,y_train,y_test=train_test_split(iris.data,iris.target,random_state=22)
        #决策树预估器
        estimator=DecisionTreeClassifier(criterion="entropy")#criterion默认为gini系数,此处选择的为信息增益的熵
        #max_depth:树深的大小,random_state:随机数种子
        estimator.fit(x_train,y_train)
        #模型评估
        y_predict=estimator.predict(x_test)
        print("y_predict:
    ",y_predict)
        print("直接对比真实值和预测值:
    ",y_test==y_predict)
        score=estimator.score(x_test,y_test)
        print("准确率为:
    ",score)
        #决策树可视化
        export_graphviz(estimator,out_file="iris_tree.dot")
  • 相关阅读:
    Laravel 出现 No application encryption key has been specified.
    windows下用composer局部安装laravel
    vue组件--通讯录
    vue组件--TagsInput
    axios封装(二)队列管理
    axios封装(一)基础配置
    [git hooks] pre-commit 配置
    qs.js
    flexbox的应用
    盒子模型详解
  • 原文地址:https://www.cnblogs.com/fengchuiguobanxia/p/15432562.html
Copyright © 2011-2022 走看看