我有一个名为ds
的数据框架,其中有3列数据,如下所示
text count label
0 I have... 12 pos
1 You sh... 8 neg
2 In thi... 9 neg
.
.
我给出了一个例子,只使用text
创建测试和培训数据,代码如下
X = ds['text']
y = ds['label']
train_X, test_X, train_Y, test_Y = train_test_split(X, y, test_size=0.25, random_state=0)
df_train75 = pd.DataFrame()
df_train75['text'] = train_X
df_train75['label'] = train_Y
df_test25 = pd.DataFrame()
df_test25['text'] = test_X
df_test25['label'] = test_Y
from sklearn.feature_extraction.text import TfidfVectorizer
tfidf_vect_7525 = TfidfVectorizer(ngram_range = (1, 1))
tfidf_vect_7525.fit(ds['text'])
train_X_tfidf_7525 = tfidf_vect_7525.transform(df_train75['text'])
test_X_tfidf_7525 = tfidf_vect_7525.transform(df_test25['text'])
from sklearn.svm import SVC
model = SVC(kernel='linear')
model.fit(train_X_tfidf_7525,train_Y)
====================================================================================================================================
我试图通过简单地用修改第一行来包含text
和count
列
X = ds[['text', 'count']
这给了我一个错误
from sklearn.svm import SVC
model = SVC(kernel='linear')
model.fit(train_X_tfidf_9010,train_Y)
====================================================================================================================================
我的问题是,我应该如何处理这个问题?我试图研究另一个问题,但没有找到答案。我发现的一个“解决方案”是使用
X = ds['text'].astype(str) + ' ' + ds['count'].astype(str)
但我认为这不是解决这个问题的正确选择。 提前谢谢你
您可以运行一个service来schedules执行一个runnable
24小时后。 比如:
你也可以使用Timer
相关问题 更多 >
编程相关推荐