科学经得起实践检验-python3.6通过决策树实战精准准确预测今日大盘走势(含代码)

本文主要是介绍科学经得起实践检验-python3.6通过决策树实战精准准确预测今日大盘走势(含代码),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

科学经得起实践检验-python3.6通过决策树实战精准准确预测今日大盘走势(含代码)




春有百花秋有月,夏有凉风冬有雪;

若无闲事挂心头,便是人间好时节。

  

  --宋.无门慧开


不废话了,以下训练模型数据,采用本人发明的极致800实时指数近期的一些实际数据,

预测采用今日的真实数据

#coding=utf-8
__author__ = 'huangzhi'

import math
import operatordef calcShannonEnt(dataset):numEntries = len(dataset)labelCounts = {}for featVec in dataset:currentLabel = featVec[-1]if currentLabel not in labelCounts.keys():labelCounts[currentLabel] = 0
        labelCounts[currentLabel] += 1

    shannonEnt = 0.0
    for key in labelCounts:prob = float(labelCounts[key]) / numEntriesshannonEnt -= prob * math.log(prob, 2)return shannonEntdef CreateDataSet():# dataset = [[1, 1, 'yes'],
    #            [1, 1, 'yes'],
    #            [1, 0, 'no'],
    #            [0, 1, 'no'],
    #            [0, 1, 'no']]

    dataset = [[3, 4, 100, 85, 4, 6, 110, 120, 4, 6, 151, 122, 8, 12, 110, 185, ''],[5, 7, 88, 85, 6, 8, 100, 130, 6, 9, 131, 132, 8, 14, 100, 195, ''],[6, 2, 60, 20, 9, 3, 80, 22, 16, 4, 131, 32, 33, 5, 160, 45, ''],[3, 4, 100, 105, 4, 6, 110, 120, 4, 6, 151, 122, 8, 12, 110, 185, ''],[5, 3, 50, 30, 8, 4, 70, 28, 12, 6, 101, 42, 28, 7, 120, 35, ''],[2, 6, 60, 95, 4, 8, 90, 130, 6, 11, 101, 142, 9, 15, 99, 145, ''],[5, 3, 70, 30, 8, 4, 90, 32, 22, 6, 141, 42, 43, 8, 150, 65, ''],[2, 8, 30, 60, 9, 8, 80, 90, 9, 20, 140, 160, 12, 32, 101, 205, '']]labels = ['l1', 'l2', 'l3', 'l4', 'l5', 'l6', 'l7', 'l8', 'l9', 'l11', 'l12', 'l13', 'l14', 'l15', 'l16', 'l17']return dataset, labelsdef splitDataSet(dataSet, axis, value):retDataSet = []for featVec in dataSet:if featVec[axis] == value:reducedFeatVec = featVec[:axis]reducedFeatVec.extend(featVec[axis + 1:])retDataSet.append(reducedFeatVec)return retDataSetdef chooseBestFeatureToSplit(dataSet):numberFeatures = len(dataSet[0]) - 1
    baseEntropy = calcShannonEnt(dataSet)bestInfoGain = 0.0;bestFeature = -1;for i in range(numberFeatures):featList = [example[i] for example in dataSet]# print(featList)
        uniqueVals = set(featList)# print(uniqueVals)
        newEntropy = 0.0
        for value in uniqueVals:subDataSet = splitDataSet(dataSet, i, value)prob = len(subDataSet) / float(len(dataSet))newEntropy += prob * calcShannonEnt(subDataSet)infoGain = baseEntropy - newEntropyif (infoGain > bestInfoGain):bestInfoGain = infoGainbestFeature = ireturn bestFeaturedef majorityCnt(classList):classCount = {}for vote in classList:if vote not in classCount.keys():classCount[vote] = 0
        classCount[vote] = 1
    sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True)return sortedClassCount[0][0]def createTree(dataSet, inputlabels):labels = inputlabels[:]classList = [example[-1] for example in dataSet]if classList.count(classList[0]) == len(classList):return classList[0]if len(dataSet[0]) == 1:return majorityCnt(classList)bestFeat = chooseBestFeatureToSplit(dataSet)bestFeatLabel = labels[bestFeat]myTree = {bestFeatLabel: {}}del (labels[bestFeat])featValues = [example[bestFeat] for example in dataSet]uniqueVals = set(featValues)for value in uniqueVals:subLabels = labels[:]myTree[bestFeatLabel][value] = createTree(splitDataSet(dataSet, bestFeat, value), subLabels)return myTreedef classify(inputTree, featLabels, testVec):firstStr = list(inputTree.keys())[0]secondDict = inputTree[firstStr]featIndex = featLabels.index(firstStr)for key in secondDict.keys():if testVec[featIndex] == key:if type(secondDict[key]).__name__ == 'dict':classLabel = classify(secondDict[key], featLabels, testVec)else:classLabel = secondDict[key]return classLabelmyDat, labels = CreateDataSet()
