<jupyter_start><jupyter_text>***As the last column(Unnamed: 32) is filled with NaN values, we will drop it.***<jupyter_code>data = data.drop(["Unnamed: 32"], axis=1)
data
data_id = data["id"]
data_id = pd.DataFrame(data_id, columns = ["id"])  #Saving IDs in a separate Dataframe
data.drop(["id"],axis=1, inplace=True)   #Dropping id from data
data["diagnosis"].value_counts()
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="radius_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="perimeter_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="area_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="smoothness_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="concavity_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="symmetry_mean", data=data, ax=axes)
_, axes = plt.subplots(figsize=(6, 4))
sns.boxplot(x="diagnosis", y="fractal_dimension_mean", data=data, ax=axes)
d = {"B":0, "M":1}
data["diagnosis"] = data["diagnosis"].map(d)
data
corr_matrix = data.corr()
plt.figure(figsize=(30,20))
sns.heatmap(corr_matrix, annot=True);<jupyter_output><empty_output><jupyter_text>Dropping correlated columns: **perimeter_mean, radius_mean, perimeter_worst, radius_worst, perimeter_se, radius_se**<jupyter_code>correlated_columns = list({
        "perimeter_mean",
        "radius_mean",
        "perimeter_worst",
        "radius_worst",
        "perimeter_se",
        "radius_se"})
data = data.drop(columns=correlated_columns, axis=1)
data
X = data.drop(["diagnosis"], axis=1)
y = data["diagnosis"]<jupyter_output><empty_output><jupyter_text>*Splitting the data into training and test sets*<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.18,random_state=32)
print("Length of training set = ", len(X_train))
print("Length of test set = ", len(X_test))<jupyter_output>Length of training set =  466
Length of test set =  103<jupyter_text>*Standard Scaling*<jupyter_code>from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)<jupyter_output><empty_output><jupyter_text>**KNN Classifier**<jupyter_code>from sklearn import metrics
from sklearn.model_selection import cross_val_score
from sklearn.neighbors import KNeighborsClassifier
model_knn = KNeighborsClassifier(n_neighbors=5)
model_knn.fit(X_train, y_train)
y_pred_knn = model_knn.predict(X_test)
accuracy_knn = metrics.accuracy_score(y_pred_knn, y_test)
scores = cross_val_score(model_knn, X_train, y_train, cv=5)
cv_score_knn = scores.mean()
print("Cross-val-score: ", cv_score_knn)
print("Accuracy score: ", accuracy_knn)<jupyter_output>Cross-val-score:  0.9484328528940746
Accuracy score:  0.970873786407767<jupyter_text>**Decision Tree Classifier**<jupyter_code>from sklearn.tree import DecisionTreeClassifier
model_dt = DecisionTreeClassifier(max_depth = 5, min_samples_split=3)
model_dt.fit(X_train, y_train)
y_pred_dt = model_dt.predict(X_test)
accuracy_dt = metrics.accuracy_score(y_pred_dt, y_test)
scores = cross_val_score(model_dt, X_train, y_train, cv=5)
cv_score_dt = scores.mean()
print("Cross-val-score: ", cv_score_dt)
print("Accuracy score: ", accuracy_dt)<jupyter_output>Cross-val-score:  0.9270189887897506
Accuracy score:  0.8932038834951457<jupyter_text>**Random Forest Classifier**<jupyter_code>from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
model_rf = RandomForestClassifier(max_depth = 7, min_samples_split=5)
model_rf.fit(X_train, y_train)
y_pred_rf = model_rf.predict(X_test)
accuracy_rf = metrics.accuracy_score(y_pred_rf, y_test)
scores = cross_val_score(model_rf, X_train, y_train, cv=5)
cv_score_rf = scores.mean()
print("Cross-val-score: ", cv_score_rf)
print("Accuracy score: ", accuracy_rf)<jupyter_output>Cross-val-score:  0.9592084191260583
Accuracy score:  0.9514563106796117<jupyter_text>**Stochastic Gradient Descent Classifier**<jupyter_code>from sklearn.linear_model import SGDClassifier, LogisticRegression
model_gd = SGDClassifier()
model_gd.fit(X_train, y_train)
y_pred_gd = model_dt.predict(X_test)
accuracy_gd = metrics.accuracy_score(y_pred_gd, y_test)
scores = cross_val_score(model_gd, X_train, y_train, cv=5)
cv_score_gd = scores.mean()
print("Cross-val-score: ", cv_score_gd)
print("Accuracy score: ", accuracy_gd)<jupyter_output>Cross-val-score:  0.9570807595515902
Accuracy score:  0.8932038834951457<jupyter_text>**Logistic Regression**<jupyter_code>model_logR = LogisticRegression()
model_logR.fit(X_train, y_train)
y_pred_logR = model_logR.predict(X_test)
accuracy_logR = metrics.accuracy_score(y_pred_logR, y_test)
scores = cross_val_score(model_logR, X_train, y_train, cv=5)
cv_score_logR = scores.mean()
print("Cross-val-score: ", cv_score_logR)
print("Accuracy score: ", accuracy_logR)<jupyter_output>Cross-val-score:  0.9656600320292839
Accuracy score:  0.9805825242718447<jupyter_text>**AdaBoost Classifier**<jupyter_code>model_ada = AdaBoostClassifier()
model_ada.fit(X_train, y_train)
y_pred_ada = model_ada.predict(X_test)
accuracy_ada = metrics.accuracy_score(y_pred_ada, y_test)
scores = cross_val_score(model_ada, X_train, y_train, cv=5)
cv_score_ada = scores.mean()
print("Cross-val-score: ", cv_score_ada)
print("Accuracy score: ", accuracy_ada)
print("Final accuracy of model = ", accuracy_logR * 100)<jupyter_output>Final accuracy of model =  98.05825242718447
{'fraction_non_alphanumeric': 0.132942847000355, 'fraction_numerical': 0.042243521476748314, 'mean_word_length': 8.454697986577182, 'pattern_counts': {'":': 2, '<': 34, '<?xml version=': 0, '>': 34, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '300906', 'license': 'MIT', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2177, 'n_words': 357, 'path': 'Classification Breast Cancer Prediciton/breast-cancer-prediction.ipynb', 'repo_name': 'somyagr/ML-Gallery', 'size': '5634'}