<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step1:  Modeling
Models are specifications of a mathematical (or probabilistic) relationship between variables.
What Is Machine Learning?
Machine learning, in our context, is the use of models that are learned from data.
Overfitting And Underfitting
Overfitting of a model is probable when the model performs well against the training data but applies poorly to any new data. Underfitting of a model is probable when the model performs poorly on either training or new data.
The above figure shows extreme underfitting with degree 0 and extreme overfitting with degree 9.
One way to reduce do not overfit is to split the data set into training and testing subsets
Step2:  When splitting data, it's important to keep input data and target data in the same order
Step3:  Correctness
Predictions fall into one of four categories
Step4:  Precision measures the accuracy of our positive predictions
Step5:  Recall measures the proportion of positives predicted by the model
Step6:  The precision and recall scores clearly point to the inadqequacy of our model. The F1 score combines precision and recall into a single new measure
<ASSISTANT_TASK:>
Python Code:
def split_data(data, prob):
    split data into fractions [prob, 1 - prob]
    results = [], []
    for row in data:
        results[0 if random.random() < prob else 1].append(row)
    return results
Explanation: Modeling
Models are specifications of a mathematical (or probabilistic) relationship between variables.
What Is Machine Learning?
Machine learning, in our context, is the use of models that are learned from data.
Overfitting And Underfitting
Overfitting of a model is probable when the model performs well against the training data but applies poorly to any new data. Underfitting of a model is probable when the model performs poorly on either training or new data.
The above figure shows extreme underfitting with degree 0 and extreme overfitting with degree 9.
One way to reduce do not overfit is to split the data set into training and testing subsets:
End of explanation
def train_test_split(x, y, test_pct):
    data = zip(x, y) # pair corresponding values
    train, test = split_data(data, 1 - test_pct) # split the data set of pairs
    x_train, y_train = zip(*train) # magical un-zip trick
    x_test, y_test = zip(*test)
    return x_train, x_test, y_train, y_test
Explanation: When splitting data, it's important to keep input data and target data in the same order:
End of explanation
true_positives = 70
false_positives = 4930
true_negatives = 981070
false_negatives = 13930
def accuracy(tp, fp, fn, tn):
    correct = tp + tn
    total = tp + fp + fn + tn
    return correct / total
accuracy(true_positives, false_positives, false_negatives, true_negatives) # 0.98114
Explanation: Correctness
Predictions fall into one of four categories:
| True Positive | Predicted true, and it was true |
| :----------- | :--------------- |
| False Positive (Type 1 Error) | Predicted true, but it was false |
| False Negative (Type 2 Error) | Predicted false, but it was true |
| True Negative | Predicted false, and it was false |
Suppose we predicted that a person has leukemia if they are named "Luke." We can predict with 98% accuracy--but this clearly shows that accuracy is itself solely a measure of a good model:
| | leukemia | no leukemia | total |
| --- | --- | --- | --- |
| "Luke" | 70 | 4,930 | 5,000 |
| not "Luke" | 13,930 | 981,070 | 995,000 |
| total | 14,000 | 986,000 | 1,000,000 |
End of explanation
def precision(tp, fp, fn, tn):
    return tp / (tp + fp)
precision(true_positives, false_positives, false_negatives, true_negatives) # 0.014
Explanation: Precision measures the accuracy of our positive predictions:
End of explanation
def recall(tp, fp, fn, tn):
    return tp / (tp + fn)
recall(true_positives, false_positives, false_negatives, true_negatives) # 0.005
Explanation: Recall measures the proportion of positives predicted by the model:
End of explanation
def f1_score(tp, fp, fn, tn):
    p = precision(tp, fp, fn, tn)
    r = recall(tp, fp, fn, tn)
    return 2 * p * r / (p + r)
f1_score(true_positives, false_positives, false_negatives, true_negatives) # 0.007
Explanation: The precision and recall scores clearly point to the inadqequacy of our model. The F1 score combines precision and recall into a single new measure:
End of explanation
<END_TASK>