python+torch linear regression model machine learning

Selected program examples: python+torch linear regression model machine learning. If you need to install the operating environment or remote debugging, please see your personal QQ business card at the bottom of the article for remote assistance from professional technicians!

Preface

This blog writes code for "Python+Torch Linear Regression Model Machine Learning". The code is clean, regular and easy to read. Recommended for learning and application.


Article directory

1. Required tools and software
2. Usage steps
       1. Main code
       2. Operation results
3. Online assistance

1. Required tools and software

       1. Python
       2. Pycharm

2. Usage steps

The code is as follows (example):
x = torch.unsqueeze(torch.linspace(-1, 1, 100), dim=1)
y = x.pow(2) + 0.2*torch.rand(x.size())

x, y = variable(x), variable(y)

#plt.scatter(x.data.numpy(), y.data.numpy())
#plt.show()
#定义层
class Net(torch.nn.Module):
    def __init__(self, n_feature, n_hidden, n_output):
       super(Net, self).__init__()
       self.hidden = torch.nn.Linear(n_feature, n_hidden)
       self.predict = torch.nn.Linear(n_hidden, n_output)
#搭建层
    def forward(self, x):
        x = F.relu(self.hidden(x))
        x = self.predict(x)
        return x
net = Net(1, 10, 1)
print(net)

plt #something about plotting
plt.show()



for t in range(100):
    prediction = net(x)

    loss = loss_func(prediction, y)

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()


operation result

Insert image description here
Insert image description here

3. Online assistance:

If you need to install the operating environment or remote debugging, please see your personal QQ business card at the bottom of the article for remote assistance from professional technicians!

1) Remote installation and running environment, code debugging
2) Visual Studio, Qt, C++, Python programming language introductory guide
3) Interface beautification
4) Software production 5
) Cloud server application
6) Website production

Current article link: https://blog.csdn.net/alicema1111/article/details/132666851
Personal blog homepage : https://blog.csdn.net/alicema1111?type=
All articles by blogger click here: https:/ /blog.csdn.net/alicema1111?type=blog

Recommended by bloggers:
Python face recognition attendance punching system:
https://blog.csdn.net/alicema1111/article/details/133434445
Python fruit tree fruit recognition : https://blog.csdn.net/alicema1111/article/details/ 130862842
Python+Yolov8+Deepsort entrance traffic statistics: https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt face recognition access management system: https://blog.csdn.net/alicema1111/ article/details/130353433
Python+Qt fingerprint entry recognition attendance system: https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5 flame smoke recognition source code sharing: https://blog.csdn.net/alicema1111 /article/details/128420453
Python+Yolov8 road bridge wall crack identification: https://blog.csdn.net/alicema1111/article/details/133434445

Guess you like

Origin blog.csdn.net/alicema1111/article/details/135065123