首页 文章 精选 留言 我的

精选列表

搜索[代码生成],共10000篇文章
优秀的个人博客,低调大师

83行代码

使用SARIMAX进行时间序列预测。 #!/usr/bin/env python #-*-coding:utf-8-*- #****************************************************************************** #****************Description:Time Series prediction using SARIMAX #****************Author:Duan Tingyin #****************Date:2018.02.14 #************************************************** import pandas as pd import matplotlib.pyplot as plt import datetime from statsmodels.tsa.api import SARIMAX datapath = '../data/' train_df = pd.read_csv(datapath+'[new] yancheng_train_20171226.csv') testA_df = pd.read_csv(datapath+'yancheng_testA_20171225.csv') testB_df = pd.read_csv(datapath+'yancheng_testB_20180224.csv') train_class = train_df.groupby(['sale_date','class_id'])['sale_quantity'].sum().to_frame().reset_index() train_class.head() def plt_class(data,x,y,class_id): this_class_id=data[data.class_id == class_id] plt.scatter(x=this_class_id[x],y=this_class_id[y]) def trans_date(x): str_x=str(x) year=int(str_x[:4]) month=int(str_x[4:]) return datetime.date(year,month,1) train_class['_sale_date']=train_class['sale_date'].apply(trans_date) testA_df['_sale_date']=testA_df['predict_date'].apply(trans_date) testB_df['_sale_date']=testB_df['predict_date'].apply(trans_date) #print(train_class.head(),testA_df.head(),testB_df.head()) s="predict_date,class_id,predict_quantity" ex=[] f=open("../data/yancheng_testA_20171225.csv","r") for line in f.readlines(): if "date" in line: continue class_id=int(line.split(",")[1]) this_class_id=train_class[train_class['class_id']==class_id][['_sale_date','sale_quantity']] if class_id==653436: print(this_class_id._sale_date) #indexed_this_class_id = this_class_id.set_index(this_class_id['_sale_date']) indexed_this_class_id=this_class_id.set_index(pd.date_range(end='2017-11',periods=len(this_class_id['_sale_date']),freq='M')) print(this_class_id['_sale_date'],pd.date_range(end='2017-11',periods=len(this_class_id['_sale_date']),freq='M')) res=0 try: fit1=SARIMAX(indexed_this_class_id.sale_quantity,verbose=False).fit() pre=fit1.get_forecast().conf_int() res=(int(round((pre['lower sale_quantity'] + pre['upper sale_quantity'])*0.5))) except Exception as e: print(e) ex.append(class_id) plt_class(train_class,'sale_date','sale_quantity',class_id) res=int(this_class_id['sale_quantity'].iloc[-1]) this_class_id.to_csv('EXCEPTION'+str(class_id) +".csv",header=True,index=False,float_format='%.0f') s+="\n" s+="201711"+ ","+str(class_id) + "," +str(res) f.close() s+="\n" train_class[['sale_date','class_id','sale_quantity']].to_csv('train_class.csv',header=True,index=False,float_format='%.0f') fw=open("201711.csv","w") fw.write(s) fw.close() print(ex)

优秀的个人博客,低调大师

180行JavaScript代码实现的小球随机移动代码

