<jupyter_start><jupyter_text>microsoftml Quickstart: Breast Cancer Prediction  SummaryThis quickstart is a simple example to show the use of the rx_fast_linear function to build a binary classifier model.  1. Load the breast cancer data We'll be using the breast cancer dataset that is built into scikit-learn. We will then use pandas and numpy to convert the data to a dataframe so that we can take a look at the data.<jupyter_code>from sklearn.datasets import load_breast_cancer
import pandas as pd
import numpy as np

bc = load_breast_cancer()

bc_df = pd.DataFrame(data = np.c_[bc['data'], bc['target']],
                     columns = bc['feature_names'].tolist() + ['target'])

bc_df.head()<jupyter_output><empty_output><jupyter_text>2. Split the data into a train and test datasetWe will now split the data into 2 datasets. A train dataset to train the model, and a test dataset to gauge how good is  the model. We'll use 80% of the data for the train dataset and 20% for the test dataset.<jupyter_code>from sklearn.model_selection import train_test_split

bc_train, bc_test = train_test_split(bc_df, test_size=0.2)

print("# of rows in training set = ",bc_train.size)
print("# of rows in test set = ",bc_test.size)<jupyter_output># of rows in training set =  14105
# of rows in test set =  3534<jupyter_text>3. Train a binary classifier modelNow that we have the dataset to train with, we'll train a model using that data. We will be using the [rx_fast_linear](https://docs.microsoft.com/en-us/r-server/python-reference/microsoftml/rx-fast-linear) function from the [microsoftml](https://docs.microsoft.com/en-us/r-server/python-reference/microsoftml/microsoftml-package) package to train the model. The first parameter to the rx_fast_linear function specifies the target label followed by the features to train the model. This is known as the *formula* and has the format of "a ~ [b]" where "a" is the column name of the target and "[b]" is the list of feature columns to train with.In this example, we create list of columns from the training dataset by taking all columns but dropping the target column (called "target" in this case).<jupyter_code>from microsoftml import rx_fast_linear

features = bc_df.columns.drop(["target"])
model = rx_fast_linear("target ~ " + "+".join(features), data=bc_train)<jupyter_output>Express Edition will continue to be enforced.
Automatically adding a MinMax normalization transform, use 'norm=Warn' or 'norm=No' to turn this behavior off.
Beginning processing data.
Rows Read: 455, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 455, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 455, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Using 2 threads to train.
Automatically choosing a check frequency of 2.
Auto-tuning parameters: maxIterations = 3294.
Auto-tuning parameters: L2 = 2.670477E-05.
Auto-tuning parameters: L1Threshold (L1/L2) = 0.
Using best model from iteration 368.
Not training a calibrator because it is not needed.
Elapsed time: 00:00:06.1734881
Elapsed time: 00:00:00.4967690<jupyter_text>4. Predict using the trained modelAt this point we have a model that we have trained on the training data, using the rx_fast_linear binary classification algorithm. Let's now use that model to predict using the [rx_predict](https://docs.microsoft.com/en-us/r-server/python-reference/microsoftml/rx-predict), based on the test dataset. We will also take a look at the return result of rx_predict function. The *PredictedLabel* column indicates whether the data represents a cancerous sample or not. The *Probability* column indicates the confidence of the prediction for that particular row of data.<jupyter_code>from microsoftml import rx_predict

prediction = rx_predict(model, data=bc_test)

prediction.head()<jupyter_output>Beginning processing data.
Rows Read: 114, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.6729840
Finished writing 114 rows.
Writing completed.<jupyter_text>5. Evaluating the modelLet's now gauge the quality of the model we have. A standard metric to use is the AUC (Area Under the Curve) metric. Assuming no overfiiting of the model has taken place, the closer the value of the AUC is to 1, the better the quality of the model.<jupyter_code>from sklearn.metrics import roc_curve, auc
fpr, tpr, thresholds = roc_curve(bc_test["target"], prediction["PredictedLabel"])

roc_auc = auc(fpr, tpr)
print(roc_auc)<jupyter_output>0.960526315789<jupyter_text>We can also look at the ROC (Receiver Operating Characteristics) curve to visually see the performance of the model.<jupyter_code>import matplotlib.pyplot as plt

plt.figure()
lw = 2
plt.plot(fpr, tpr, color='darkorange',
         lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC of Breast Cancer Prediction')
plt.legend(loc="lower right")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08645086257026556, 'fraction_numerical': 0.028106222136072882, 'mean_word_length': 5.150178784266984, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 3, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '638992', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1525, 'n_words': 638, 'path': 'microsoftml/quickstarts/binary-classification/Binary+Classification+Quickstart.ipynb', 'repo_name': 'mounirHai/ML-Server-Python-Samples', 'size': '5159'}