我是 pytorch 的新手,只是尝试编写一个网络。是data.shape(204,6170),最后 5 列是一些标签。数据中的数字是浮点数,如 0.030822。#%%from sklearn.feature_selection import RFEimport numpy as npimport pandas as pdimport torchimport torch.nn as nnfrom sklearn.model_selection import train_test_splitimport torch.functional as F#%%data = pd.read_table("table.log")data_x = data.iloc[:, 0:(data.shape[1]-5)]data_y = data.loc[:, 'target']X_train, X_test, y_train, y_test = train_test_split(data_x,data_y,test_size=0.2,random_state=0)#%%from sklearn.linear_model import LinearRegressionlr = LinearRegression(normalize=True)lr.fit(X_train,y_train)rfe1 = RFE(estimator=lr,n_features_to_select=2000)rfe1 = rfe1.fit(X_train,y_train)#%%x_train_rfe1 = X_train[X_train.columns[rfe1.support_]]print(x_train_rfe1.head())class testmodel(nn.Module): def __init__(self): super(testmodel,self).__init__() self.conv = nn.Sequential( nn.Conv1d(1500, 500, 1500, 0, 0), nn.ReLU(), nn.Conv1d(500, 100, 500, 0), nn.ReLU(), nn.Conv1d(100, 20, 100, 0), nn.Sigmoid() ) def forward(self,x): x = self.conv return x#%%x_train_rfe1 = torch.Tensor(x_train_rfe1.values)y_train = torch.Tensor(y_train.values.astype(np.int64))model = testmodel()y = model(x_train_rfe1)criterion = nn.MSELoss()loss = criterion(y, y_train)print(loss)错误在哪里?网上一般都是这样写的吗?我该如何改进它?
添加回答
举报
0/150
提交
取消