Pytorch predict Result is Almost the same

username: Liuyang
cooked: <p>I have only seven characteristics in a data forecasting the amount of bicycles. Why do I predict that the results are almost the same?<br>
<img src="https://discuss.pytorch.org/uploads/default/original/2X/a/a5a05875c53c6c7bbe6e4adbd867c14d06dd7532.png" alt="image" data-base62-sha1="nDcjVmtCM4PzXNc4f76wWMDF8Pg" width="603" height="195"><br>
<strong>Out:</strong><br>
tensor([[50.9622],<br>
[50.7544],<br>
[50.2624],<br>
[49.4988],<br>
[50.6219],<br>
[50.3502],<br>
[50.2156],<br>
[50.7703],<br>
[51.0407],<br>
[50.7978]])</p>

username: sparsepy
cooked: <p>Maybe your model is too simple. Better you show your full code.</p>

username: Liuyang
cooked: <h1><a name="thank-you-1" class="anchor" href="#thank-you-1"></a>Thank you</h1>
<h2><a name="this-is-all-the-code-2" class="anchor" href="#this-is-all-the-code-2"></a>This is all the code</h2>
<h2><a name="if-you-need-all-the-data-i-can-give-it-to-you-3" class="anchor" href="#if-you-need-all-the-data-i-can-give-it-to-you-3"></a>If you need all the data, I can give it to you.</h2>
<pre data-code-wrap="python"><code class="lang-python">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')    
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">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")    
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">train.columns    
</code></pre>
<p><strong>OUt</strong><br>
Index([‘city’, ‘hour’, ‘is_workday’, ‘weather’, ‘temp_1’, ‘temp_2’, ‘wind’,    ‘y’],    dtype=‘object’)</p>
<pre data-code-wrap="python"><code class="lang-python">train.head()    
</code></pre>
<p><img src="https://discuss.pytorch.org/uploads/default/original/2X/5/5a59e79974afae253ba032fe0c5f0aff0933d301.png" alt="image" data-base62-sha1="cThAIzrTZ0dNeZfr6lzeOgEoxSF" width="651" height="213"></p>
<pre data-code-wrap="python"><code class="lang-python"># 取出训练集的y
y_train = train.pop('y')
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">train = torch.FloatTensor(train.values)
test = torch.FloatTensor(test.values)
y_train = torch.FloatTensor(y_train.values)
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">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()
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">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)
</code></pre>
<p><strong>OUt</strong>˽˽</p>
<pre><code>tensor(4836.1333, grad_fn=&lt;MseLossBackward&gt;)
tensor(2624.3867, grad_fn=&lt;MseLossBackward&gt;)
tensor(2307.5830, grad_fn=&lt;MseLossBackward&gt;)
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">y_train[:10]
</code></pre>
<pre><code>tensor([15., 48., 21., 11., 39., 12., 11., 67., 77.,  2.])
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">net(train[:10])
</code></pre>
<p><strong>Out</strong><br>
tensor([[51.4017],<br>
[49.5164],<br>
[48.2066],<br>
[49.3453],<br>
[49.4258],<br>
[48.9165],<br>
[48.8166],<br>
[49.5939],<br>
[50.7129],<br>
[49.8309]])</p>