} c2_vect_options = { 'ngram_range': (1,1), 'sublinear_tf': True, 'smooth_idf': True, 'preprocessor': pr.no_usernames, 'use_idf': True, 'stop_words': None } c1_default_options = { 'penalty': 'l1', 'C': 1.0 } c2_default_options = { 'C': 1.0 } c1 = MaxEnt(docs_train_subjectivity, y_train_subjectivity, default_options=c1_default_options, vect_options=c1_vect_options) c2 = SVM(docs_train_polarity, y_train_polarity, default_options=c2_default_options, vect_options=c2_vect_options) clf = Combined(c1, c2) if len(sys.argv) > 1: y_predicted = clf.predict(docs_test) sys.stdout.write(pe.predictions_as_str(y_predicted)) else: s.test_clf(clf, docs_test, y_test)
rect = ax.bar(ind+(width * x) + 4, res[x], width, color=colors[x]) autolabel(rect) # fig.autofmt_xdate() # Shink current axis by 20% box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax.legend( ['Precision', 'Recall', 'F1 Score', 'Accuracy'], loc='center left', bbox_to_anchor=(1, 0.5) ) savefig("plots/round2/maxent_extra.png", format="png") plt.clf() fig = plt.figure(2) ax = fig.add_subplot(111) plt.title('Confusion Matrix For MaxEnt, w/NTNU') res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest') for i, cas in enumerate(conf_arr): for j, c in enumerate(cas): if c>0: plt.text(j-.2, i+.2, c, fontsize=14) cb = fig.colorbar(res) savefig("plots/round2/maxent_confuse_extra.png", format="png") stat.test_clf(clf, docs_test, y_test)
for i, l in enumerate(labels): for x, y in enumerate(res): rect = ax.bar(ind + (width * x) + 4, res[x], width, color=colors[x]) autolabel(rect) # fig.autofmt_xdate() # Shink current axis by 20% box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.8, box.height]) ax.legend(['Precision', 'Recall', 'F1 Score', 'Accuracy'], loc='center left', bbox_to_anchor=(1, 0.5)) savefig("plots/round2/svm_orig.png", format="png") plt.clf() fig = plt.figure(2) ax = fig.add_subplot(111) plt.title('Confusion Matrix For SVM') res = ax.imshow(array(norm_conf), cmap=cm.jet, interpolation='nearest') for i, cas in enumerate(conf_arr): for j, c in enumerate(cas): if c > 0: plt.text(j - .2, i + .2, c, fontsize=14) cb = fig.colorbar(res) savefig("plots/round2/svm_confuse_orig.png", format="png") stat.test_clf(clf, docs_test, y_test)