哪些神经网络架构可以解决我的分类问题?

发布于 2025-01-20 12:18:56 字数 3666 浏览 2 评论 0原文

我是深度学习的新手,所以我需要一些建议。根据X,Y坐标和年,我的变量发生了变化。例如,根据“ x,y坐标”和变量“ b”根据“年”而变化的变量“ a”变化,并且根据两个变化,可变“ c”都会根据两个变化(x,y坐标和年)。我想创建一个时空预测模型。但是,变量“ c”不仅会影响目标变量“ t”,而且还会根据前2年的价值影响目标变量。在这种情况下,如何创建时空预测模型?哪些神经网络体系结构解决了我的分类问题?

import pandas as pd
data = {'x': [40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1 ], 'y': [100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1], 'a': [1.0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 ], 'b': [1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 ], 'c': [1.0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0], 't': [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ], 'year': [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2001, 2001, 2001, 2001, 2001, 2001, 2001, 2001, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004]}   
df = pd.DataFrame(data)
df
        
         x        y      a    b      c   t  year
    0   40.1    100.1   1.0  1.0    1.0  1  2000
    1   50.1    110.1   0.0  1.0    1.0  1  2000
    2   60.1    120.1   1.0  1.0    1.0  1  2000
    3   70.1    130.1   1.0  1.0    0.0  0  2000
    4   80.1    140.1   0.0  1.0    0.0  0  2000
    5   90.1    150.1   0.0  1.0    0.0  0  2000
    6   0.0     160.1   0.0  1.0    0.0  0  2000
    7   300.1   400.1   0.0  1.0    0.0  0  2000
    8   40.1    100.1   1.0  0.5    1.0  0  2001
    9   50.1    110.1   0.0  0.5    0.0  1  2001
    10  60.1    120.1   1.0  0.5    1.0  0  2001
    11  70.1    130.1   1.0  0.5    0.0  0  2001
    12  80.1    140.1   0.0  0.5    0.0  1  2001
    13  90.1    150.1   0.0  0.5    0.0  1  2001
    14  0.0     160.1   0.0  0.5    1.0  0  2001
    15  300.1   400.1   0.0  0.5    0.0  0  2001
    16  40.1    100.1   1.0  0.9    1.0  0  2002
    17  50.1    110.1   0.0  0.9    0.0  1  2002
    18  60.1    120.1   1.0  0.9    0.0  1  2002
    19  70.1    130.1   1.0  0.9    0.0  1  2002
    20  80.1    140.1   0.0  0.9    1.0  0  2002
    21  90.1    150.1   0.0  0.9    1.0  0  2002
    22  0.0     160.1   0.0  0.9    0.0  1  2002
    23  300.1   400.1   0.0  0.9    0.0  0  2002
    24  40.1    100.1   1.0  0.3    1.0  0  2003
    25  50.1    110.1   0.0  0.3    0.0  1  2003
    26  60.1    120.1   1.0  0.3    0.0  1  2003
    27  70.1    130.1   1.0  0.3    0.0  1  2003
    28  80.1    140.1   0.0  0.3    0.0  0  2003
    29  90.1    150.1   0.0  0.3    0.0  1  2003
    30  0.0     160.1   0.0  0.3    1.0  0  2003
    31  300.1   400.1   0.0  0.3    1.0  0  2003
    32  40.1    100.1   1.0  0.2    1.0  0  2004
    33  50.1    110.1   0.0  0.2    0.0  0  2004
    34  60.1    120.1   1.0  0.2    0.0  0  2004
    35  70.1    130.1   1.0  0.2    0.0  1  2004
    36  80.1    140.1   0.0  0.2    1.0  1  2004
    37  90.1    150.1   0.0  0.2    0.0  0  2004
    38  0.0     160.1   0.0  0.2    0.0  0  2004
    39  300.1   400.1   0.0  0.2    0.0  0  2004

