Пример #1
0
 plt.legend()
 plt.xlabel("bumpiness")
 plt.ylabel("grade")
 plt.show()
 
 ################################################################################
 
 ### your code here!  name your classifier object clf if you want the 
 ### visualization code (prettyPicture) to show you the decision boundary
 
 from sklearn.ensemble import RandomForestClassifier
 from sklearn.metrics import accuracy_score
 from time import time
 
 features_train, labels_train = RandomForestClassifier.make_classification(n_samples=10, n_features=1,
                                                                           n_informative=2, n_redundant=0,
                                                                           random_state=0, shuffle=False)
 clf = RandomForestClassifier(max_depth=2, random_state=0)
 t0 = time()
 clf.fit(features_train, labels_train)
 print("training time:", round(time()-t0, 3), "s")
 t0 = time()
 pred = clf.predict(features_test)
 
 print("predict time:", round(time()-t0, 3), "s")
 
 ## call the method to show the updated chart.
 
 print("Accuracy precision for Random Forest: %r" % accuracy_score(pred, labels_test))
 print("10th: %r, 26th: %r, 50th: %r" % (pred[10], pred[26], pred[50]))
 print("No. of predicted to be in the 'Chris'(1): %r" % sum(pred))