Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. from sklearn.ensemble import RandomForestClassifier
  2. model = RandomForestClassifier(n_estimators=100, min_samples_leaf=10,
  3. random_state=1)
  4. model.fit(x_train, y_train)
  5. print(model.score)
  6. #Accuracy of prediction
  7. y_pred = model.predict(x_test)
  8. #Mean Standard Error
  9. mean_squared_error(y_pred, y_test)
  10. model.score(x_test, y_test)
  11. Out[423]: 0.80038542832276516
  12.  
  13. from sklearn.ensemble import GradientBoostingClassifier #For Classification
  14. clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
  15. max_depth=1)
  16. clf.fit(x_train, y_train)
  17.  
  18. clf.fit(x_train, y_train)
  19. Traceback (most recent call last):
  20.  
  21. File "<ipython-input-425-9249b506d83f>", line 1, in <module>
  22. clf.fit(x_train, y_train)
  23.  
  24. File "C:Anaconda3libsite-packagessklearnensemblegradient_boosting.py",
  25. line 973, in fit
  26. X, y = check_X_y(X, y, accept_sparse=['csr', 'csc', 'coo'], dtype=DTYPE)
  27.  
  28. File "C:Anaconda3libsite-packagessklearnutilsvalidation.py", line 526,
  29. in check_X_y
  30. y = column_or_1d(y, warn=True)
  31.  
  32. File "C:Anaconda3libsite-packagessklearnutilsvalidation.py", line 562,
  33. in column_or_1d
  34. raise ValueError("bad input shape {0}".format(shape))
  35.  
  36. ValueError: bad input shape (37533, 3)
  37.  
  38. print(x_train)
  39. No Yes
  40. 32912 1.0 0.0
  41. 35665 1.0 0.0
  42. 32436 1.0 0.0
  43. 25885 1.0 0.0
  44. 24896 1.0 0.0
  45. 51734 1.0 0.0
  46. 4235 1.0 0.0
  47. 51171 1.0 0.0
  48. 33221 0.0 1.0
  49.  
  50. print(y_train)
  51. Fatal Incident Non-Fatal
  52. 32912 0.0 0.0 1.0
  53. 35665 0.0 0.0 1.0
  54. 32436 0.0 0.0 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement