我试图用大熊猫将这张专辑中的第一张图像转换成第二张图像,但我得到的只是第三张...
F.mean_squared_error
from chainer import iterators, optimizers, training
from chainer import Chain
from chainer.datasets import mnist
import chainer.functions as F
import chainer.links as L
from chainer.training import extensions
import numpy as np
# simple addition data
N = 1000
x_ = np.random.choice(10, size=(N, 2)).astype(np.float32)
y_ = x_.sum(axis=1).astype(np.float32)
train = [(x[:,None], np.asarray([y])) for x, y in zip(x_, y_)]
train_iter = iterators.SerialIterator(train, 1000)
# model
class Model(Chain):
def __init__(self):
super(Model, self).__init__()
with self.init_scope():
self.l_out = L.Linear(2, 1)
def forward(self, x):
return self.l_out(x)
model = Model()
model = F.mean_squared_error
# run
optimizer = optimizers.Adam()
optimizer.setup(model)
updater = training.updaters.StandardUpdater(train_iter, optimizer)
trainer = training.Trainer(updater, (1000, 'epoch'), out='mnist_result')
trainer.run()
Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1981 453.1 126.3 5.8 47.1 25.3 16.8 0 1.1 4.4 17.8 52.5 72.4
1982 211.4 23.1 231.2 0.8 0.2 0 0 0 15.3 0.9 8.6 59.9
1983 45.2 22.1 537.7 22.8 29.9 0 0 0.1 0.7 1.2 47 20.9
1984 390.2 514.2 140.3 7.3 0 0 2.8 0.1 0 18.3 23.2 91.7
我的代码就是这样:
Year Month Value
1981 Jan 453.1
1981 Feb 126.3
1981 Mar 5.8
1981 Apr 47.1
...
我该如何替代每年的几个月?我想每个月都有第一年,然后每个月都有第二年……而不是每年的第一个月。
答案 0 :(得分:0)
对列名称使用有序分类法,因此两列都可以DataFrame.sort_values
进行正确排序:
spring.data.web.pageable.default-page-size
或将Series转换为months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
data = pd.read_csv("Burketown.csv", index_col=['Year'])[months]
data.columns = pd.CategoricalIndex(data.columns, ordered=True, categories=months)
df = data.reset_index()[months]
fixed_data = (pd.melt(data, id_vars=['Year'], value_vars=months)
.sort_values(['Year', 'variable']))
:
ordered categorical