I am new to deep learning so I need some advice. I have variables changing according to x, y coordinates, and year. For example, variable "a" changes according to "x, y coordinates" and variable "b" changes according to "year", and also, variable "c" changes according to both of them (x, y coordinates and year). I want to create a spatiotemporal prediction model. However, variable "c" affects the target variable "t" not only for that year but also according to its value in the previous 2 years. In that case, how can I create a spatiotemporal prediction model? Which neural network architectures solve my classification problem?

import pandas as pd
data = {'x': [40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1, 40.1, 50.1, 60.1, 70.1, 80.1, 90.1, 0, 300.1 ], 'y': [100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1, 100.1, 110.1, 120.1, 130.1, 140.1, 150.1, 160.1, 400.1], 'a': [1.0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0 ], 'b': [1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2 ], 'c': [1.0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0], 't': [1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 ], 'year': [2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2001, 2001, 2001, 2001, 2001, 2001, 2001, 2001, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004]}   
df = pd.DataFrame(data)
df
        
         x        y      a    b      c   t  year
    0   40.1    100.1   1.0  1.0    1.0  1  2000
    1   50.1    110.1   0.0  1.0    1.0  1  2000
    2   60.1    120.1   1.0  1.0    1.0  1  2000
    3   70.1    130.1   1.0  1.0    0.0  0  2000
    4   80.1    140.1   0.0  1.0    0.0  0  2000
    5   90.1    150.1   0.0  1.0    0.0  0  2000
    6   0.0     160.1   0.0  1.0    0.0  0  2000
    7   300.1   400.1   0.0  1.0    0.0  0  2000
    8   40.1    100.1   1.0  0.5    1.0  0  2001
    9   50.1    110.1   0.0  0.5    0.0  1  2001
    10  60.1    120.1   1.0  0.5    1.0  0  2001
    11  70.1    130.1   1.0  0.5    0.0  0  2001
    12  80.1    140.1   0.0  0.5    0.0  1  2001
    13  90.1    150.1   0.0  0.5    0.0  1  2001
    14  0.0     160.1   0.0  0.5    1.0  0  2001
    15  300.1   400.1   0.0  0.5    0.0  0  2001
    16  40.1    100.1   1.0  0.9    1.0  0  2002
    17  50.1    110.1   0.0  0.9    0.0  1  2002
    18  60.1    120.1   1.0  0.9    0.0  1  2002
    19  70.1    130.1   1.0  0.9    0.0  1  2002
    20  80.1    140.1   0.0  0.9    1.0  0  2002
    21  90.1    150.1   0.0  0.9    1.0  0  2002
    22  0.0     160.1   0.0  0.9    0.0  1  2002
    23  300.1   400.1   0.0  0.9    0.0  0  2002
    24  40.1    100.1   1.0  0.3    1.0  0  2003
    25  50.1    110.1   0.0  0.3    0.0  1  2003
    26  60.1    120.1   1.0  0.3    0.0  1  2003
    27  70.1    130.1   1.0  0.3    0.0  1  2003
    28  80.1    140.1   0.0  0.3    0.0  0  2003
    29  90.1    150.1   0.0  0.3    0.0  1  2003
    30  0.0     160.1   0.0  0.3    1.0  0  2003
    31  300.1   400.1   0.0  0.3    1.0  0  2003
    32  40.1    100.1   1.0  0.2    1.0  0  2004
    33  50.1    110.1   0.0  0.2    0.0  0  2004
    34  60.1    120.1   1.0  0.2    0.0  0  2004
    35  70.1    130.1   1.0  0.2    0.0  1  2004
    36  80.1    140.1   0.0  0.2    1.0  1  2004
    37  90.1    150.1   0.0  0.2    0.0  0  2004
    38  0.0     160.1   0.0  0.2    0.0  0  2004
    39  300.1   400.1   0.0  0.2    0.0  0  2004

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2025-01-27 12:18:56

