Untitled

From Chartreuse Hornbill, 2 Months ago, written in Plain Text, viewed 48 times.
URL http://codebin.org/view/a01dc4be Embed
Download Paste or View Raw
  1. model = RandomForestClassifier()
  2. parametrs = ({'max_depth':range(2, 10),
  3.             'n_estimators':range(1, 81, 5)
  4.              })
  5. grid_search_cv_model = GridSearchCV(model, parametrs, scoring='recall', n_jobs=-1, cv=4)
  6. %%time
  7. grid_search_cv_model.fit(features_tr, target)
  8.  
  9. grid_search_cv_model.best_params_
  10. #выдал {'max_depth': 9, 'n_estimators': 6}
  11. grid_search_cv_model.best_score_
  12. #выдал 0.5176759274663117
  13.  
  14. потом разбила (features_tr, target) на таргет и валидацию
  15.  
  16. %%time
  17.      
  18. best_model = None
  19. best_result = 0
  20. best_est = 0
  21. best_depth = 0
  22. for est in range(1, 81, 5):
  23.     for depth in range (1, 21):
  24.         model = RandomForestClassifier(random_state=12345, n_estimators=est, max_depth=depth)
  25.         model.fit(features_train,target_train)
  26.         pred=model.predict(features_valid)
  27.         result = recall_score(target_valid,pred)
  28.        
  29.         if result > best_result:
  30.             best_model = model
  31.             best_result = result
  32.             best_est = est
  33.             best_depth = depth
  34.            
  35. print("Recall наилучшей модели на валидационной выборке:", best_result)
  36. print(best_model)
  37.  
  38. #получила Recall наилучшей модели на валидационной выборке: 0.7912161038096822
  39. RandomForestClassifier(max_depth=20, n_estimators=41, random_state=12345)
  40.  

Reply to "Untitled"

Here you can reply to the paste above