<jupyter_start><jupyter_text>SVM Hard Margin Classifier<jupyter_code>classifier_hard = svm.SVC(C=1000, probability=True, kernel='linear')
classifier_hard.fit(train_x, y_train.astype(int))
y_predict_hard = classifier_hard.predict(test_x)
y_predict_hard_prob = classifier_hard.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_hard_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict_hard))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict_hard))
print("Precision : ",precision_score(y_test.astype(int), y_predict_hard))
print("Recall : ",recall_score(y_test.astype(int), y_predict_hard))

print(classification_report(y_test.astype(int), y_predict_hard, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output><jupyter_text>SVM Soft Margin Classifier<jupyter_code>classifier_soft = svm.SVC(C=0.001, probability=True, kernel='linear')
classifier_soft.fit(train_x, y_train.astype(int))
y_predict_soft = classifier_soft.predict(test_x)
y_predict_soft_prob = classifier_soft.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_soft_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict_soft))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict_soft))
print("Precision : ",precision_score(y_test.astype(int), y_predict_soft))
print("Recall : ",recall_score(y_test.astype(int), y_predict_soft))

print(classification_report(y_test.astype(int), y_predict_soft, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output><jupyter_text>Finding the best value of Gamma<jupyter_code>gamma_values = [0.001, 0.01, 0.1, 1, 10, 100, 1000]
grid5 = GridSearchCV(svm.SVC(), param_grid=dict(C=gamma_values, kernel=['linear']), cv=5)
grid5.fit(train_x, y_train.astype(int))
print(grid5.best_score_)
print(grid5.best_estimator_)
y_predict_best5 = grid5.predict(test_x)
print(classification_report(y_test.astype(int), y_predict_best5, target_names=['Washington', 'Masachussets']))
print("Accuracy Score: " + str(accuracy_score(y_test.astype(int), y_predict_best5)))
confusion_matrix(y_test.astype(int), y_predict_best5)<jupyter_output>precision    recall  f1-score   support

  Washington       0.71      0.94      0.81      4490
Masachussets       0.81      0.42      0.55      2909

 avg / total       0.75      0.73      0.71      7399

Accuracy Score: 0.7321259629679686<jupyter_text>Logistic Regression without regularization<jupyter_code>logistic_clf = LogisticRegression(penalty='l2', C=1e10)
logistic_clf.fit(train_x, y_train.astype(int))
y_predict = logistic_clf.predict(test_x)
y_predict_prob = logistic_clf.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict))
print("Precision : ",precision_score(y_test.astype(int), y_predict))
print("Recall : ",recall_score(y_test.astype(int), y_predict))

print(classification_report(y_test.astype(int), y_predict, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output><jupyter_text>Logistic Regression with L2 regularization<jupyter_code>logistic_clf = LogisticRegression(penalty='l2', C=1000)
logistic_clf.fit(train_x, y_train.astype(int))
y_predict = logistic_clf.predict(test_x)
y_predict_prob = logistic_clf.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict))
print("Precision : ",precision_score(y_test.astype(int), y_predict))
print("Recall : ",recall_score(y_test.astype(int), y_predict))

print(classification_report(y_test.astype(int), y_predict, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output><jupyter_text>Logistic Regression with L1 regularization<jupyter_code>logistic_clf = LogisticRegression(penalty='l1', C=1000)
logistic_clf.fit(train_x, y_train.astype(int))
y_predict = logistic_clf.predict(test_x)
y_predict_prob = logistic_clf.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict))
print("Precision : ",precision_score(y_test.astype(int), y_predict))
print("Recall : ",recall_score(y_test.astype(int), y_predict))

print(classification_report(y_test.astype(int), y_predict, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output><jupyter_text>Random Forest Classifier<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rforest_clf = RandomForestClassifier(n_estimators = 150)
rforest_clf.fit(train_x, y_train.astype(int))
y_predict = rforest_clf.predict(test_x)
y_predict_prob = rforest_clf.predict_proba(test_x)
skplt.metrics.plot_roc_curve(y_test.astype(int), y_predict_prob)
plt.show()
print(confusion_matrix(y_test.astype(int), y_predict))
print("Accuracy : ", accuracy_score(y_test.astype(int), y_predict))
print("Precision : ",precision_score(y_test.astype(int), y_predict))
print("Recall : ",recall_score(y_test.astype(int), y_predict))

print(classification_report(y_test.astype(int), y_predict, target_names=['Washington', 'Masachussets']))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13554272947309626, 'fraction_numerical': 0.021038912679203128, 'mean_word_length': 10.357293868921776, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '173418', 'license': 'MIT', 'n_tokens_mistral': 2162, 'n_tokens_neox': 2006, 'n_words': 237, 'path': 'Project 5/Part2_LSI.ipynb', 'repo_name': 'srlakhe/Large_Scale_Data_Mining', 'size': '5371'}