我正在嘗試使用以下方法將我的資料集拆分為訓練集和測驗集:
for train_set, test_set in stratified.split(complete_df, complete_df["loan_condition_int"]):
stratified_train = complete_df.loc[train_set]
stratified_test = complete_df.loc[test_set]
我的資料框complete_df沒有任何NaN價值。我通過使用complete_df.isnull().sum().max()which 回傳來確保它0。
但我仍然收到警告說:
Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.
并且它會導致稍后出錯。我嘗試使用我在網上找到的一些技術,但仍然無法解決。
uj5u.com熱心網友回復:
首先,您應該澄清什么是stratified. 我假設它是 sklearn 的StratifiedShuffleSplit物件。
我的資料集 complete_df 沒有任何 NAN 值。
警告訊息中的“缺失標簽”不是指缺失值,即 NaN。錯誤是說train_set和/或test_set包含在 的索引中不存在的值(標簽)complete_df。那是因為.loc根據行(和列)標簽而不是行位置執行索引,而train_set和test_set指示行號。因此,如果您的 DataFrame 的索引與行的整數位置不一致(似乎是這種情況),則會發出警告。
要按行位置選擇,請使用iloc。這應該作業
for train_set, test_set in stratified.split(complete_df, complete_df["loan_condition_int"]):
stratified_train = complete_df.iloc[train_set]
stratified_test = complete_df.iloc[test_set]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/343422.html
下一篇:從R中的資料幀串列進行子集化
