Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a7aab7e

Browse files
Update 06-数据汇总.md
1 parent 7c3d8fe commit a7aab7e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎06-数据汇总.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ df.sample(n=6, replace=False)
6666
# 采样后放回
6767
df.sample(n=6, replace=True)
6868

69+
# 打乱数据顺序
70+
from sklearn.utils import shuffle
71+
df = shuffle(df, random_state=10).reset_index(drop=True)
72+
73+
# 下采样
74+
from imblearn.under_sampling import RandomUnderSampler
75+
RUS = RandomUnderSampler(random_state=10, ratio=0.3)
76+
X_RUS, y_RUS = RUS.fit_sample(X_train, y_train)
77+
X_RUS = pd.DataFrame(X_RUS, columns = list(X_train.columns))
78+
y_RUS = pd.DataFrame(y_RUS, columns= {'y'})
79+
y_RUS['y'].value_counts()
80+
df_rus = y_RUS.join(X_RUS)
81+
6982
# 数据表描述性统计
7083
df.describe().round(2).T
7184

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /