1 回答
TA贡献1831条经验 获得超4个赞
你必须像这样调整你的第二部分:
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()
通过使用在参数中传递您的数据
DictVectorizer(x_df.to_dict("记录"))
但这不起作用。DictVectorizer 的唯一可用参数可以在文档中找到。
第二个错误是您尝试将 DictVectorizer() 与来自 x_df 的数据一起放入管道中
管道.fit(x_train,y_train)
这里的问题是 x_train 数据将提供给您的DictVectorizer()
,但 x_train 只是分割 x_df ,并且在您的代码中没有管道的早期,您ictVectorizer()
以 的形式向 D 提供了数据x_df.to_dict("records")
。
因此,您还需要通过管道传递相同类型的数据。这就是为什么我已经将调整后的代码中x_df.to_dict("records")
的 与分开train_test_split()
,以便矢量化器可以处理它。
最后一件事是,在定义管道时您还忘记了括号LinearSVC()
(“模型”,LinearSVC)
添加回答
举报