python - AssertionError is raised when running an example from sklearn library -


import pandas pd import numpy np sklearn.learning_curve import learning_curve import matplotlib.pyplot plt   def plot_learning_curve(estimator, title, x, y, ylim=none, cv=none,                         n_jobs=1, train_sizes=np.linspace(.1, 1.0, 5)):     """     generate simple plot of test , traning learning curve.      parameters     ----------     estimator : object type implements "fit" , "predict" methods         object of type cloned each validation.      title : string         title chart.      x : array-like, shape (n_samples, n_features)         training vector, n_samples number of samples ,         n_features number of features.      y : array-like, shape (n_samples) or (n_samples, n_features), optional         target relative x classification or regression;         none unsupervised learning.      ylim : tuple, shape (ymin, ymax), optional         defines minimum , maximum yvalues plotted.      cv : integer, cross-validation generator, optional         if integer passed, number of folds (defaults 3).         specific cross-validation objects can passed, see         sklearn.cross_validation module list of possible objects      n_jobs : integer, optional         number of jobs run in parallel (default 1).     """     plt.figure()     plt.title(title)     if ylim not none:         plt.ylim(*ylim)     plt.xlabel("training examples")     plt.ylabel("score")     train_sizes, train_scores, test_scores = learning_curve(         estimator, x, y, cv=cv, n_jobs=n_jobs, train_sizes=train_sizes)     train_scores_mean = np.mean(train_scores, axis=1)     train_scores_std = np.std(train_scores, axis=1)     test_scores_mean = np.mean(test_scores, axis=1)     test_scores_std = np.std(test_scores, axis=1)     plt.grid()      plt.fill_between(train_sizes, train_scores_mean - train_scores_std,                      train_scores_mean + train_scores_std, alpha=0.1,                      color="r")     plt.fill_between(train_sizes, test_scores_mean - test_scores_std,                      test_scores_mean + test_scores_std, alpha=0.1, color="g")     plt.plot(train_sizes, train_scores_mean, 'o-', color="r",              label="training score")     plt.plot(train_sizes, test_scores_mean, 'o-', color="g",              label="cross-validation score")      plt.legend(loc="best")     return plt    forest = ensemble.randomforestclassifier(bootstrap=true, class_weight=none, max_depth=none, max_features='auto', max_leaf_nodes=none,min_samples_leaf=1, min_samples_split=6,min_weight_fraction_leaf=0.0, n_estimators=300, n_jobs=-1,oob_score=false, random_state=111, verbose=0, warm_start=false)  cv = cross_validation.shufflesplit(alldata.shape[0], n_iter=10,                                    test_size=0.2, random_state=0)  title = "learning curve (random forest)" plot_learning_curve(forest, title, alldata, y, ylim=none, cv=cv, n_jobs=-1)  plt.show() 

when run code in ipython notebook (python 2.7), following error can seen cmd. took function plot_learning_curve the following website.

enter image description here

with code got this

milenko@milenko-x58-usb3:~$ python k1.py  traceback (most recent call last):   file "k1.py", line 68, in <module>     forest = ensemble.randomforestclassifier(bootstrap=true, class_weight=none, max_depth=none, max_features='auto', max_leaf_nodes=none,min_samples_leaf=1, min_samples_split=6,min_weight_fraction_leaf=0.0, n_estimators=300, n_jobs=-1,oob_score=false, random_state=111, verbose=0, warm_start=false) nameerror: name 'ensemble' not defined 

my python version

python 2.7.11 :: anaconda 2.4.1 (64-bit) 

i think should create class ensemble.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -