我正在使用neupy来获得一组具有以下代码的神经元:
All = pd.read_csv("inputfile.csv")
df = pd.DataFrame(All)
coords = df.as_matrix(columns=['lat', 'lng'])
sofmnet = algorithms.SOFM(n_inputs=2,
n_outputs=4,
step=0.5,
show_epoch=1,
shuffle_data=True,
verbose=True,
learning_radius=1,
features_grid=(4, 1),)
sofmnet.train(coords,epochs=20)
neuronlocations = sofmnet.weight.T1-如何读取/获取与每个神经元相关联的点集?2- inputfile.csv具有日期、日期、lng字段。我想要计算每个神经元每天的点数。如何继续?谢谢
发布于 2018-11-13 04:24:09
您可以使用predict方法来查找最近神经元的编码。以下是官方文档中的一个示例。
>>> import numpy as np
>>> from neupy import algorithms, environment
>>>
>>> environment.reproducible()
>>>
>>> data = np.array([
... [0.1961, 0.9806],
... [-0.1961, 0.9806],
... [-0.5812, -0.8137],
... [-0.8137, -0.5812],
... ])
>>>
>>> sofm = algorithms.SOFM(
... n_inputs=2,
... n_outputs=2,
... step=0.1,
... learning_radius=0
... )
>>> sofm.train(data, epochs=100)
>>> sofm.predict(data)
array([[0, 1],
[0, 1],
[1, 0],
[1, 0]])预测返回一个热编码的神经元标识符。您可以通过对输出应用argmax来获得神经元的索引
>>> prediction = sofm.predict(data)
>>> neuron_index = prediction.argmax(axis=1)您可以使用此信息来解决第二个问题。
>>> df['neuron_index'] = neuron_index
>>> df.groupby(['date', 'neuron_index']).count()
lat lng
date neuron_index
2018-05-06 0 1 1
2018-05-07 0 1 1
1 2 2https://stackoverflow.com/questions/53166166
复制相似问题