Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import time
  2. import sys
  3.  
  4. from sklearn import ensemble, datasets, model_selection, metrics
  5. import numpy as np
  6.  
  7. n_estimators = int(sys.argv[1])
  8.  
  9. rs = np.random.RandomState(12345)
  10.  
  11. X, y = datasets.make_classification(n_samples=10000, n_features=12,
  12. n_informative=12, n_redundant=0,
  13. n_repeated=0, random_state=rs)
  14. X = X.astype(np.float32)
  15.  
  16. X_train, X_test, y_train, y_test = \
  17. model_selection.train_test_split(X, y, test_size=0.8,
  18. random_state=rs)
  19.  
  20. rfc = ensemble.RandomForestClassifier(n_estimators=n_estimators,
  21. n_jobs=-1, random_state=rs)
  22. time1 = time.perf_counter()
  23. rfc.fit(X_train, y_train)
  24. time2 = time.perf_counter()
  25. proba = rfc.predict_proba(X_test)
  26. time3 = time.perf_counter()
  27.  
  28. print("{:5.3f} sec to fit".format(time2-time1))
  29. print("{:5.3f} sec to predict".format(time3-time2))
  30. print("{:5.3f} brier score".format(metrics.brier_score_loss(y_test, proba[:, 1])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement