当前位置: 首页 > news >正文

vps主机可以做几个网站唐山公司做网站

vps主机可以做几个网站,唐山公司做网站,WordPress实现微信一键登录,服务器是干什么用的1. 项目背景 本文基于kaggle平台相关竞赛项目,具体连接如下: Time Series Forecasting With SARIMAX 基本信息如内容说明、数据集、已提交代码、当前得分排名以及比赛规则等,如图【1】所示,可以认真阅读。 图 1 2. 数据读取 …

1. 项目背景

本文基于kaggle平台相关竞赛项目,具体连接如下:

Time Series Forecasting With SARIMAX

基本信息如内容说明、数据集、已提交代码、当前得分排名以及比赛规则等,如图【1】所示,可以认真阅读。

图 1

2. 数据读取

使用python得pandas包进行csv文件读取

# read train data
df = pd.read_csv("/kaggle/input/daily-climate-time-series-data/DailyDelhiClimateTrain.csv", parse_dates=['date'],  # change to date time formatindex_col="date")
df

2.1 数据信息图形化观测

定义图表模板,对不同维度的数据进行图形化分析。

# Get the 'xgridoff' template
grid_template = pio.templates['xgridoff']
grid_template.layout.font.color = 'black'  # Light gray font color# Adjust gridline color and width
grid_template.layout.xaxis.gridcolor = 'rgba(0, 0, 0, 0.3)'  # Light gray with transparency
grid_template.layout.yaxis.gridcolor = 'rgba(0, 0, 0, 0.3)'  # Light gray with transparency
grid_template.layout.xaxis.gridwidth = 1  # Set gridline width
grid_template.layout.yaxis.gridwidth = 1  # Set gridline width# Update Plotly templates with template
pio.templates['ts_template'] = grid_template# plot mean temperature, humidity, wind_speed, meanpressure for watch
fig_meantemp = px.line(df, x=df.index, y='meantemp', title='Mean Temperature Over Time')
fig_meantemp.update_layout(template='ts_template', title_x=0.5, xaxis_title="Date")
fig_meantemp.show()fig_humidity = px.line(df, x=df.index, y='humidity', title='Humidity Over Time')
fig_humidity.update_layout(template='ts_template', title_x=0.5, xaxis_title="Date")
fig_humidity.show()fig_wind_speed = px.line(df, x=df.index, y='wind_speed', title='Wind Speed Over Time')
fig_wind_speed.update_layout(template='ts_template', title_x=0.5, xaxis_title="Date")
fig_wind_speed.show()fig_meanpressure = px.line(df, x=df.index, y='meanpressure', title='Mean Pressure Over Time')
fig_meanpressure.update_layout(template='ts_template', title_x=0.5, xaxis_title="Date")
fig_meanpressure.show()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
可以从图中看到平均温度,湿度,风速,气压等数据波形图,也可以宏观的看到数据的趋势信息,为后续进一步学习做初步探索。

2.3 数据分量

针对预测数据项平均温度,我们可以分解平均温度数据,进一步分析数据形态、特征。seasonal_decompose函数返回的是trend、seasonal和residual分别表示趋势、季节性和残留三部分的数据,observed代表原始序列。

from statsmodels.tsa.seasonal import seasonal_decompose
import plotly.subplots as sp# Perform seasonal decomposition
result = seasonal_decompose(df['meantemp'], model='additive', period=365)# Plot the decomposed components
fig = sp.make_subplots(rows=4, cols=1, shared_xaxes=True, subplot_titles=['Observed', 'Trend', 'Seasonal', 'Residual'])fig.add_trace(go.Scatter(x=df.index, y=result.observed, mode='lines', name='Observed'), row=1, col=1)
fig.add_trace(go.Scatter(x=df.index, y=result.trend, mode='lines', name='Trend'), row=2, col=1)
fig.add_trace(go.Scatter(x=df.index, y=result.seasonal, mode='lines', name='Seasonal'), row=3, col=1)
fig.add_trace(go.Scatter(x=df.index, y=result.resid, mode='lines', name='Residual'), row=4, col=1)fig.update_layout(template= 'ts_template',height=800, title='Seasonal Decomposition of Mean Temperature')
fig.show()

在这里插入图片描述
从图中可以看出,平均温度数据具有很强的季节性,趋势是逐渐升高的,但是受噪音影响有限。

2.4 特征选取

基于以上数据形态观测和分析,我们可以大致选定数据中的部分特征作为影响平均温度的因素(特征信息),这里就选定湿度和风速作为特征信息进行训练和预测。

df = df[['meantemp', 'humidity', 'wind_speed']]
df.head()

2.5 归一化

from sklearn.preprocessing import RobustScaler, MinMaxScalerrobust_scaler = RobustScaler()   # scaler for wind_speed
minmax_scaler = MinMaxScaler()  # scaler for humidity
target_transformer = MinMaxScaler()   # scaler for target (meantemp)dl_train['wind_speed'] = robust_scaler.fit_transform(dl_train[['wind_speed']])  # robust for wind_speed
dl_train['humidity'] = minmax_scaler.fit_transform(dl_train[['humidity']]) # minmax for humidity
dl_train['meantemp'] = target_transformer.fit_transform(dl_train[['meantemp']]) # targetdl_test['wind_speed'] = robust_scaler.transform(dl_test[['wind_speed']])
dl_test['humidity'] = minmax_scaler.transform(dl_test[['humidity']])
dl_test['meantemp'] = target_transformer.transform(dl_test[['meantemp']])display(dl_train.head())

3. 序列稳定性验证

import statsmodels.api as sm
from statsmodels.tsa.stattools import adfuller, kpssdef check_stationarity(series):print(f'\n___________________Checking Stationarity for: {series.name}___________________\n')# ADF Testadf_test = adfuller(series.values)print('ADF Test:\n')print('ADF Statistic: %f' % adf_test[0])print('p-value: %f' % adf_test[1])print('Critical Values:')for key, value in adf_test[4].items():print('\t%s: %.3f' % (key, value))if (adf_test[1] <= 0.05) & (adf_test[4]['5%'] > adf_test[0]):print("\u001b[32mSeries is Stationary (ADF Test)\u001b[0m")else:print("\x1b[31mSeries is Non-stationary (ADF Test)\x1b[0m")print('\n' + '-'*50 + '\n')# KPSS Testkpss_test = kpss(series.values, regression='c', nlags='auto')print('KPSS Test:\n')print('KPSS Statistic: %f' % kpss_test[0])print('p-value: %f' % kpss_test[1])print('Critical Values:')for key, value in kpss_test[3].items():print('\t%s: %.3f' % (key, value))if kpss_test[1] > 0.05:print("\u001b[32mSeries is Stationary (KPSS Test)\u001b[0m")else:print("\x1b[31mSeries is Non-stationary (KPSS Test)\x1b[0m")

那么我们就可以针对选取的特征进行稳定性分析。

# Check initial stationarity for each feature
check_stationarity(df['meantemp'])
check_stationarity(df['humidity'])
check_stationarity(df['wind_speed'])
___________________Checking Stationarity for: meantemp___________________ADF Test:ADF Statistic: -2.021069
p-value: 0.277412
Critical Values:1%: -3.4355%: -2.86410%: -2.568
Series is Non-stationary (ADF Test)--------------------------------------------------KPSS Test:KPSS Statistic: 0.187864
p-value: 0.100000
Critical Values:10%: 0.3475%: 0.4632.5%: 0.5741%: 0.739
Series is Stationary (KPSS Test)___________________Checking Stationarity for: humidity___________________ADF Test:ADF Statistic: -3.675577
p-value: 0.004470
Critical Values:1%: -3.4355%: -2.86410%: -2.568
Series is Stationary (ADF Test)--------------------------------------------------KPSS Test:KPSS Statistic: 0.091737
p-value: 0.100000
Critical Values:10%: 0.3475%: 0.4632.5%: 0.5741%: 0.739
Series is Stationary (KPSS Test)___________________Checking Stationarity for: wind_speed___________________ADF Test:ADF Statistic: -3.838097
p-value: 0.002541
Critical Values:1%: -3.4355%: -2.86410%: -2.568
Series is Stationary (ADF Test)--------------------------------------------------KPSS Test:KPSS Statistic: 0.137734
p-value: 0.100000
Critical Values:10%: 0.3475%: 0.4632.5%: 0.5741%: 0.739
Series is Stationary (KPSS Test)

可以看到平均温度是不稳定的,那么就需要进行差分处理。具体什么是差分及差分阶数请自行查阅。

# 1st degree differencing
df['meantemp_diff'] = df['meantemp'].diff().fillna(0)  # diff() default is 1st degree differencing 
check_stationarity(df['meantemp_diff']);
___________________Checking Stationarity for: meantemp_diff___________________ADF Test:ADF Statistic: -16.294070
p-value: 0.000000
Critical Values:1%: -3.4355%: -2.86410%: -2.568
Series is Stationary (ADF Test)--------------------------------------------------KPSS Test:KPSS Statistic: 0.189493
p-value: 0.100000
Critical Values:10%: 0.3475%: 0.4632.5%: 0.5741%: 0.739
Series is Stationary (KPSS Test)

3. 模型训练和预测

# Split the data into training and testing sets
train_size = int(len(df) * 0.8)
train, test = df.iloc[:train_size], df.iloc[train_size:]
# SARIMAXfrom statsmodels.tsa.statespace.sarimax import SARIMAX
from sklearn.metrics import mean_squared_error, r2_score, mean_absolute_error# Define the SARIMA model parameters
order = (1, 1, 6)  # Non-seasonal order (p, d, q)
seasonal_order = (1, 1, 1, 7)  # Seasonal order (P, D, Q, S)  # Fit the SARIMA model
sarima_model = SARIMAX(endog=train['meantemp'], exog=train[['humidity', 'wind_speed']],order=order, seasonal_order=seasonal_order)
sarima_model_fit = sarima_model.fit()# Make predictions
sarima_pred = sarima_model_fit.predict(start=test.index[0], end=test.index[-1],exog=test[['humidity', 'wind_speed']])# Calculate error
mse = mean_squared_error(test['meantemp'], sarima_pred)
r2 = r2_score(test['meantemp'], sarima_pred)
print('Test MSE:', mse)
print('Test R²: %.3f' % r2)# Plot the results
plt.figure(figsize=(10, 5))
plt.plot(test.index, test['meantemp'], label='Actual')
plt.plot(test.index, sarima_pred, color='red', label='SARIMA Forecast')
plt.xlabel('Date')
plt.ylabel('Meantemp')
plt.title('SARIMA Forecast')
plt.legend()
plt.show()

在这里插入图片描述
如上图所示,可以看到实际数据和预测数据的曲线图,从图中可以看到,预测值与实际值之间存在较大gap,这就说明模型泛化能力不好,对未来数据不能很好的预测。这就需要我们对模型参数进行调整,以期达到更好的效果。当然有些是受限于模型本身的局限性,始终无法对数据做出合理预测,那就需要我们寻找其他的模型,比如RNN、CNN、LSTM等更强大的深度学习模型来进行训练和预测。

参考文档

  1. ARIMA Model for Time Series Forecasting
  2. 季节性ARIMA模型
  3. https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average

如有侵权,烦请联系删除


文章转载自:
http://clarionet.xkzr.cn
http://continency.xkzr.cn
http://articulator.xkzr.cn
http://behaviourism.xkzr.cn
http://supereminence.xkzr.cn
http://sulphite.xkzr.cn
http://heliotropism.xkzr.cn
http://sanforized.xkzr.cn
http://piteous.xkzr.cn
http://twitter.xkzr.cn
http://commissariat.xkzr.cn
http://provokable.xkzr.cn
http://geophone.xkzr.cn
http://meningitis.xkzr.cn
http://binuclear.xkzr.cn
http://outdrink.xkzr.cn
http://sakellaridis.xkzr.cn
http://nmu.xkzr.cn
http://fishmonger.xkzr.cn
http://layfolk.xkzr.cn
http://indrawing.xkzr.cn
http://momento.xkzr.cn
http://escribe.xkzr.cn
http://animalism.xkzr.cn
http://cotylosaur.xkzr.cn
http://unlade.xkzr.cn
http://fledgeling.xkzr.cn
http://radarscope.xkzr.cn
http://circumspectly.xkzr.cn
http://wafs.xkzr.cn
http://frizzy.xkzr.cn
http://cryptobiosis.xkzr.cn
http://suppository.xkzr.cn
http://pretext.xkzr.cn
http://slickness.xkzr.cn
http://kithe.xkzr.cn
http://habitus.xkzr.cn
http://flare.xkzr.cn
http://budget.xkzr.cn
http://gasify.xkzr.cn
http://glorification.xkzr.cn
http://allodial.xkzr.cn
http://portwine.xkzr.cn
http://melanite.xkzr.cn
http://spell.xkzr.cn
http://newsstand.xkzr.cn
http://driftingly.xkzr.cn
http://nonacceptance.xkzr.cn
http://plantsman.xkzr.cn
http://tetrapolis.xkzr.cn
http://subsoil.xkzr.cn
http://autocephaly.xkzr.cn
http://telecom.xkzr.cn
http://piraeus.xkzr.cn
http://hanoi.xkzr.cn
http://geognosy.xkzr.cn
http://collator.xkzr.cn
http://electromagnet.xkzr.cn
http://sporotrichosis.xkzr.cn
http://memorization.xkzr.cn
http://idemfactor.xkzr.cn
http://aerobiotic.xkzr.cn
http://hydrofoil.xkzr.cn
http://coinage.xkzr.cn
http://googolplex.xkzr.cn
http://oriana.xkzr.cn
http://azoospermia.xkzr.cn
http://vested.xkzr.cn
http://nizamate.xkzr.cn
http://strongyloid.xkzr.cn
http://toggle.xkzr.cn
http://permanently.xkzr.cn
http://rijeka.xkzr.cn
http://ostracean.xkzr.cn
http://mrcs.xkzr.cn
http://respectability.xkzr.cn
http://scummy.xkzr.cn
http://thews.xkzr.cn
http://commis.xkzr.cn
http://roading.xkzr.cn
http://fishable.xkzr.cn
http://woods.xkzr.cn
http://shogunate.xkzr.cn
http://carboxylate.xkzr.cn
http://cosmographer.xkzr.cn
http://beautyberry.xkzr.cn
http://overture.xkzr.cn
http://haulage.xkzr.cn
http://yerkish.xkzr.cn
http://unordinary.xkzr.cn
http://attitudinarian.xkzr.cn
http://varlet.xkzr.cn
http://abruption.xkzr.cn
http://zomba.xkzr.cn
http://chamfron.xkzr.cn
http://abducens.xkzr.cn
http://beneficent.xkzr.cn
http://subtractive.xkzr.cn
http://craniad.xkzr.cn
http://nonliving.xkzr.cn
http://www.15wanjia.com/news/59500.html

相关文章:

  • 做公务员考试哪个网站好网络营销产品推广方案
  • 做药品网站有哪些aso榜单优化
  • 鄱阳有做百度网站的热搜榜排名今日第一
  • 企业年金的作用及意义搜索引擎优化怎么做的
  • 巨野县建设局网站微博付费推广有用吗
  • 网站实例如何建立自己的网站?
  • 怎么用net123做网站网络推广计划书范文
  • 相机拍照的图片怎么做网站呀seo建站技巧
  • 中国招标网官方网站智慧软文发布系统
  • 网站制作经典案例百度提交入口网址截图
  • 做3d地形比较好的网站对网站和网页的认识
  • 做国外销售都上什么网站如何搭建企业网站
  • 网站设计培训成都抖音推广公司
  • 网站建设需要条件上海网络seo公司
  • 网站开发网站制作seo关键词优化软件官网
  • 优良的定制网站建设百度浏览器官网入口
  • 网站运营思路快速优化seo
  • 网站美工建设软件下载情感营销案例
  • 深圳专业商城网站制作全球搜索
  • 如何自己做购物网站全国最新疫情最新消息
  • 装饰公司营销网站模板优化网站建设seo
  • 如何做中英切换的网站91手机用哪个浏览器
  • 无锡做装修网站百度网站关键词排名查询
  • 自己做视频网站只能用地址连接公司网站设计要多少钱
  • wordpress网站流量网页设计网站建设
  • 网站开发和上传中错误的是怎么建立网站?
  • 网站建设基础与实践seo企业建站系统
  • 网站运营做哪些工作呢百度精准引流推广
  • 九江建筑工程有限公司谷歌网站优化
  • 沈阳开发网站的地方全网自媒体平台