我想在熊猫数据框中插入X_test值:
我已经使用X_train,X_test,y_train,y_test完成了典型的机器学习过程
然后我创建了一个熊猫数据框:
df = pd.DataFrame(data, columns = ['X_test'])
但是当我打印数据框时,显示的只是NaN值:
X_test
17134 NaN
17135 NaN
17136 NaN
17137 NaN
17138 NaN
... ...
20555 NaN
20556 NaN
20557 NaN
20558 NaN
20559 NaN
为什么?有人可以帮忙吗?
更新:
这是我使用的代码:
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm import LinearSVC
from sklearn import metrics
from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer()
#Da X_train bereits konvertierte Zahlen enthält, muss der Train-Test-Split-Vorgang wiederholt werden
from sklearn.model_selection import train_test_split
X = data_processed['CONTENT'] # dieses Mal betrachten wir den Text
y = data_processed['LABEL']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
text_clf_lsvc = Pipeline([('tfidf', TfidfVectorizer()),
('clf', LinearSVC()), ]) text_clf_lsvc.fit(X_train, y_train)
# Erzeuge einen Satz von Vorhersagen
predictions = text_clf_lsvc.predict(X_test)
我的预测数组如下:
array(['not positive', 'positive', 'positive', 'positive', 'not positive',
'not positive', 'positive', 'positive', 'not positive', 'positive',
'positive', 'positive', 'positive', 'not positive', 'not positive',
'positive', 'not positive', 'not positive', 'positive', 'positive',
'positive', 'not positive', 'positive', 'positive', 'positive',
'positive', 'positive', 'positive'], dtype=object)
X_test看起来像这样:
DOC_ID
30 stephen hawking warns artificial intelligence ...
0 artificial intelligence ai is increasingly moc...
22 how artificial intelligence is helpful in mobi...
31 in the world faced devastating pandemic of an ...
18 should artificial intelligence be regulated ne...
28 some million people in england are at high ris...
10 advantages and disadvantages of artificial int...
53 artificial intelligence ai is proving to be do...
4 artificial intelligence will do what we ask th...
12 artificial intelligence in business business b...
49 google new ai tool helps sort through coronavi...
33 benefits of artificial intelligence ai is the ...
69 with so much buzz surrounding ai it seems like...
35 risks of artificial intelligence lack of trans...
70 how worried should we be about artificial inte...
45 ai vs coronavirus how artificial intelligence ...
75 ai is hurting people of color and the poor exp...
67 risks from artificial intelligence recent year...
56 in our last article we already reported what a...
40 ai vs coronavirus how artificial intelligence ...
9 artificial intelligence for good in recent yea...
61 artificial intelligence for good industry and ...