<jupyter_start><jupyter_text>Week 6 Quiz <NAME> - paj2117<jupyter_code>import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score

# to supress warnings about a change in the LogisticRegression solver
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
# Load the sample breast_cancer dataset from Scikit-Learn
#   returning just the X features matrix and y label vector.
#   The target here is a binary classification task.
#   For more information, see https://scikit-learn.org/stable/datasets/index.html#breast-cancer-dataset
X,y = load_breast_cancer(return_X_y=True)
# Split X and y into X_train,X_test,y_train,y_test 
#   using train_test_split, stratify using y.
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=.1,stratify=y,random_state=123)
# Get a baseline, mean 5-fold cross-validation accuracy score 
#   for a DummyClassifier with default parameter settings 
#   using X_train,y_train.
scores = cross_val_score(DummyClassifier(),X_train,y_train,cv=5)
print(f'mean cv accuracy: {np.mean(scores):0.2f}')
# Get a mean, 5-fold cross-validation accuracy score 
#   for a LogisticRegression model with default parameter settings
#   using X_train,y_train.
scores = cross_val_score(LogisticRegression(),X_train,y_train,cv=5)
print(f'mean cv accuracy: {np.mean(scores):0.2f}')
# Retrain a LogisticRegression model with default parameters on the full training set.
lr = LogisticRegression().fit(X_train,y_train)
# Evaluate generalization accuracy of the trained LogisticRegression model on the test set.
acc = lr.score(X_test, y_test)
print(f'test-set accuracy: {acc:0.2f}')<jupyter_output>test-set accuracy: 0.96
{'fraction_non_alphanumeric': 0.08471849865951743, 'fraction_numerical': 0.011796246648793566, 'mean_word_length': 6.464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '246576', 'license': 'CC0-1.0', 'n_tokens_mistral': 629, 'n_tokens_neox': 605, 'n_words': 167, 'path': 'weekly_quiz/Week_6_Quiz_paj2117.ipynb', 'repo_name': 'perrindesign/data-science-class', 'size': '1870'}