<html> <body> <div id ='desc'><b>test1:</b>test2</div> <canvas id = 'canvas'></canvas> </body> <script> window.onload = init(); function init() { canvas = document.getElementById('canvas'); context = canvas.getContext('2d'); canvas.height = window.innerHeight; canvas.width = window.innerWidth; mouse = {x:0,y:0}; colors = [ '#af0','#7CD14E','#1CDCFF','#FFFF00','#FF0000','#aee137','#bef202','#00b2ff','#7fff24','#13cd4b','#c0fa38','#f0a','#a0f','#0af','#000000' ]; canvas.addEventListener('mousemove',MouseMove,false); canvas.addEventListener('mousedown',MouseDown,false); canvas.addEventListener('mouseup',MouseUp,false); window.addEventListener('resize',canvasResize,false); dotsHolder = []; mouseMove = false; mouseDown = false; for(i = 0;i < 100;i++){ dotsHolder.push(new dots()); } /*REQUEST ANIMATION FRAME*/ (function() { var lastTime = 0; var vendors = ['ms', 'moz', 'webkit', 'o']; for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; } if (window.requestAnimationFrame) window.requestAnimationFrame = function(callback, element) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); console.log("timetoCall : " + timeToCall); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); console.log("id: " + id); lastTime = currTime + timeToCall; console.log("last time: " + lastTime); //return id; }; if (!window.cancelAnimationFrame) window.cancelAnimationFrame = function(id) { clearTimeout(id); }; }()); } function canvasResize(event) { canvas.height = window.innerHeight; canvas.width = window.innerWidth; cancelAnimationFrame(animate); } function MouseUp(event) { if(mouseMove) { mouseMove = false;} if(mouseDown) { mouseDown = false; } } function MouseDown(event) { mouseDown = true; } function MouseMove(event) { mouse.x = event.pageX - canvas.offsetLeft; mouse.y = event.pageY - canvas.offsetTop; if(mouseMove) { context.lineTo(mouseX,mouseY); context.stroke(); } } function dots(){ this.xPos = Math.random()*canvas.width; this.yPos = Math.random()*canvas.height; this.color = colors[Math.floor(Math.random()*colors.length)]; this.radius = Math.random()*10; this.vx = Math.cos(this.radius); this.vy = Math.sin(this.radius); this.stepSize = Math.random() / 10; this.step = 0; this.friction = 7; this.speedX = this.vx; this.speedY = this.vy; } dots.draw = function() { context.clearRect(0,0,canvas.width,canvas.height); for(var c = 0; c < dotsHolder.length;c++) { dot = dotsHolder[c]; context.beginPath(); distanceX = dot.xPos - mouse.x; distanceY = dot.yPos - mouse.y; var particleDistance = Math.sqrt(distanceX*distanceX + distanceY*distanceY); var particleMouse = Math.max( Math.min( 75 / ( particleDistance /dot.radius ), 7 ), 1 ); context.fillStyle = dot.color; dot.xPos += dot.vx; dot.yPos += dot.vy; if(dot.xPos < -50) { dot.xPos = canvas.width+50; } if(dot.yPos < -50) { dot.yPos = canvas.height+50; } if(dot.xPos > canvas.width+50) { dot.xPos = -50; } if(dot.yPos > canvas.height+50) { dot.yPos = -50; } context.arc(dot.xPos,dot.yPos,(dot.radius/2.5)*particleMouse,0,2*Math.PI,false); //console.log("circle x: " + dot.xPos + " y: " + dot.yPos); context.fill(); if(mouseDown) { var minimumDistance = 164, distance = Math.sqrt((dot.xPos - mouse.x) * (dot.xPos - mouse.x) + (dot.yPos - mouse.y) * (dot.yPos - mouse.y)), distanceX = dot.xPos - mouse.x, distanceY = dot.yPos - mouse.y; if (distance < minimumDistance) { var forceFactor = minimumDistance / (distance * distance), xforce = (mouse.x - dot.xPos) % distance/7, yforce = (mouse.y - dot.yPos) % distance/dot.friction, forceField = forceFactor * 2/dot.friction; dot.vx -= forceField * xforce; dot.vy -= forceField * yforce; } if(dot.vx > dot.speed) { dot.vx = dot.speed/dot.friction; dot.vy = dot.speed/dot.friction; } else if (dot.vy > dot.speed) { dot.vy = dot.speed/dot.friction; } } } } function animate(){ requestAnimationFrame(animate); dots.draw(); } animate(); </script> </html> 鼠标单击小球后,会立即改变其移动方向和速度: 这是通过给canvas标签页注册的mousemove,mousedown响应函数实现的: 本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册