AttributeError:“顺序”对象没有属性“大小”

我是 pytorch 的新手,只是尝试编写一个网络。是data.shape(204,6170),最后 5 列是一些标签。数据中的数字是浮点数,如 0.030822。


#%%

from sklearn.feature_selection import RFE

import numpy as np

import pandas as pd

import torch

import torch.nn as nn

from sklearn.model_selection import train_test_split

import 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 LinearRegression

lr = 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)


错误在哪里?网上一般都是这样写的吗?我该如何改进它?


慕村225694
浏览 112回答 1
1回答

蝴蝶不菲

您永远不会x通过.convforwarddef forward(self, x):     x = self.conv(x)         return x
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python