「java实现预测算法」java数据预测

博主:adminadmin 2023-01-09 04:42:06 661

本篇文章给大家谈谈java实现预测算法,以及java数据预测对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java伪随机数是否有可以预测的方法?

只要知道了种子,就能预测了

java的伪随机数的生成完全依赖于种子

如果有相同的种子,那么生成的伪随机数序列就会相同

Matlab实现或者java编程实现 神经网络 灰色模型预测

灰色预测模型为GM(1,1)

灰参数a和u的值:

a=-0.0323252892223847 u=14042.3315313962

原始序列预测值:

13205 14705 15188 15687 16203 16735 17285 17853 18439 19045

累加序列预测值:

14705 15188 15687 16203 16735 17285 17853 18439 19045 19671

级比值:

0.933017734755882 0.991731483427931 0.906095238095238 0.951546640889319 0.951264367816092 0.952798160113898 0.980668027064762 0.994977559307544 1.07637451115712

相对误差值:

0 3.90438540431923 6.43063985387993 0.395441255218115 2.10782203579584 3.81930406598348 5.34849588953024 4.12878515843797 1.47641388551927 0.5323261370569

2013-2017年的预测值

2013 20317.4561851648

2014 20984.954243779

2015 21674.381900971

2016 22386.4596192006

2017 23121.9315305897

怎么用java实现apriori算法

作者:何史提

链接:

来源:知乎

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Apriori算法的理念其实很简单,可是实现起上来却复杂无比,因为当中无可避免用Set和Hash Table等高阶的数据结构,而且有很多loop用以读取数据。

我不建议用Java,应改用Python或Scala一类的语言。如果用Python,代码大概50行左右,但可以想像用Java便看起来复杂得多。看如下:

from operator import and_

from itertools import combinations

class AprioriAssociationRule:

def __init__(self, inputfile):

self.transactions = []

self.itemSet = set([])

inf = open(inputfile, 'rb')

for line in inf.readlines():

elements = set(filter(lambda entry: len(entry)0, line.strip().split(',')))

if len(elements)0:

self.transactions.append(elements)

for element in elements:

self.itemSet.add(element)

inf.close()

self.toRetItems = {}

self.associationRules = []

def getSupport(self, itemcomb):

if type(itemcomb) != frozenset:

itemcomb = frozenset([itemcomb])

within_transaction = lambda transaction: reduce(and_, [(item in transaction) for item in itemcomb])

count = len(filter(within_transaction, self.transactions))

return float(count)/float(len(self.transactions))

def runApriori(self, minSupport=0.15, minConfidence=0.6):

itemCombSupports = filter(lambda freqpair: freqpair[1]=minSupport,

map(lambda item: (frozenset([item]), self.getSupport(item)), self.itemSet))

currentLset = set(map(lambda freqpair: freqpair[0], itemCombSupports))

k = 2

while len(currentLset)0:

currentCset = set([i.union(j) for i in currentLset for j in currentLset if len(i.union(j))==k])

currentItemCombSupports = filter(lambda freqpair: freqpair[1]=minSupport,

map(lambda item: (item, self.getSupport(item)), currentCset))

currentLset = set(map(lambda freqpair: freqpair[0], currentItemCombSupports))

itemCombSupports.extend(currentItemCombSupports)

k += 1

for key, supportVal in itemCombSupports:

self.toRetItems[key] = supportVal

self.calculateAssociationRules(minConfidence=minConfidence)

def calculateAssociationRules(self, minConfidence=0.6):

for key in self.toRetItems:

subsets = [frozenset(item) for k in range(1, len(key)) for item in combinations(key, k)]

for subset in subsets:

confidence = self.toRetItems[key] / self.toRetItems[subset]

if confidence minConfidence:

self.associationRules.append([subset, key-subset, confidence])

关于java实现预测算法和java数据预测的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。