import tensorflow as tfimport pandas as pdimport numpy as npimport matplotlib as pltfrom sklearn.model_selection import train_test_splitfrom tensorflow import kerasfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Densefrom sklearn.preprocessing import StandardScalerimport functoolsLABEL_COLUMN = 'Endstage'LABELS = [1, 2, 3, 4]x = pd.read_csv('HCVnew.csv', index_col=False)def get_dataset(file_path, **kwargs): dataset = tf.data.experimental.make_csv_dataset( file_path, batch_size=35, # Artificially small to make examples easier to show. label_name=LABEL_COLUMN, na_value="?", num_epochs=1, ignore_errors=True, **kwargs) return datasetSELECT_COLUMNS = ["Alter", "Gender", "BMI", "Fever", "Nausea", "Fatigue", "WBC", "RBC", "HGB", "Plat", "AST1", "ALT1", "ALT4", "ALT12", "ALT24", "ALT36", "ALT48", "ALT24w", "RNABase", "RNA4", "Baseline", "Endstage"]DEFAULTS = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]temp_dataset = get_dataset("HCVnew.csv", select_columns=SELECT_COLUMNS, column_defaults=DEFAULTS)def pack(features, label): return tf.stack(list(features.values()), axis=-1), labelpacked_dataset = temp_dataset.map(pack)"""for features, labels in packed_dataset.take(1): print(features.numpy()) print() print(labels.numpy())"""NUMERIC_FEATURES = ["Alter", "Gender","BMI", "Fever", "Nausea", "Fatigue", "WBC", "RBC", "HGB", "Plat", "AST1", "ALT1", "ALT4", "ALT12", "ALT24", "ALT36", "ALT48", "ALT24w", "RNABase", "RNA4", "Baseline", "Endstage"]您好,我正在嘗試構建一個神經(jīng)網(wǎng)絡,該神經(jīng)網(wǎng)絡可以根據(jù)包含患者信息的csv文件預測丙型肝炎,我無法修復錯誤...我收到錯誤:KeyError'Endstage',而Endstage是包含相應值(介于1和4之間)并用作標簽列的csv列。如果有人有一個想法可以解決我的問題,那么請告訴我。非常感謝您的幫助!
1 回答

小怪獸愛吃肉
TA貢獻1852條經(jīng)驗 獲得超1個贊
這是因為是你的標簽列,框架通過從數(shù)據(jù)集中刪除(彈出)它來幫你一個忙。否則,您的訓練數(shù)據(jù)集也將具有目標類,使其無用。Endstage
將其從任何其他位置刪除,使其進入訓練集功能。NUMERIC_FEATURES
[編輯]
OP在后續(xù)問題(在評論中)中詢問了為什么在修復初始問題后,他會遇到錯誤:
值錯誤:特征數(shù)字不在特征字典中
從外觀上看,調用的特征是通過調用 來生成的。后者用于創(chuàng)建 和 ,但這些從不使用。然而,這句話:numeric
PackNumericFeatures
packed_train_data
packed_test_data
numeric_column = tf.feature_column.numeric_column('numeric', normalizer_fn=normalizer, shape=[len(NUMERIC_FEATURES)])
假設數(shù)據(jù)在那里 - 因此出現(xiàn)錯誤。
添加回答
舉報
0/150
提交
取消