zoukankan      html  css  js  c++  java
  • 决策树预测活动类型

    import os
    import csv
    import random
    import numpy as np
    import pandas as pd
    from sklearn.cross_validation import cross_val_score
    os.chdir('E:\HumanActivity')
    #加载数据  
    data=pd.read_csv('test.csv',sep=',')
    print(data.ix[:5])
    #决策树预测活动类型
    from sklearn.tree import DecisionTreeClassifier
    clf = DecisionTreeClassifier(random_state=14) 
    x_previous = data[['timestamp','x','y','z']].values
    y_true = data['act_num'].values
    scores = cross_val_score(clf,x_previous,y_true,scoring='accuracy')
    print("决策树预测准确率: {0:1f}%".format(np.mean(scores) * 100))

    预测结果:

    决策树预测准确率: 40.238367%

    随机森林算法:

    from sklearn.ensemble import RandomForestClassifier
    clf = RandomForestClassifier(random_state=14)
    x_test = data[['timestamp','x','y','z']].values
    scores = cross_val_score(clf,x_test,y_true,scoring='accuracy')
    print("随机森林预测准确率: {0:1f}%".format(np.mean(scores) * 100))

    预测结果:

    随机森林预测准确率: 46.861539%

  • 相关阅读:
    @override报错
    idea快捷键
    java中getAttribute与getParameter的区别
    localStorage基于浏览器的本地存储
    js画布组件(<canvas></canvas>)
    easyui
    关于Bootstrap
    使用layUI美化的登录功能
    EXT JS
    ★一些文章链接
  • 原文地址:https://www.cnblogs.com/luban/p/9133884.html
Copyright © 2011-2022 走看看