我的資料集由 32 列組成,但在尋找重要特征后,我發現其中 4 個是最重要的,所以我想只處理它們,但這個錯誤讓我面臨:
這是我的代碼:
df = pd.read_csv("/content/drive/MyDrive/deepLearning/wisc_bc_data.csv")
df = df.rename(columns={'diagnosis':'Label'})
dff = pd.DataFrame(df, columns=['perimeter_worst', 'texture_worst', 'area_worst', 'area_mean','Label'])
x = pd.DataFrame(dff, columns=['perimeter_worst', 'texture_worst', 'area_worst', 'area_mean'])
y = dff["Label"].values
# Encoding categorical data from text (B and M) to integers (0 and 1)
from sklearn.preprocessing import LabelEncoder
labelencoder = LabelEncoder()
Y = labelencoder.fit_transform(y) # M=1 and B=0
print("Labels after encoding are: ", np.unique(Y))
y_array = pd.DataFrame(Y, columns=['Label'])
#Split data into train and test to verify accuracy after fitting the model.
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(x, y_array, test_size=0.25, random_state=42)
print("Shape of training data is: ", X_train.shape)
print("Shape of testing data is: ", X_test.shape)
model_important = Sequential()
model_important.add(Dense(16, input_dim=30, activation='relu'))
model_important.add(Dropout(0.2))
model_important.add(Dense(1))
model_important.add(Activation('sigmoid'))
model_important.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model_important.summary())
但這是錯誤:
history = model_important.fit(X_train, y_train, verbose=1, epochs=100, batch_size=64,
validation_data=(X_test, y_test))
ValueError:層“sequential_21”的輸入0與層不兼容:預期形狀=(無,30),發現形狀=(無,4)
你能幫助我嗎
uj5u.com熱心網友回復:
你有這行代碼
model_important.add(Dense(16, input_dim=30, activation='relu'))
您將輸入尺寸設定為 30 將其更改為 4
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/419550.html
標籤:
上一篇:InvalidArgumentError:logits和標簽必須具有相同的第一維,得到logits形狀[15488,3]和標簽形狀[32]
