<jupyter_start><jupyter_text>Import Csv File from local Repo<jupyter_code>data = pd.read_csv('.\\Downloads\\data.csv')
data.head()
data.groupby("diagnosis").count()
data.isna().sum()<jupyter_output><empty_output><jupyter_text>Drop some unwanted column and id Column<jupyter_code>data = data.drop(["Unnamed: 32","id"],axis='columns')
data.head()
data.describe()<jupyter_output><empty_output><jupyter_text>Visualize correlation between features<jupyter_code>#Create a pair plot
sns.pairplot(data.iloc[: ,0:6], hue = 'diagnosis')
data.corr()
X= data.drop(["diagnosis"],axis="columns")
Y = data.diagnosis
Y.replace({'M':1,'B':0},inplace=True)
Y.head(20)<jupyter_output><empty_output><jupyter_text>Splitting Test And Train Split<jupyter_code>#split data into train and test
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,Y,test_size=0.20,stratify=Y)
y_train.value_counts()
y_test.value_counts()<jupyter_output><empty_output><jupyter_text>Apply logistic Regression on Dataset<jupyter_code>#build logistic regression model
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(max_iter=100)
lr.fit(X_train,y_train)
lr.score(X_test,y_test)
y_pred = lr.predict(X_test)
from sklearn.metrics import confusion_matrix , classification_report
print(classification_report(y_test,y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.97      0.96      0.97        72
           1       0.93      0.95      0.94        42

    accuracy                           0.96       114
   macro avg       0.95      0.96      0.95       114
weighted avg       0.96      0.96      0.96       114<jupyter_text>Data range varies too much so scaling Dataset and seeing if this makes any difference in accuracy<jupyter_code>#apply scaling also
from sklearn.preprocessing import  StandardScaler
scaler =  StandardScaler()
X_train_scaled =scaler.fit_transform(X_train)
X_test_scaled =scaler.transform(X_test)
#again train logistic regression for scaled data and see the diff
lrsclaed = LogisticRegression(max_iter=100)
lrsclaed.fit(X_train_scaled,y_train)
y_predscaled = lrsclaed.predict(X_test_scaled)
lrsclaed.score(X_test_scaled,y_test)
from sklearn.metrics import confusion_matrix , classification_report
print(classification_report(y_test,y_predscaled))<jupyter_output>precision    recall  f1-score   support

           0       1.00      0.99      0.99        72
           1       0.98      1.00      0.99        42

    accuracy                           0.99       114
   macro avg       0.99      0.99      0.99       114
weighted avg       0.99      0.99      0.99       114<jupyter_text>Applying Random Forest Classifier For the same Dataset<jupyter_code>from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(n_estimators=40)
rf.fit(X_train_scaled, y_train)
y_predscaledrf =rf.predict(X_test_scaled)
rf.score(X_test_scaled, y_test)
print(classification_report(y_test,y_predscaledrf))<jupyter_output>precision    recall  f1-score   support

           0       0.96      0.99      0.97        72
           1       0.97      0.93      0.95        42

    accuracy                           0.96       114
   macro avg       0.97      0.96      0.96       114
weighted avg       0.97      0.96      0.96       114
{'fraction_non_alphanumeric': 0.0893233082706767, 'fraction_numerical': 0.05533834586466165, 'mean_word_length': 3.121437422552664, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '382277', 'license': 'MIT', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1143, 'n_words': 231, 'path': 'Breast_Cancer_Prediction.ipynb', 'repo_name': 'lalitaa/DSProjects', 'size': '3325'}