向训练数据添加行的最佳方法是什么?
import numpy as np
import pandas as pd
# Features=x / Labels=y
new_train1 = pd.DataFrame({'A': [1,2,3,3,4,4],
'B': [4,5,6,6,4,3],
'C': ['a','b','c','ddd','c','ddd']})
new_train2 = pd.DataFrame({'A': [1],
'B': [4],
'C': ['a']})
# Add new_train2's row to new_train1.
也许这会奏效:
new_train1 = new_train1.append(new_train2)
new_train1 = new_train1.reset_index(drop=True)
最后,数据被分成要素和标签。
new_train_x = new_train1.iloc[:,0:1] # Cols A and B
new_train_y = new_train1['C']
编辑:值得注意的是,在尝试此过程(添加一行)后,这里是混淆矩阵(#s来自实际数据集,而非上面的样本集):
[[336 0 7 0 3 0]
[ 23 8 358 0 0 3]
[ 0 0 373 1 0 0]
[ 0 0 0 281 30 25]
[ 0 0 0 14 220 33]
[ 0 0 0 6 14 265]]
在添加行之前(每当多次删除一行时),这里是典型的混淆矩阵(再次使用实际数据中的#s而不是样本数据):
[[343 0 0 0 3 0]
[ 2 349 39 0 0 2]
[ 0 52 322 0 0 0]
[ 0 0 0 330 3 3]
[ 0 0 0 3 261 3]
[ 0 0 0 2 1 282]]
以下是添加或删除任何数据点之前的混淆矩阵:
[[343 0 0 0 3 0]
[ 3 355 31 0 0 3]
[ 0 30 344 0 0 0]
[ 0 0 0 331 1 4]
[ 0 0 0 1 261 5]
[ 0 0 0 3 4 278]]