在上采样后将 numpy.ndarry 转换为维护索引的 DataFrame
convert numpy.ndarry to DataFrame maintaining indices after upsampling
X_train_1, X_test_1, y_train_1, y_test = train_test_split(x, y,
test_size = .3)
X_train_sam, y_train_sam = ADASYN(random_state=42).fit_sample(X_train_1, y_train_1)
type(X_train_1)
pandas.core.frame.DataFrame
X_train_1.shape
(1668, 353)
type(X_train_sam)
numpy.ndarray
X_train_sam.shape
(2698, 353)
如何将 X_train_sam 转换回数据框,使其与 X_train_1[=16= 相同] 并在向新数据添加索引的同时维护索引 ?
像这样:
result = pd.DataFrame(X_train_sam)
result.columns = train_1.columns
X_train_1, X_test_1, y_train_1, y_test = train_test_split(x, y,
test_size = .3)
X_train_sam, y_train_sam = ADASYN(random_state=42).fit_sample(X_train_1, y_train_1)
type(X_train_1)
pandas.core.frame.DataFrame
X_train_1.shape
(1668, 353)
type(X_train_sam)
numpy.ndarray
X_train_sam.shape
(2698, 353)
如何将 X_train_sam 转换回数据框,使其与 X_train_1[=16= 相同] 并在向新数据添加索引的同时维护索引 ?
像这样:
result = pd.DataFrame(X_train_sam)
result.columns = train_1.columns