代码
import torch
import torch.nn.functional as F
from sklearn.datasets import make_blobs
import matplotlib.pyplot as plt
# torch.manual_seed(1) # reproducible
# make fake data
x,target_y = make_blobs(n_samples=300, n_features=2, centers=[[5,5],[-5,-5],[0,0]], random_state=0)
# The code below is deprecated in Pytorch 0.4. Now, autograd directly supports tensors
# x, y = Variable(x), Variable(y)
# plt.scatter(x.data.numpy()[:, 0], x.data.numpy()[:, 1], c=y.data.numpy(), s=100, lw=0, cmap='RdYlGn')
# plt.show()
class Net(torch