有时,问题不在于你使用什么模型,而在于你如何改变你的功能。您说您的目标取决于过去的特征值,因此您可以重新排列数据以反映这一点。

这是如何将三个连续的行连接成一行的方法。

X = df.drop("t", axis=1)
y = df["t"]

X = (
    pd.concat([X, X.shift(1), X.shift(2)], axis=1, keys=["t0", "t-1", "t-2"])
    .dropna()
)
y = y.iloc[2:]
>>> X.head()
    t0  t0  t0  t0  t0  t0      t-1 t-1 t-1 t-1 t-1 t-1     t-2 t-2 t-2 t-2 t-2 t-2
    x   y   a   b   c    year   x   y   a   b   c   year    x   y   a   b   c   year
2   60.1    120.1   1.0 1.0 1.0 2000    50.1    110.1   0.0 1.0 1.0 2000.0  40.1    100.1   1.0 1.0 1.0 2000.0
3   70.1    130.1   1.0 1.0 0.0 2000    60.1    120.1   1.0 1.0 1.0 2000.0  50.1    110.1   0.0 1.0 1.0 2000.0
4   80.1    140.1   0.0 1.0 0.0 2000    70.1    130.1   1.0 1.0 0.0 2000.0  60.1    120.1   1.0 1.0 1.0 2000.0
5   90.1    150.1   0.0 1.0 0.0 2000    80.1    140.1   0.0 1.0 0.0 2000.0  70.1    130.1   1.0 1.0 0.0 2000.0

您现在可以拟合任何分类模型。我选择了 sklearn 中的一个简单的逻辑回归器。

from sklearn.linear_model import LogisticRegression

clf = LogisticRegression()
clf.fit(X, y)
>>> clf.score(X, y)
0.7368421052631579

相同模型在纯数据上的得分 0.625,添加额外的时间步得分 0.8108

我并不是说这是唯一的方法,但确实值得考虑。

有关更多详细信息,您可以阅读 https://machinelearningmastery.com/basic -feature-engineering-time-series-data-python/

Sometimes it's not a matter of what model you use, but how you transform your features. You say that your target depends on past feature values, so you can rearrange your data to reflect this.

Here it is how to concatenate three consecutive rows into a single one.

X = df.drop("t", axis=1)
y = df["t"]

X = (
    pd.concat([X, X.shift(1), X.shift(2)], axis=1, keys=["t0", "t-1", "t-2"])
    .dropna()
)
y = y.iloc[2:]
>>> X.head()
    t0  t0  t0  t0  t0  t0      t-1 t-1 t-1 t-1 t-1 t-1     t-2 t-2 t-2 t-2 t-2 t-2
    x   y   a   b   c    year   x   y   a   b   c   year    x   y   a   b   c   year
2   60.1    120.1   1.0 1.0 1.0 2000    50.1    110.1   0.0 1.0 1.0 2000.0  40.1    100.1   1.0 1.0 1.0 2000.0
3   70.1    130.1   1.0 1.0 0.0 2000    60.1    120.1   1.0 1.0 1.0 2000.0  50.1    110.1   0.0 1.0 1.0 2000.0
4   80.1    140.1   0.0 1.0 0.0 2000    70.1    130.1   1.0 1.0 0.0 2000.0  60.1    120.1   1.0 1.0 1.0 2000.0
5   90.1    150.1   0.0 1.0 0.0 2000    80.1    140.1   0.0 1.0 0.0 2000.0  70.1    130.1   1.0 1.0 0.0 2000.0

You can now fit any classification model. I have chosen a simple logistic regressor from sklearn.

from sklearn.linear_model import LogisticRegression

clf = LogisticRegression()
clf.fit(X, y)
>>> clf.score(X, y)
0.7368421052631579

The same model on the plain data scores 0.625, adding an extra timestep scores 0.8108.

I'm not saying this is the only approach but certainly something to consider.

For more details you can read https://machinelearningmastery.com/basic-feature-engineering-time-series-data-python/.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文