第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在 sklearn 中為 dictvectorizer 和 Linearsvc 創(chuàng)建管道

在 sklearn 中為 dictvectorizer 和 Linearsvc 創(chuàng)建管道

喵喔喔 2023-07-18 10:23:35
根據(jù)我所讀到的內(nèi)容,我需要?jiǎng)?chuàng)建模型并將其保存為管道才能執(zhí)行此操作。我一直在嘗試根據(jù) SO 上的其他示例來執(zhí)行此操作,但無法使其工作。如何將現(xiàn)有模型轉(zhuǎn)變?yōu)榱魉€版本?第一個(gè)代碼片段保存,第二個(gè)代碼片段是我將其放入管道的嘗試之一,但我收到“str”對象沒有屬性“items”錯(cuò)誤。我認(rèn)為這與 to_dict 過程有關(guān),但不知道如何在管道版本中復(fù)制它,任何人都可以提供幫助。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)vectorizer = DictVectorizer()X = vectorizer.fit_transform(x_df.to_dict("records"))y = dframe.tag.valuesx_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=0)model = LinearSVC(loss="squared_hinge",C=0.5,class_weight='balanced',multi_class='ovr')model.fit(x_train, y_train)dump(model, 'filename.joblib')?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.valuesx_train, x_test, y_train, y_test = train_test_split(x_df, y, test_size=0.1, random_state=0)pipe = Pipeline([('vectorizer', DictVectorizer(x_df.to_dict("records"))), ('model', LinearSVC)])?pipe.fit(x_train, y_train)
查看完整描述

1 回答

?
慕容708150

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)


查看完整回答
反對 回復(fù) 2023-07-18
  • 1 回答
  • 0 關(guān)注
  • 104 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號