第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

隨機森林在訓(xùn)練和測試中獲得 98% 的準確率,但在其他情況下總是預(yù)測同一類

隨機森林在訓(xùn)練和測試中獲得 98% 的準確率,但在其他情況下總是預(yù)測同一類

繁星coding 2023-08-22 14:58:28
我花了 30 個小時來調(diào)試這個問題,但它完全沒有意義,希望你們中的一個人可以向我展示不同的觀點。問題是,我在隨機森林中使用訓(xùn)練數(shù)據(jù)幀并獲得了 98%-99% 的良好準確率,但是當我嘗試加載新樣本進行預(yù)測時。該模型總是猜測同一類。#  Shuffle the data-frames records. The labels are still attacheddf = df.sample(frac=1).reset_index(drop=True)#  Extract the labels and then remove them from the datay = list(df['label'])X = df.drop(['label'], axis='columns')#  Split the data into training and testing setsX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=TEST_SIZE)#  Construct the modelmodel = RandomForestClassifier(n_estimators=N_ESTIMATORS, max_depth=MAX_DEPTH, random_state=RANDOM_STATE,oob_score=True)#  Calculate the training accuracyin_sample_accuracy = model.fit(X_train, y_train).score(X_train, y_train)#  Calculate the testing accuracytest_accuracy = model.score(X_test, y_test)print()print('In Sample Accuracy: {:.2f}%'.format(model.oob_score_ * 100))print('Test Accuracy: {:.2f}%'.format(test_accuracy * 100))我處理數(shù)據(jù)的方式是相同的,但是當我對 X_test 或 X_train 進行預(yù)測時,我得到了正常的 98%,當我對新數(shù)據(jù)進行預(yù)測時,它總是猜測相同的類。    #  The json file is not in the correct format, this function normalizes it    normalized_json = json_normalizer(json_file, "", training=False)    #  Turn the json into a list of dictionaries which contain the features    features_dict = create_dict(normalized_json, label=None)    #  Convert the dictionaries into pandas dataframes    df = pd.DataFrame.from_records(features_dict)    print('Total amount of email samples: ', len(df))    print()    df = df.fillna(-1)    #  One hot encodes string values    df = one_hot_encode(df, noOverride=True)    if 'label' in df.columns:        df = df.drop(['label'], axis='columns')    print(list(model.predict(df))[:100])    print(list(model.predict(X_train))[:100])上面是我的測試場景,你可以在最后兩行看到我對X_train用于訓(xùn)練模型的數(shù)據(jù)和df樣本外數(shù)據(jù)的預(yù)測,它總是猜測類別 0。一些有用的信息:數(shù)據(jù)集不平衡;0 類大約有 150,000 個樣本,而 1 類大約有 600,000 個樣本有141個功能更改 n_estimators 和 max_depth 并不能解決問題任何想法都會有幫助,如果您需要更多信息,請讓我知道我的大腦現(xiàn)在很混亂,這就是我能想到的。
查看完整描述

1 回答

?
慕沐林林

TA貢獻2016條經(jīng)驗 獲得超9個贊

已修復(fù),問題是數(shù)據(jù)集不平衡,我也意識到改變深度會給我不同的結(jié)果。

例如,10 棵深度為 3 的樹 -> 似乎工作正常 10 棵深度為 6 的樹 -> 回到猜測同一類


查看完整回答
反對 回復(fù) 2023-08-22
  • 1 回答
  • 0 關(guān)注
  • 1736 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號