我想执行逻辑回归,但我不知道如何编码输入。我已经把数据分开了。
我的df有以下列:
doc_no,personal_no,记号(使用spacy的预处理文本),日和分数
数据类型:
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 doc_no 30363 non-null int64
1 personal_no 30363 non-null int64
2 tokens 30363 non-null object
3 day 30363 non-null object
4 score 30363 non-null object
dtypes: int64(2), object(3)这些标记看起来像一个列表。日期如下: MAY03,JUN05等。分数是0或1分。
我想预测基于令牌的分数。
我把数据分开:
columns = ['doc_no', 'personal_no', 'tokens', 'day', 'score']
df = df_new.loc[:, columns]
# arranging the data
features = ['doc_no', 'personal_no', 'tokens', 'day']
X = df.loc[:, features]
y = df.loc[:, ['score']]
# train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0,
train_size=0.8)我知道我需要用TF-以色列国防军将令牌矢量化我想?但到目前为止还不起作用。当我尝试运行这个:
model = LogisticRegression().fit(X_train, y_train) 我知道这个错误:
ValueError: could not convert string to float: "['word', 'word', 'word', 'word']我将内容改为“word”,因为我的数据对隐私敏感。
我做什么好?
我还想对这些数据执行随机森林和梯度增强决策树。对于这些算法,我还需要考虑其他的问题吗?
提前感谢!
发布于 2022-06-14 13:12:28
TfidfVectorizer (我想你谈论的是从滑雪而来的)作品来自文本。因此,如果您的文本已经被标记,您不能使用它。
您可以将公式应用于自己,这非常简单,或者您可以执行以下操作:
tokens = [" ".join(ts) for ts in tokens]
tfifd_scores = TfidfVectorizer().fit_transform(tokens)注:我想你从spacy得到的记号和你从sklearn得到的不同。否则,只需跳过标记化,直接处理文本。
https://stackoverflow.com/questions/72616802
复制相似问题