# print(calcShannonEnt(myDat))

# print(splitDataSet(myDat, 1, 1))

# print(chooseBestFeatureToSplit(myDat))

myTree = createTree(myDat, labels)#通过早上9:41分的实际数据进行预测
print(classify(myTree, labels, [1, 6, 156, 169, 1, 6, 156, 169, 1, 6, 156, 169, 1, 6, 156, 169]))
#通过早上10:41分的实际数据进行预测
print(classify(myTree, labels, [1, 6, 156, 169, 4, 9, 129, 263, 4, 9, 129, 263, 4, 9, 129, 263]))
#通过下午13:41分的实际数据进行预测
print(classify(myTree, labels, [1, 6, 156, 169, 4, 9, 129, 263, 5, 12, 123, 306, 5, 12, 123, 306]))
#通过下午14:41分的实际数据进行预测
print(classify(myTree, labels, [1, 6, 156, 169, 4, 9, 129, 263, 5, 12, 123, 306, 6, 13, 99, 397]))
 
 
运行结果如下:
D:\Programs\Python\Python36-64\python.exe D:/pyfenlei/决策树/jcs4.py
跌
跌
跌
跌

这篇关于科学经得起实践检验-python3.6通过决策树实战精准准确预测今日大盘走势(含代码)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/554323

相关文章

LangChain转换链:让数据处理更精准

1. 转换链的概念 在开发AI Agent(智能体)时,我们经常需要对输入数据进行预处理,这样可以更好地利用LLM。LangChain提供了一个强大的工具——转换链(TransformChain),它可以帮我们轻松实现这一任务。 转换链(TransformChain)主要是将 给定的数据 按照某个函数进行转换,再将 转换后的结果 输出给LLM。 所以转换链的核心是:根据业务逻辑编写合适的转换函

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

C++必修:模版的入门到实践

✨✨ 欢迎大家来到贝蒂大讲堂✨✨ 🎈🎈养成好习惯,先赞后看哦~🎈🎈 所属专栏:C++学习 贝蒂的主页:Betty’s blog 1. 泛型编程 首先让我们来思考一个问题,如何实现一个交换函数? void swap(int& x, int& y){int tmp = x;x = y;y = tmp;} 相信大家很快就能写出上面这段代码,但是如果要求这个交换函数支持字符型

公共筛选组件(二次封装antd)支持代码提示

如果项目是基于antd组件库为基础搭建,可使用此公共筛选组件 使用到的库 npm i antdnpm i lodash-esnpm i @types/lodash-es -D /components/CommonSearch index.tsx import React from 'react';import { Button, Card, Form } from 'antd'

17.用300行代码手写初体验Spring V1.0版本

1.1.课程目标 1、了解看源码最有效的方式,先猜测后验证,不要一开始就去调试代码。 2、浓缩就是精华,用 300行最简洁的代码 提炼Spring的基本设计思想。 3、掌握Spring框架的基本脉络。 1.2.内容定位 1、 具有1年以上的SpringMVC使用经验。 2、 希望深入了解Spring源码的人群,对 Spring有一个整体的宏观感受。 3、 全程手写实现SpringM

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测 目录 时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测基本介绍程序设计参考资料 基本介绍 MATLAB实现LSTM时间序列未来多步预测-递归预测。LSTM是一种含有LSTM区块(blocks)或其他的一种类神经网络,文献或其他资料中LSTM区块可能被描述成智能网络单元,因为

亮相WOT全球技术创新大会,揭秘火山引擎边缘容器技术在泛CDN场景的应用与实践

2024年6月21日-22日,51CTO“WOT全球技术创新大会2024”在北京举办。火山引擎边缘计算架构师李志明受邀参与,以“边缘容器技术在泛CDN场景的应用和实践”为主题,与多位行业资深专家,共同探讨泛CDN行业技术架构以及云原生与边缘计算的发展和展望。 火山引擎边缘计算架构师李志明表示:为更好地解决传统泛CDN类业务运行中的问题,火山引擎边缘容器团队参考行业做法,结合实践经验,打造火山

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

代码随想录算法训练营:12/60

非科班学习算法day12 | LeetCode150:逆波兰表达式 ,Leetcode239: 滑动窗口最大值  目录 介绍 一、基础概念补充: 1.c++字符串转为数字 1. std::stoi, std::stol, std::stoll, std::stoul, std::stoull(最常用) 2. std::stringstream 3. std::atoi, std

记录AS混淆代码模板

开启混淆得先在build.gradle文件中把 minifyEnabled false改成true,以及shrinkResources true//去除无用的resource文件 这些是写在proguard-rules.pro文件内的 指定代码的压缩级别 -optimizationpasses 5 包明不混合大小写 -dontusemixedcaseclassnames 不去忽略非公共