Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. df = pd.read_csv('gym_churn.csv')
  2.  
  3. df_train, df_valid = train_test_split(df, test_size=0.25, random_state=12345)
  4.  
  5. features_train = df_train.drop(['Churn',
  6. 'gender',
  7. 'Phone',
  8. #'Contract_period',
  9. #'Age',
  10. #'Avg_additional_charges_total',
  11. #'Month_to_end_contract',
  12. #'Lifetime',
  13. #'Avg_class_frequency_total',
  14. #'Avg_class_frequency_current_month'
  15. ], axis = 1)
  16. target_train = df_train['Churn']
  17.  
  18. features_valid = df_valid.drop(['Churn',
  19. 'gender',
  20. 'Phone',
  21. #'Contract_period',
  22. #'Age',
  23. #'Avg_additional_charges_total',
  24. #'Month_to_end_contract',
  25. #'Lifetime',
  26. #'Avg_class_frequency_total',
  27. #'Avg_class_frequency_current_month'
  28. ], axis = 1)
  29. target_valid = df_valid['Churn']
  30.  
  31. for estim in range(5, 70, 5):
  32. model_RF = RandomForestRegressor(random_state=12345, n_estimators=estim)
  33. model_RF.fit(features_train, target_train)
  34. predictions_valid = model_RF.predict(features_valid)
  35. print(predictions_valid)
  36. mse = mean_squared_error(target_valid, predictions_valid)
  37. rmse = mse**0.5
  38.  
  39. print('Estimators:', estim)
  40. print('Rmse:', round(rmse, 2))
  41. print('Accuracy:', accuracy_score(target_valid, predictions_valid))
  42. print('Precision:', precision_score(target_valid, predictions_valid))
  43. print('Recal:', recall_score(target_valid, predictions_valid))
  44. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement