<jupyter_start><jupyter_text>**Random Forest Classifier With 83% Test Accuracy**<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state=123)
 
rfc = RandomForestClassifier(n_estimators=16,
                            random_state=1111,
                            max_features=8)

rfc.fit(X_train, y_train)

print('The training error is {0:.3f}'.format(mean_absolute_error(y_train, rfc.predict(X_train))))
print('The testing error is {0:.3f}'.format(mean_absolute_error(y_test, rfc.predict(X_test))))
predictions = rfc.predict(X_train)
accuracy = accuracy_score(y_train, predictions)
print(np.round(accuracy*100, 2), '%')
predictions = rfc.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(np.round(accuracy*100, 2), '%')
print(confusion_matrix(y_test, predictions))
print("="*60)
print(classification_report(y_test, predictions))
probs = rfc.predict_proba(X_test)  
probs = probs[:, 1]  
fper, tper, thresholds = roc_curve(y_test, probs) 
plt.plot(fper, tper)
plt.plot([0,1], [0,1], 'k--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Random Forest Classifier ROC curve')
plt.show()<jupyter_output><empty_output><jupyter_text>**XG Boost Classifier With 87% Test Accuracy**<jupyter_code>xgb_clf = xgb.XGBClassifier(learning_rate=0.3,n_estimators=180, max_depth=3)
xgb_clf.fit(X_train, y_train)
predictions = xgb_clf.predict(X_train)
# accuracy score
accuracy = accuracy_score(y_train, predictions)
print(np.round(accuracy*100, 2), '%')
predictions = xgb_clf.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(np.round(accuracy*100, 2), '%')
print(confusion_matrix(y_test, predictions))
print("="*60)
print(classification_report(y_test, predictions))
probs = xgb_clf.predict_proba(X_test)  
probs = probs[:, 1]  
fper, tper, thresholds = roc_curve(y_test, probs) 
plt.plot(fper, tper)
plt.plot([0,1], [0,1], 'k--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title(' RFC ROC curve')
plt.show()
from sklearn.metrics import roc_auc_score
r_a_score = roc_auc_score(y_test, probs)
print("ROC-AUC-Score:", r_a_score)<jupyter_output>ROC-AUC-Score: 0.8827509421034601<jupyter_text>**Gradient Boosting Classifier With 82% Test Accuracy**<jupyter_code>clf = GradientBoostingClassifier(n_estimators=25, learning_rate=0.7, max_depth=1, random_state=0)
clf.fit(X_train, y_train)
predictions = clf.predict(X_train)
accuracy = accuracy_score(y_train, predictions)
print(np.round(accuracy*100, 2), '%')
predictions = clf.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(np.round(accuracy*100, 2), '%')
print(confusion_matrix(y_test, predictions))
print("="*60)
print(classification_report(y_test, predictions))
probs = clf.predict_proba(X_test)  
probs = probs[:, 1]  
fper, tper, thresholds = roc_curve(y_test, probs) 
plt.plot(fper, tper)
plt.plot([0,1], [0,1], 'k--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Gradient Boosting ROC curve')
plt.show()<jupyter_output><empty_output><jupyter_text>**Logistic Regression With 81% Test Accuracy**<jupyter_code>logreg = LogisticRegression(random_state=1,max_iter=10000)
logreg.fit(X_train, y_train)
predictions = logreg.predict(X_train)
accuracy = accuracy_score(y_train, predictions)
print(np.round(accuracy*100, 2), '%')
predictions = logreg.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(np.round(accuracy*100, 2), '%')
print(confusion_matrix(y_test, predictions))
print("="*60)
print(classification_report(y_test, predictions))
probs = logreg.predict_proba(X_test)  
probs = probs[:, 1]  
fper, tper, thresholds = roc_curve(y_test, probs) 
plt.plot(fper, tper)
plt.plot([0,1], [0,1], 'k--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Decision Tree ROC curve')
plt.show()
dt = DecisionTreeClassifier(max_depth=4, random_state=1,max_features=8) 
dt.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>**Decision Tree With 83% Test Accuracy**<jupyter_code>predictions = dt.predict(X_train)
accuracy = accuracy_score(y_train, predictions)
print(np.round(accuracy*100, 2), '%')
predictions = dt.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(np.round(accuracy*100, 2), '%')
print(confusion_matrix(y_test, predictions))
print("="*60)
print(classification_report(y_test, predictions))
probs = dt.predict_proba(X_test)  
probs = probs[:, 1]  
fper, tper, thresholds = roc_curve(y_test, probs) 
plt.plot(fper, tper)
plt.plot([0,1], [0,1], 'k--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Decision Tree ROC curve')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15338857021457403, 'fraction_numerical': 0.029742936052687487, 'mean_word_length': 7.7835820895522385, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '242635', 'license': 'MIT', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1791, 'n_words': 310, 'path': 'Assignment_ML_L2.ipynb', 'repo_name': 'Sanyam8055/100-Days-of-ML', 'size': '4707'}