下面是一个基于 PyTorch 的多对多回归预测的示例代码:
```python import torch import torch.nn as nn import torch.optim as optim import matplotlib.pyplot as plt
读取 csv 文件
import pandas as pd data = pd.read_csv("data.csv") X = data.iloc[:, :4] # 前 4 列为特征 Y = data.iloc[:, 4:] # 剩余的 50 列为标签
划分训练集和测试集
from sklearn.model_selection import train_test_split X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)
转换为 PyTorch 张量
X_train = torch.tensor(X_train.values).float() X_test = torch.tensor(X_test.values).float() Y_train = torch.tensor(Y_train.values).float() Y_test = torch.tensor(Y_test.values).float()
定义模型
class RegressionModel(nn.Module): def init(self): supe