I have only seven characteristics in a data forecasting the amount of bicycles. Why do I predict that the results are almost the same?
Out:
tensor([[50.9622],
[50.7544],
[50.2624],
[49.4988],
[50.6219],
[50.3502],
[50.2156],
[50.7703],
[51.0407],
[50.7978]])
Maybe your model is too simple. Better you show your full code.
Thank you
This is all the code
If you need all the data, I can give it to you.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import torch˽
import torch.nn as nn
import warnings
warnings.filterwarnings('ignore')
train = pd.read_csv("../../Data/3-sofa公共自行车使用量预测/train.csv",index_col='id')
test = pd.read_csv("../../Data/3-sofa公共自行车使用量预测/test.csv",index_col='id')
submit = pd.read_csv("../../Data/3-sofa公共自行车使用量预测/sample_submit.csv")
train.columns
OUt
Index([‘city’, ‘hour’, ‘is_workday’, ‘weather’, ‘temp_1’, ‘temp_2’, ‘wind’, ‘y’], dtype=‘object’)
train.head()
# 取出训练集的y
y_train = train.pop('y')
train = torch.FloatTensor(train.values)
test = torch.FloatTensor(test.values)
y_train = torch.FloatTensor(y_train.values)
net = torch.nn.Sequential(
torch.nn.Linear(7,100),
torch.nn.Sigmoid(),
torch.nn.Linear(100,1),
)
optimizer = torch.optim.Adam(net.parameters(),lr=0.02)
loss_func = torch.nn.MSELoss()
for i in range(60):
prediction = net(train)
loss = loss_func(prediction,y_train)
# 梯度归零
optimizer.zero_grad()
# 计算梯度
loss.backward()
# 更新结点
optimizer.step()
if i % 20 == 0:
print(loss)
OUt˽˽
tensor(4836.1333, grad_fn=<MseLossBackward>)
tensor(2624.3867, grad_fn=<MseLossBackward>)
tensor(2307.5830, grad_fn=<MseLossBackward>)
y_train[:10]
tensor([15., 48., 21., 11., 39., 12., 11., 67., 77., 2.])
net(train[:10])
Out
tensor([[51.4017],
[49.5164],
[48.2066],
[49.3453],
[49.4258],
[48.9165],
[48.8166],
[49.5939],
[50.7129],
[49.8309]])