Hi sir. I could not preform the visualization for the performance matrix. It is showing me error:
Import the three supervised learning models from sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.neighbors import KNeighborsClassifier
Initialize the three models
clf_A = RandomForestClassifier(random_state = 50)
clf_B = AdaBoostClassifier(random_state = 50)
clf_C = KNeighborsClassifier()
Calculate the number of samples for 1%, 10%, and 100% of the training data
samples_1 = X_train.shape[0] * 1/100
samples_1 = math.trunc(samples_1)
samples_10 = X_train.shape[0] * 10/100
samples_10= math.trunc(samples_10)
samples_100 = X_train.shape[0] * 100/100
samples_100 = math.trunc(samples_100)
#print samples_1," ",samples_10," ",samples_100," "
Collect results on the learners
results = {}
for clf in [clf_A,clf_B,clf_C]:
clf_name = clf.class.name
results[clf_name] = {}
for i, samples in enumerate([samples_1, samples_10, samples_100]):
results[clf_name][i] = train_predict(clf, samples, X_train, y_train, X_test, y_test)
Run metrics visualization for the three supervised learning models chosen
vs.evaluate(results, accuracy, fscore)
RandomForestClassifier trained on 361 samples.
RandomForestClassifier trained on 3617 samples.
RandomForestClassifier trained on 36177 samples.
AdaBoostClassifier trained on 361 samples.
AdaBoostClassifier trained on 3617 samples.
AdaBoostClassifier trained on 36177 samples.
KNeighborsClassifier trained on 361 samples.
KNeighborsClassifier trained on 3617 samples.
KNeighborsClassifier trained on 36177 samples.
IndexError Traceback (most recent call last)
in
28
29 # Run metrics visualization for the three supervised learning models chosen
---> 30 vs.evaluate(results, accuracy, fscore)
~\Downloads\charity_donors-master\charity_donors-master\visuals.py in evaluate(results, accuracy, f1)
73
74 # Creative plot code
---> 75 ax[j/3, j%3].bar(i+k*bar_width, results[learner][i][metric], width = bar_width, color = colors[k])
76 ax[j/3, j%3].set_xticks([0.45, 1.45, 2.45])
77 ax[j/3, j%3].set_xticklabels(["1%", "10%", "100%"])
IndexError: only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices