- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用一些时间序列功耗数据并尝试对其进行线性回归分析。
数据具有以下列:
日期,丹麦_消费,德国_消费,捷克_消费,奥地利_消费。
它是频率为小时的时间序列数据。
但是,每列都有 NaN 的值
我的目标是创建一个线性回归模型
对没有空值的数据子集进行训练和测试,然后尝试预测丹麦消费列的值,例如,当前具有 NaN 值的值。
我计划使用一个国家/地区消费列以及序号值中的日期作为我的培训/测试功能,以尝试预测第二个国家/地区的消费值。
这是数据的示例。
Date Denmark Germany Czech Austria
2018-01-01 00:00:00 1607.0 42303.0 5520 6234.0
2018-01-01 01:00:00 1566.0 41108.0 5495 6060.0
2018-01-01 02:00:00 1460.0 40554.0 5461 5872.0
2018-01-01 03:00:00 1424.0 38533.0 5302 5564.0
2018-01-01 04:00:00 1380.0 38494.0 5258 5331.0
我做了几件事。
Germany Date
consumption
Date
2018-07-08 44394.125000 736883
2019-01-16 66148.125000 737075
2019-08-03 45718.083333 737274
2019-06-09 41955.250000 737219
2020-03-04 61843.958333 737488
这是我的 y_train 数据集的示例。
Date
2018-01-01 1511.083333
2018-01-02 1698.625000
2018-01-03 1781.291667
2018-01-04 1793.458333
2018-01-05 1796.875000
Name: Denmark_consumption, dtype: float64
这是实际的相关代码。
lin_model = LinearRegression()
lin_model.fit(X_train,y_train)
y_pred = lin_model.predict(X_test)
plt.scatter(X_test['Date'].map(dt.datetime.fromordinal),y_pred,color='black')
plt.plot(X_test['Date'],y_pred)
系数、R 平方和均方误差为:
Coefficients:
[0.01941453 0.01574128]
Mean squared error: 14735.12
Coefficient of determination: 0.51
有人可以让我知道我做错了什么吗?另外,我的方法准确吗?尝试有意义吗
最佳答案
你的方法很复杂,但可行。就我个人而言,我认为在德国的日期和德国的消费量之间创建线性映射可能更容易,然后尝试通过这种方式对丹麦的消费量进行预测。
但是,坚持你的方法,你应该记住有两个自变量(德国的日期转换为整数,德国的消费量),丹麦的消费量取决于这两个变量。因此,通过像现在这样在 2D 图中根据预测绘制测试日期,您实际上错过了消费变量。您应该绘制的是德国的日期,以及德国的消费量与丹麦在 3D 平面中的消费量。
此外,您不应该期望得到一条直线:通过多元线性回归和两个自变量,您可以预测飞机。
这是我放在一起的一个简短示例,它类似于您可能想要实现的目标。根据需要随意更改日期格式。
import pandas as pd
import numpy as np
import datetime as dt
from mpl_toolkits.mplot3d import *
import matplotlib.pyplot as plt
from matplotlib import cm
from sklearn.linear_model import LinearRegression
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
# starts 2018/11/02
df_germany = pd.DataFrame({
'Germany consumption': [45000, 47000, 48000, 42000, 50000],
'Date': [737000, 737001, 737002, 737003, 737004]})
df_germany_test = pd.DataFrame({
'Germany consumption': [42050, 42000, 57000, 30000, 52000, 53000],
'Date': [737000, 737001, 737002, 737003, 737004, 737005]})
df_denmark = pd.DataFrame({
'Denmark consumption': [1500, 1600, 1700, 1800, 2000]
})
X_train = df_germany.to_numpy()
y_train = df_denmark['Denmark consumption']
# make X_test the same as X_train to make sure all points are on the plane
# X_test = df_germany
# make X_test slightly different
X_test = df_germany_test
lin_model = LinearRegression()
lin_model.fit(X_train,y_train)
y_pred = lin_model.predict(X_test)
fig = plt.figure()
ax = fig.gca(projection='3d')
# plt.hold(True)
x_surf=np.linspace(min(X_test['Date'].values), max(X_test['Date'].values), num=20)
y_surf=np.linspace(min(X_test['Germany consumption'].values), max(X_test['Germany consumption'].values), num=20)
x_surf, y_surf = np.meshgrid(x_surf, y_surf)
b0 = lin_model.intercept_
b1, b2 = lin_model.coef_
z_surf = b0+ b2*x_surf + b1*y_surf
ax.plot_surface(x_surf, y_surf, z_surf, cmap=cm.cool, alpha = 0.2) # plot a 3d surface plot
ax.scatter(X_test['Date'].values, X_test['Germany consumption'].values, y_pred, alpha=1.0)
plt.show()
关于python - 线性回归图没有给我有意义的可视化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63045562/
在我的 previous question ,已经确定,当纹理四边形时,面部被分解为三角形,纹理坐标以仿射方式插值。 不幸的是,我不知道如何解决这个问题。 provided link很有用,但没有达到
是否有简单的解决方案可以在 Qt 中为图像添加运动模糊?还没有找到任何关于模糊的好教程。我需要一些非常简单的东西,我可以理解,如果我可以改变模糊角度,那就太好了。 最佳答案 Qt 没有运动模糊过滤器。
我想构建一个有点复杂的轴,它可以处理线性数据到像素位置,直到某个值,在该值中所有内容都被归入一个类别,因此具有相同的数据到像素值。例如,考虑具有以下刻度线的 y 轴: 0%, 10%, 20%, 30
我需要确保两个 View 元素彼此相邻且垂直高度相同。我会使用基线约束来做到这一点,但目前我正在使用线性、可滚动的布局( ScrollView 中的线性布局),当我点击一个元素时,它不允许我从中获取基
考虑正则表达式 ".*?\s*$" 和一个不以空格结尾的字符串。 示例 " a" .最后\s永远无法匹配 a这就是为什么 匹配器迭代: \s\s\s\s\s - fails .\s\s\
Closed. This question needs to be more focused。它当前不接受答案。 想要改善这个问题吗?更新问题,使它仅关注editing this post的一个问题。
我正在尝试阅读英特尔软件开发人员手册以了解操作系统的工作原理,这四个寻址术语让我感到困惑。以上是我的理解,如有不对请指正。 线性地址 : 对一个孤立的程序来说,似乎是一长串以地址0开头的内存。该程序的
有很多方法可以使用正则表达式并相应地使用匹配/测试匹配来检查字符串是否有效。我正在检查包含字母(a-b)、运算符(+、-、/、*)、仅特殊字符(如(')'、'(')和数字(0-9)的表达式是否有效 我
我正在使用 iris 数据集在 R 中练习 SVM,我想从我的模型中获取特征权重/系数,但我想我可能误解了一些东西,因为我的输出给了我 32 个支持向量。假设我要分析四个变量,我会得到四个。我知道在使
我正在使用 iris 数据集在 R 中练习 SVM,我想从我的模型中获取特征权重/系数,但我想我可能误解了一些东西,因为我的输出给了我 32 个支持向量。假设我要分析四个变量,我会得到四个。我知道在使
如何向左或向右滑动线性布局。在该线性布局中,默认情况下我有一个不可见的删除按钮,还有一些其他小部件,它们都是可见状态,当向左滑动线性布局时,我需要使其可见的删除按钮,当向右滑动时,我需要隐藏该删除按钮
我正在编写一个 R 脚本,运行时会给出因变量的预测值。我的所有变量都被分类(如图所示)并分配了一个编号,总类数为101。(每个类是歌曲名称)。 所以我有一个训练数据集,其中包含 {(2,5,6,1)8
如果源栅格位于 linear RGB color space使用以下 Java 代码进行转换,应用过滤器时(最后一行)会引发 java.awt.image.ImagingOpException: Un
我想为我的多个 UIImageView 设置动画,使其从 A 点线性移动到 B 点。 我正在使用 options:UIViewAnimationOptionCurveLinear - Apple 文档
我第一次无法使用 CSS3 创建好看的渐变效果。右侧应该有从黑色到透明的渐变透明渐变。底部是页脚,所以它需要在底部另外淡化为透明。 如果可能的话,一个例子: 页面的背景是一张图片,所以不可能有非透明淡
我有一组线性代数方程,Ax=By。其中A是36x20的矩阵,x是20x1的 vector ,B是36x13,y是13x1。 排名(A)=20。因为系统是超定的,所以最小二乘解是可能的,即; x = (
我有一个带有年月数据列(yyyymm)的 Pandas 数据框。我计划将数据插入每日和每周值。下面是我的 df。 df: 201301 201302 201303
假设我想找到2条任意高维直线的“交点”。这两条线实际上不会相交,但我仍然想找到最相交的点(即尽可能靠近所有线的点)。 假设这些线有方向向量A、B和初始点C、D,我可以通过简单地设置一个线性最小二乘问题
如果我想编写一个函数(可能也是一个类),它从不可变的查找表(调用构造函数时固定)返回线性“平滑”数据,如下所示: 例如func(5.0) == 0.5。 存储查找表的最佳方式是什么? 我正在考虑使用两
给定一条线 X像素长如: 0-------|---V---|-------|-------|-------max 如果0 <= V <= max , 线性刻度 V位置将是 X/max*V像素。 如何计
我是一名优秀的程序员,十分优秀!