1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超4個(gè)贊
你必須像這樣調(diào)整你的第二部分:
dframe = pd.read_csv("ner.csv", encoding = "ISO-8859-1", error_bad_lines=False)
dframe.dropna(inplace=True)
dframe[dframe.isnull().any(axis=1)].size?
x_df = dframe.drop(['Unnamed: 0', 'sentence_idx', 'tag'], axis=1)
y = dframe.tag.values
x_train, x_test, y_train, y_test = train_test_split(x_df.to_dict("records"), y, test_size=0.1, random_state=0)
pipe = Pipeline([('vectorizer', DictVectorizer()), ('model', LinearSVC(loss="squared_hinge",C=0.5,class_weight='balanced',multi_class='ovr'))])?
pipe.fit(x_train, y_train)
您試圖DictVectorizer()
通過使用在參數(shù)中傳遞您的數(shù)據(jù)
DictVectorizer(x_df.to_dict("記錄"))
但這不起作用。DictVectorizer 的唯一可用參數(shù)可以在文檔中找到。
第二個(gè)錯(cuò)誤是您嘗試將 DictVectorizer() 與來自 x_df 的數(shù)據(jù)一起放入管道中
管道.fit(x_train,y_train)
這里的問題是 x_train 數(shù)據(jù)將提供給您的DictVectorizer()
,但 x_train 只是分割 x_df ,并且在您的代碼中沒有管道的早期,您ictVectorizer()
以 的形式向 D 提供了數(shù)據(jù)x_df.to_dict("records")
。
因此,您還需要通過管道傳遞相同類型的數(shù)據(jù)。這就是為什么我已經(jīng)將調(diào)整后的代碼中x_df.to_dict("records")
的 與分開train_test_split()
,以便矢量化器可以處理它。
最后一件事是,在定義管道時(shí)您還忘記了括號LinearSVC()
(“模型”,LinearSVC)
添加回答
舉報(bào)