我正在使用 LSTM NN 和 Keras 进行时间序列预测。作为输入特征,有两个变量(降水量和温度),要预测的一个目标是地下水位。
\n尽管实际数据和输出之间存在严重的偏移(见图),但它似乎工作得很好。
\n现在我读到这可能是网络无法正常工作的典型标志,因为它似乎在模仿输出并且
\n\n\n该模型实际上所做的是,当预测\n时间 \xe2\x80\x9ct+1\xe2\x80\x9d 的值时,它只是使用时间 \xe2\x80\x9ct\xe2\x80\x9d 的值作为它的预测https://towardsdatascience.com/how-not-to-use-machine-learning-for-time-series-forecasting-avoiding-the-pitfalls-19f9d7adf424
\n
然而,在我的例子中这实际上是不可能的,因为目标值不用作输入变量。我使用的是具有两个特征的多元时间序列,与输出特征无关。\n此外,预测值在未来 (t+1) 中不会偏移,而是似乎滞后于 (t-1)。
\n\n这是我的网络的完整代码:
\n# Split in Input and Output Data \nx_1 = data[[\'MeanT\']].values\nx_2 = data[[\'Precip\']].values\ny = data[[\'Z_424A_6857\']].values\n\n# Scale Data\nx = np.hstack([x_1, x_2])\nscaler = MinMaxScaler(feature_range=(0, 1))\nx = scaler.fit_transform(x)\n\nscaler_out = MinMaxScaler(feature_range=(0, 1))\ny = scaler_out.fit_transform(y)\n\n# Reshape Data\nx_1, x_2, y = H.create2feature_data(x_1, x_2, y, window)\ntrain_size = int(len(x_1) * .8)\ntest_size = int(len(x_1)) # * .5\n\nx_1 = np.expand_dims(x_1, 2) # …Run Code Online (Sandbox Code Playgroud) 我最近设法在一台新计算机上安装了 Code::Blocks 和 MinGW 编译器。
我在 Code::Blocks 上的调试器有问题。它实际上不会让我创建任何项目并给我一条错误消息。
错误消息如下:
wxWidgets Debug Alert
A debugging check in this application has failed.
../../src/common/file.cpp(361): assert ""(pBuf != __null) && IsOpened()"" failed in Write()
Run Code Online (Sandbox Code Playgroud)
这是整个事情的图片:[错误消息]

如果我按停止,那么一切都会崩溃。
但是,如果我按继续,则会收到此警告:
Warning
Couldn't save project C:\Users\40737\Documents\yy\yy.cbp
(Maybe the file is write-protected?)
Run Code Online (Sandbox Code Playgroud)
这是一张图片:[警告信息]

如果我继续点击确定,同样的错误会再次出现:
再来一张图:【错误再次出现】

有什么可做的?
我正在尝试更新以下函数以通过图例报告集群信息:
color_names = ["red", "blue", "yellow", "black", "pink", "purple", "orange"]
def plot_3d_transformed_data(df, title, colors="red"):
ax = plt.figure(figsize=(12,10)).gca(projection='3d')
#fig = plt.figure(figsize=(8, 8))
#ax = fig.add_subplot(111, projection='3d')
if type(colors) is np.ndarray:
for cname, class_label in zip(color_names, np.unique(colors)):
X_color = df[colors == class_label]
ax.scatter(X_color[:, 0], X_color[:, 1], X_color[:, 2], marker="x", c=cname, label=f"Cluster {class_label}" if type(colors) is np.ndarray else None)
else:
ax.scatter(df.Type, df.Length, df.Freq, alpha=0.6, c=colors, marker="x", label=str(clusterSizes) )
ax.set_xlabel("PC1: Type")
ax.set_ylabel("PC2: Length")
ax.set_zlabel("PC3: Frequency")
ax.set_title(title)
if type(colors) is np.ndarray:
#ax.legend()
plt.gca().legend()
plt.legend(bbox_to_anchor=(1.04,1), loc="upper …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何选项可以使下图(sns.heatmap(df)子图的输出)变得平滑:
我刚刚在这里找到了一个相关的答案,这是通过使用建议的zsmooth:
data = [go.Heatmap(z=[[1, 20, 30],
[20, 1, 60],
[30, 60, 1]],
zsmooth = 'best')]
iplot(data)
Run Code Online (Sandbox Code Playgroud)
我使用的代码片段seaborn如下:
#plotting all columns ['A','B','C'] in-one-window side by side
fig, axes = plt.subplots(nrows=1, ncols=3 , figsize=(20,10))
plt.subplot(131)
sns.heatmap(df1, vmin=-1, vmax=1, cmap ="coolwarm", linewidths=.75 , linecolor='black', cbar=True , cbar_kws={"ticks":[-1.0,-0.75,-0.5,-0.25,0.00,0.25,0.5,0.75,1.0]})
fig.axes[-1].set_ylabel('[MPa]', size=20) #cbar_kws={'label': 'Celsius'}
plt.title('A', fontsize=12, color='black', loc='center', style='italic')
plt.axis('off')
plt.subplot(132)
sns.heatmap(df2, vmin=-1, vmax=1, cmap ="coolwarm", linewidths=.75 , linecolor='black', cbar=True , cbar_kws={"ticks":[-1.0,-0.75,-0.5,-0.25,0.00,0.25,0.5,0.75,1.0]})
fig.axes[-1].set_ylabel('[Mpa]', size=20) #cbar_kws={'label': …Run Code Online (Sandbox Code Playgroud) 我的输出:

def load_data(self):
"""
Load data from list of paths
:return: 3D-array X and 2D-array y
"""
X = None
y = None
df = pd.read_excel('data/Data.xlsx', header=None)
for i in range(len(df.columns)):
sentences_ = df[i].to_numpy().tolist()
label_vec = [0.0 for _ in range(0, self.n_class)]
label_vec[i] = 1.0
labels_ = [label_vec for _ in range(0, len(sentences_))]
if X is None:
X = sentences_
y = labels_
else:
X += sentences_
y += labels_
X, max_length = self.tokenize_sentences(X)
X = self.word_embed_sentences(X, max_length=self.max_length)
return np.array(X), …Run Code Online (Sandbox Code Playgroud) 有一个数据框,总共由 14 列组成,最后一列是整数值为 0 或 1 的目标标签。
我已经定义:
X = df.iloc[:,1:13]---- 这由特征值组成y = df.iloc[:,-1]------ 这由相应的标签组成两者具有所需的相同长度,X是由 13 列组成的数据框,形状为 (159880, 13),y是形状为 (159880,) 的数组类型
但是当我执行train_test_split(), X-时y,该功能无法正常工作。
下面是简单的代码:
X_train, y_train, X_test, y_test = train_test_split(X, y, random_state = 0)
Run Code Online (Sandbox Code Playgroud)
分裂之后, 和X_train都X_test具有形状 (119910,13)。y_train具有形状 (39970,13) 并且y_test具有形状 (39970,)
这很奇怪,即使在定义test_size参数之后,结果仍然保持不变。
请指教,可能出了什么问题。
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from adspy_shared_utilities import …Run Code Online (Sandbox Code Playgroud) 我有一个关于为什么将 TensorFlow 变量设置为small 的问题stddev。我想很多人都会从 TensorFlow 初学者指南中测试 MNIST 测试代码。接下来,第一层的权重使用0.1truncated_normal来初始化stddev。我猜想如果将其设置为更大的值,那么结果将是相同的,这是完全准确的。但是虽然增加了纪元数,但它不起作用。有谁知道这个原因吗?
原来的 :
W_layer = tf.Variable(tf.truncated_normal([inp.get_shape()[1].value, size],stddev=0.1), name='w_'+name)
#result : (990, 0.93000001, 0.89719999)
Run Code Online (Sandbox Code Playgroud)
修改的 :
W_layer = tf.Variable(tf.truncated_normal([inp.get_shape()[1].value, size],stddev=200), name='w_'+name)
#result : (99990, 0.1, 0.098000005)
Run Code Online (Sandbox Code Playgroud) 我已经使用这篇文章GMM 和使用 NumPy 的最大似然优化实现了GMM的EM 算法,但未成功,如下所示:
import numpy as np
def PDF(data, means, variances):
return 1/(np.sqrt(2 * np.pi * variances) + eps) * np.exp(-1/2 * (np.square(data - means) / (variances + eps)))
def EM_GMM(data, k, iterations):
weights = np.ones((k, 1)) / k # shape=(k, 1)
means = np.random.choice(data, k)[:, np.newaxis] # shape=(k, 1)
variances = np.random.random_sample(size=k)[:, np.newaxis] # shape=(k, 1)
data = np.repeat(data[np.newaxis, :], k, 0) # shape=(k, n)
for step in range(iterations):
# Expectation step …Run Code Online (Sandbox Code Playgroud) python ×5
scikit-learn ×2
c++ ×1
debugging ×1
gmm ×1
heatmap ×1
keras ×1
legend ×1
matplotlib ×1
numpy ×1
pandas ×1
prediction ×1
seaborn ×1
smoothing ×1
tensorflow ×1
time-series ×1
variables ×1