Lecture 14: September 8th, 2023#
Today:
Give a few more examples with logistic regression
Loss function for classification problems
Reminders and Updates:
We will have lecture on Monday (our last lecture :( ) I plan to cover K-Means clustering
New token-earning opportunity on Canvas
I will release new chances for ML outcomes from last week
Remaining ML outcomes will be posted by tonight (P20 is already live)
Homework 7 and Homework 8 are due Monday!
Final Project:
You do not have to include all of our ML models in your final project! You are welcome to, but it is not a requirement. In lecture we’ve seen the following models:
Linear regression
Logistic regression
K-Means clustering (Monday)
Including at least one of these models is expected for the final project, but you do not need to do all of them. If you are able to spend a good amount of time with just one of the above models, then I think that’s good. If you end up finishing a question too fast, it might be nice to try another model.
Recap of Lecture 13#
Recall that on Wednesday, we used Logistic Regression with flipper length and bill length columns to predict whether or not a penguin belonged to the Chinstrap species. As a reminder, this is binary classification, because we only have two possible outputs.
import altair as alt
import pandas as pd
import seaborn as sns
import numpy as np
df = sns.load_dataset("penguins").dropna(axis=0)
df["isChinstrap"] = (df["species"] == "Chinstrap")
cols = ["flipper_length_mm", "bill_length_mm"]
c1 = alt.Chart(df).mark_point(filled=True,size=100).encode(
x = alt.X("flipper_length_mm").scale(zero=False),
y = alt.Y("bill_length_mm").scale(zero=False),
color="species",
shape="species",
tooltip = ["species","pred","index"]
).properties(title='actual species')
c1
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(df[cols], df["isChinstrap"])
LogisticRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LogisticRegression()
df["pred"] = clf.predict(df[cols])
In today’s lecture, I want to talk a little bit more about this same example.
df.loc[[18, 19, 20], cols + ["isChinstrap", "pred"]]
| flipper_length_mm | bill_length_mm | isChinstrap | pred | |
|---|---|---|---|---|
| 18 | 184.0 | 34.4 | False | False |
| 19 | 194.0 | 46.0 | False | True |
| 20 | 174.0 | 37.8 | False | False |
The Chinstrap penguins all appear in the same portion of the dataset, so we shouldn’t be concerned that none of the penguins in rows labeled 18,19, and 20 are Chinstrap. Looking at the prediction column, what goes wrong?
Notice: The model has the wrong prediction for row label 19.
One question we can ask is how confident was our model that row label 19 penguin was really a Chinstrap?
To get the classes that our model predicts, we can use the classes_ attribute of clf. The important thing here is the order in which the classes are returned. When we ask for probabilities, they will be returned in this same order.
clf.classes_
array([False, True])
The first entry is False, means this is not a Chinstrap. The second entry is True, means this is a Chinstrap.
Now let’s predict the probabilities for these three rows.
The probabilities below are a little difficult to read. Here’s how we can make things look a little better.
clf.predict_proba(df.loc[[18,19,20],cols])
array([[9.99771697e-01, 2.28303114e-04],
[3.29559670e-01, 6.70440330e-01],
[7.71818762e-01, 2.28181238e-01]])
#Returns just decimals, instead of scientific notation
np.set_printoptions(suppress=True)
clf.predict_proba(df.loc[[18,19,20],cols])
array([[0.9997717 , 0.0002283 ],
[0.32955967, 0.67044033],
[0.77181876, 0.22818124]])
clf.classes_
array([False, True])
These are our classes. Notice, we could have replaced the boolean values with strings in our model, and it would have worked the same. We’ll see this with multiclass logistic regression later in the lecture. False: “The penguin is not Chinstrap” True: “The penguin is Chinstrap”
df["isChinstrap"]
0 False
1 False
2 False
4 False
5 False
...
338 False
340 False
341 False
342 False
343 False
Name: isChinstrap, Length: 333, dtype: bool
Let’s try to interpret these probs. for each row.
For label 18 row, the model is 99.97% sure that the penguin is not a Chinstrap penguin. This is good, because the if we look at the true data, the corresponding penguin is not Chinstrap.
For label 19 row, the model is 33% sure that the penguin is not Chinstrap (and thus 67% sure that it is a Chinstrap). Notice how confident the model was for row 18 versus row 19, this is good because the model was correct for row 18, but incorrect for row 19.
df.loc[[18, 19, 20], cols + ["isChinstrap", "pred"]]
| flipper_length_mm | bill_length_mm | isChinstrap | pred | |
|---|---|---|---|---|
| 18 | 184.0 | 34.4 | False | False |
| 19 | 194.0 | 46.0 | False | True |
| 20 | 174.0 | 37.8 | False | False |
Great question from the chat: at what point should we be concerned about the model being confidently incorrect? Answer: There is no good answer. It’s really going to depend on your specific problem/data (for example, does your data have some weird outliers)?
Interpretation Question: As flipper length increases, is the penguin more or less likely to be a Chinstrap, according to our model? What about bill length?

Recall:
We are dealing with a sigmoid function: \(\sigma(x) = \frac{1}{1 + e^{-x}}\)
Range is (0,1), so this makes it a good candidate for modeling probability.
As \(x\) increases, \(\sigma(x)\) increases as well (i.e. the sigmoid function is increasing); therefore, the larger the input, the closer the probability to 1, which means the outcome is more likely to happen. (Similarly, smaller input means less likely to happen.)
Recall, for logistic regression, we determine \(x\) using the following linear equation: $\( L(x) = \text{bill coefficient}*\text{bill length} + \text{flipper coefficient}*\text{flipper length} + \text{intercept} \)$
Putting everything together, because \(L(x)\) is what we pass to the sigmoid function, if \(L(x)\) is larger, that means there’s a larger probability, and if \(L(x)\) is smaller, that means there’s a smaller probability.
So, to answer the question above, we should look at the coefficients of our model.
cols
['flipper_length_mm', 'bill_length_mm']
clf.coef_
array([[-0.34802208, 1.08405225]])
The coefficient for flipper length is negative, while the coefficient for bill length is positive. This means that if flipper length increases, then \(L(x)\) decreases, so the probability is smaller => the penguin is less likely to be Chinstrap.
The coefficient for bill length, on the other hand, is positive! This means that if bill length increases, then so does \(L(x)\), so the probability is larger => the penguin is more likely to be Chinstrap.
Multiclass Logistic Regression#
Many of you have already started the homeworks for this week, which deal with multiclass logistic regression (this is where we predict more than 2 classes). Let’s see an example of it in action together as a class.
Drop the “pred” column from
df(we will make a new one below) using thedropmethod and a suitableaxiskeyword argument.
df.head()
| species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isChinstrap | pred | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | False | False |
| 1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | False | False |
| 2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | False | False |
| 4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | False | False |
| 5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | False | False |
#errors here means if I run this cell again it will ignore an errors
df = df.drop("pred", axis=1, errors="ignore")
df.head()
| species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isChinstrap | |
|---|---|---|---|---|---|---|---|---|
| 0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | False |
| 1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | False |
| 2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | False |
| 4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | False |
| 5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | False |
Fit a new logistic regression classifier, using the same input features, but this time using the “species” column as our target. (This is our first time seeing logistic regression with more than two classes. When we perform classification with two classes, it is called “Binary Classification”, and is often easier to explain.)
df.species.unique()
array(['Adelie', 'Chinstrap', 'Gentoo'], dtype=object)
Notice there are 3 species of penguins, so there will be 3 classes in our model. Even though there are now more than 2 classes, the procedure will be the exact same as what we did for binary classification.
clf = LogisticRegression()
cols
['flipper_length_mm', 'bill_length_mm']
clf.fit(df[cols],df["species"])
LogisticRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LogisticRegression()
One nice thing is that the model automatically reports the outputs using the values in the “species” column. In particular, these will be strings, and is a nice example of how our output doesn’t need to be boolean/numeric.
Check the
coef_attribute. How does it relate to thecoef_attribute we found above, where we were only considering Chinstrap penguins?
clf.classes_
array(['Adelie', 'Chinstrap', 'Gentoo'], dtype=object)
The order of the classes is extremely important. I believe scikit-learn will always output them in alphabetical order. Looking at the coefficients below, the first row corresponds to the coefficients for the Adelie species, the second row to the Chinstrap species, and the third row to the Gentoo species.
clf.coef_
array([[-0.10544131, -0.59253116],
[-0.2674632 , 0.71305121],
[ 0.37290451, -0.12052006]])
Now, we have 3 rows, where each row represents the coefficients corresponding to the penguin species.
Add a column “pred” to
dfcontaining the predicted values.
df["pred"] = clf.predict(df[cols])
df
| species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isChinstrap | pred | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | False | Adelie |
| 1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | False | Adelie |
| 2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | False | Adelie |
| 4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | False | Adelie |
| 5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | False | Adelie |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 338 | Gentoo | Biscoe | 47.2 | 13.7 | 214.0 | 4925.0 | Female | False | Gentoo |
| 340 | Gentoo | Biscoe | 46.8 | 14.3 | 215.0 | 4850.0 | Female | False | Gentoo |
| 341 | Gentoo | Biscoe | 50.4 | 15.7 | 222.0 | 5750.0 | Male | False | Gentoo |
| 342 | Gentoo | Biscoe | 45.2 | 14.8 | 212.0 | 5200.0 | Female | False | Gentoo |
| 343 | Gentoo | Biscoe | 49.9 | 16.1 | 213.0 | 5400.0 | Male | False | Gentoo |
333 rows × 9 columns
Remember the model had made a mistake in row 19 when we were just doing binary classification. Let’s see how it did for this multiclass classification.
df.loc[[19],:]
| species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isChinstrap | pred | |
|---|---|---|---|---|---|---|---|---|---|
| 19 | Adelie | Torgersen | 46.0 | 21.5 | 194.0 | 4200.0 | Male | False | Chinstrap |
Let’s look at the probabilities for this row.
clf.classes_
array(['Adelie', 'Chinstrap', 'Gentoo'], dtype=object)
clf.predict_proba(df.loc[[19],cols])
array([[0.08336009, 0.91516209, 0.00147781]])
Here, our model is 91% sure that the penguin is Chinstrap. This is worse!! than in our binary classification, where it was 67% sure that it was Chinstrap.
clf.predict_proba(df.loc[[18,19,20],cols])
array([[0.99998469, 0.00001469, 0.00000062],
[0.08336009, 0.91516209, 0.00147781],
[0.99375309, 0.00624688, 0.00000003]])
Our model is very confident that rows 18 and 20 are Adelie penguins (this is good, because in this case that is correct). It is less confident that row 19 is a Chinstrap (which is good, beause it got this one wrong).
Make an Altair scatter plot showing the predicted values.
cols
['flipper_length_mm', 'bill_length_mm']
df["index"] = df.species.index
Int64Index([ 0, 1, 2, 4, 5, 6, 7, 12, 13, 14,
...
332, 333, 334, 335, 337, 338, 340, 341, 342, 343],
dtype='int64', length=333)
c2 = alt.Chart(df).mark_point(filled=True,size=100).encode(
x=alt.X(cols[0]).scale(zero=False),
y=alt.Y(cols[1]).scale(zero=False),
color="pred",
shape="pred",
tooltip=["species","pred","index"]
).properties(title="predicted species")
c2
#Trying to find the row 19 penguin!
c3 = alt.Chart(df[df["species"]=="Adelie"]).mark_point(filled=True,size=100).encode(
x=alt.X(cols[0]).scale(zero=False),
y=alt.Y(cols[1]).scale(zero=False),
color="pred",
shape="pred",
tooltip=["species","pred","index"]
).properties(title="predicted species")
c3
Let’s now view this chart next to the actual species.
c1 | c2
It looks like our model did a pretty good job of predicting the species! The main difference is the predictions look a little more regular than the actual data, but this is to be expected.
It’s a little difficult to see (because of the space between the points), but the decision boundaries are line segments, where on one side of each line segment we make one prediction, and on the other side we make a different prediction.
Generating fake data to better see the decision boundaries#
Using
np.linspace, make a NumPy array of 70 equally spaced x-coordinates and 70 equally spaced y-coordinates. Name these NumPy arraysxandy.
x = np.linspace(170,235,70)
y = np.linspace(30,60,70)
Notice, we selected these ranges to roughly follow the ranges in the real data (flipper length and bill length).
x
array([170. , 170.94202899, 171.88405797, 172.82608696,
173.76811594, 174.71014493, 175.65217391, 176.5942029 ,
177.53623188, 178.47826087, 179.42028986, 180.36231884,
181.30434783, 182.24637681, 183.1884058 , 184.13043478,
185.07246377, 186.01449275, 186.95652174, 187.89855072,
188.84057971, 189.7826087 , 190.72463768, 191.66666667,
192.60869565, 193.55072464, 194.49275362, 195.43478261,
196.37681159, 197.31884058, 198.26086957, 199.20289855,
200.14492754, 201.08695652, 202.02898551, 202.97101449,
203.91304348, 204.85507246, 205.79710145, 206.73913043,
207.68115942, 208.62318841, 209.56521739, 210.50724638,
211.44927536, 212.39130435, 213.33333333, 214.27536232,
215.2173913 , 216.15942029, 217.10144928, 218.04347826,
218.98550725, 219.92753623, 220.86956522, 221.8115942 ,
222.75362319, 223.69565217, 224.63768116, 225.57971014,
226.52173913, 227.46376812, 228.4057971 , 229.34782609,
230.28985507, 231.23188406, 232.17391304, 233.11594203,
234.05797101, 235. ])
y
array([30. , 30.43478261, 30.86956522, 31.30434783, 31.73913043,
32.17391304, 32.60869565, 33.04347826, 33.47826087, 33.91304348,
34.34782609, 34.7826087 , 35.2173913 , 35.65217391, 36.08695652,
36.52173913, 36.95652174, 37.39130435, 37.82608696, 38.26086957,
38.69565217, 39.13043478, 39.56521739, 40. , 40.43478261,
40.86956522, 41.30434783, 41.73913043, 42.17391304, 42.60869565,
43.04347826, 43.47826087, 43.91304348, 44.34782609, 44.7826087 ,
45.2173913 , 45.65217391, 46.08695652, 46.52173913, 46.95652174,
47.39130435, 47.82608696, 48.26086957, 48.69565217, 49.13043478,
49.56521739, 50. , 50.43478261, 50.86956522, 51.30434783,
51.73913043, 52.17391304, 52.60869565, 53.04347826, 53.47826087,
53.91304348, 54.34782609, 54.7826087 , 55.2173913 , 55.65217391,
56.08695652, 56.52173913, 56.95652174, 57.39130435, 57.82608696,
58.26086957, 58.69565217, 59.13043478, 59.56521739, 60. ])
I want to take the cartesian product of x and y to get a grid of artificial data that I can plot/fit. There are a few ways to get this, we could use itertools.product or the NumPy function meshgrid.
from itertools import product
product(x,y)
<itertools.product at 0x7f6193ae3380>
It’s difficult to see what this is at first glance, but what if we convert it to a list?
list(product(x,y))
[(170.0, 30.0),
(170.0, 30.434782608695652),
(170.0, 30.869565217391305),
(170.0, 31.304347826086957),
(170.0, 31.73913043478261),
(170.0, 32.17391304347826),
(170.0, 32.608695652173914),
(170.0, 33.04347826086956),
(170.0, 33.47826086956522),
(170.0, 33.91304347826087),
(170.0, 34.34782608695652),
(170.0, 34.78260869565217),
(170.0, 35.21739130434783),
(170.0, 35.65217391304348),
(170.0, 36.08695652173913),
(170.0, 36.52173913043478),
(170.0, 36.95652173913044),
(170.0, 37.391304347826086),
(170.0, 37.82608695652174),
(170.0, 38.26086956521739),
(170.0, 38.69565217391305),
(170.0, 39.130434782608695),
(170.0, 39.565217391304344),
(170.0, 40.0),
(170.0, 40.434782608695656),
(170.0, 40.869565217391305),
(170.0, 41.30434782608695),
(170.0, 41.73913043478261),
(170.0, 42.17391304347826),
(170.0, 42.608695652173914),
(170.0, 43.04347826086956),
(170.0, 43.47826086956522),
(170.0, 43.91304347826087),
(170.0, 44.34782608695652),
(170.0, 44.78260869565217),
(170.0, 45.21739130434783),
(170.0, 45.65217391304348),
(170.0, 46.086956521739125),
(170.0, 46.52173913043478),
(170.0, 46.95652173913044),
(170.0, 47.391304347826086),
(170.0, 47.826086956521735),
(170.0, 48.26086956521739),
(170.0, 48.69565217391305),
(170.0, 49.130434782608695),
(170.0, 49.565217391304344),
(170.0, 50.0),
(170.0, 50.434782608695656),
(170.0, 50.869565217391305),
(170.0, 51.30434782608695),
(170.0, 51.73913043478261),
(170.0, 52.173913043478265),
(170.0, 52.608695652173914),
(170.0, 53.04347826086956),
(170.0, 53.47826086956522),
(170.0, 53.91304347826087),
(170.0, 54.347826086956516),
(170.0, 54.78260869565217),
(170.0, 55.21739130434783),
(170.0, 55.65217391304348),
(170.0, 56.086956521739125),
(170.0, 56.52173913043478),
(170.0, 56.95652173913044),
(170.0, 57.391304347826086),
(170.0, 57.826086956521735),
(170.0, 58.26086956521739),
(170.0, 58.69565217391305),
(170.0, 59.130434782608695),
(170.0, 59.565217391304344),
(170.0, 60.0),
(170.94202898550725, 30.0),
(170.94202898550725, 30.434782608695652),
(170.94202898550725, 30.869565217391305),
(170.94202898550725, 31.304347826086957),
(170.94202898550725, 31.73913043478261),
(170.94202898550725, 32.17391304347826),
(170.94202898550725, 32.608695652173914),
(170.94202898550725, 33.04347826086956),
(170.94202898550725, 33.47826086956522),
(170.94202898550725, 33.91304347826087),
(170.94202898550725, 34.34782608695652),
(170.94202898550725, 34.78260869565217),
(170.94202898550725, 35.21739130434783),
(170.94202898550725, 35.65217391304348),
(170.94202898550725, 36.08695652173913),
(170.94202898550725, 36.52173913043478),
(170.94202898550725, 36.95652173913044),
(170.94202898550725, 37.391304347826086),
(170.94202898550725, 37.82608695652174),
(170.94202898550725, 38.26086956521739),
(170.94202898550725, 38.69565217391305),
(170.94202898550725, 39.130434782608695),
(170.94202898550725, 39.565217391304344),
(170.94202898550725, 40.0),
(170.94202898550725, 40.434782608695656),
(170.94202898550725, 40.869565217391305),
(170.94202898550725, 41.30434782608695),
(170.94202898550725, 41.73913043478261),
(170.94202898550725, 42.17391304347826),
(170.94202898550725, 42.608695652173914),
(170.94202898550725, 43.04347826086956),
(170.94202898550725, 43.47826086956522),
(170.94202898550725, 43.91304347826087),
(170.94202898550725, 44.34782608695652),
(170.94202898550725, 44.78260869565217),
(170.94202898550725, 45.21739130434783),
(170.94202898550725, 45.65217391304348),
(170.94202898550725, 46.086956521739125),
(170.94202898550725, 46.52173913043478),
(170.94202898550725, 46.95652173913044),
(170.94202898550725, 47.391304347826086),
(170.94202898550725, 47.826086956521735),
(170.94202898550725, 48.26086956521739),
(170.94202898550725, 48.69565217391305),
(170.94202898550725, 49.130434782608695),
(170.94202898550725, 49.565217391304344),
(170.94202898550725, 50.0),
(170.94202898550725, 50.434782608695656),
(170.94202898550725, 50.869565217391305),
(170.94202898550725, 51.30434782608695),
(170.94202898550725, 51.73913043478261),
(170.94202898550725, 52.173913043478265),
(170.94202898550725, 52.608695652173914),
(170.94202898550725, 53.04347826086956),
(170.94202898550725, 53.47826086956522),
(170.94202898550725, 53.91304347826087),
(170.94202898550725, 54.347826086956516),
(170.94202898550725, 54.78260869565217),
(170.94202898550725, 55.21739130434783),
(170.94202898550725, 55.65217391304348),
(170.94202898550725, 56.086956521739125),
(170.94202898550725, 56.52173913043478),
(170.94202898550725, 56.95652173913044),
(170.94202898550725, 57.391304347826086),
(170.94202898550725, 57.826086956521735),
(170.94202898550725, 58.26086956521739),
(170.94202898550725, 58.69565217391305),
(170.94202898550725, 59.130434782608695),
(170.94202898550725, 59.565217391304344),
(170.94202898550725, 60.0),
(171.8840579710145, 30.0),
(171.8840579710145, 30.434782608695652),
(171.8840579710145, 30.869565217391305),
(171.8840579710145, 31.304347826086957),
(171.8840579710145, 31.73913043478261),
(171.8840579710145, 32.17391304347826),
(171.8840579710145, 32.608695652173914),
(171.8840579710145, 33.04347826086956),
(171.8840579710145, 33.47826086956522),
(171.8840579710145, 33.91304347826087),
(171.8840579710145, 34.34782608695652),
(171.8840579710145, 34.78260869565217),
(171.8840579710145, 35.21739130434783),
(171.8840579710145, 35.65217391304348),
(171.8840579710145, 36.08695652173913),
(171.8840579710145, 36.52173913043478),
(171.8840579710145, 36.95652173913044),
(171.8840579710145, 37.391304347826086),
(171.8840579710145, 37.82608695652174),
(171.8840579710145, 38.26086956521739),
(171.8840579710145, 38.69565217391305),
(171.8840579710145, 39.130434782608695),
(171.8840579710145, 39.565217391304344),
(171.8840579710145, 40.0),
(171.8840579710145, 40.434782608695656),
(171.8840579710145, 40.869565217391305),
(171.8840579710145, 41.30434782608695),
(171.8840579710145, 41.73913043478261),
(171.8840579710145, 42.17391304347826),
(171.8840579710145, 42.608695652173914),
(171.8840579710145, 43.04347826086956),
(171.8840579710145, 43.47826086956522),
(171.8840579710145, 43.91304347826087),
(171.8840579710145, 44.34782608695652),
(171.8840579710145, 44.78260869565217),
(171.8840579710145, 45.21739130434783),
(171.8840579710145, 45.65217391304348),
(171.8840579710145, 46.086956521739125),
(171.8840579710145, 46.52173913043478),
(171.8840579710145, 46.95652173913044),
(171.8840579710145, 47.391304347826086),
(171.8840579710145, 47.826086956521735),
(171.8840579710145, 48.26086956521739),
(171.8840579710145, 48.69565217391305),
(171.8840579710145, 49.130434782608695),
(171.8840579710145, 49.565217391304344),
(171.8840579710145, 50.0),
(171.8840579710145, 50.434782608695656),
(171.8840579710145, 50.869565217391305),
(171.8840579710145, 51.30434782608695),
(171.8840579710145, 51.73913043478261),
(171.8840579710145, 52.173913043478265),
(171.8840579710145, 52.608695652173914),
(171.8840579710145, 53.04347826086956),
(171.8840579710145, 53.47826086956522),
(171.8840579710145, 53.91304347826087),
(171.8840579710145, 54.347826086956516),
(171.8840579710145, 54.78260869565217),
(171.8840579710145, 55.21739130434783),
(171.8840579710145, 55.65217391304348),
(171.8840579710145, 56.086956521739125),
(171.8840579710145, 56.52173913043478),
(171.8840579710145, 56.95652173913044),
(171.8840579710145, 57.391304347826086),
(171.8840579710145, 57.826086956521735),
(171.8840579710145, 58.26086956521739),
(171.8840579710145, 58.69565217391305),
(171.8840579710145, 59.130434782608695),
(171.8840579710145, 59.565217391304344),
(171.8840579710145, 60.0),
(172.82608695652175, 30.0),
(172.82608695652175, 30.434782608695652),
(172.82608695652175, 30.869565217391305),
(172.82608695652175, 31.304347826086957),
(172.82608695652175, 31.73913043478261),
(172.82608695652175, 32.17391304347826),
(172.82608695652175, 32.608695652173914),
(172.82608695652175, 33.04347826086956),
(172.82608695652175, 33.47826086956522),
(172.82608695652175, 33.91304347826087),
(172.82608695652175, 34.34782608695652),
(172.82608695652175, 34.78260869565217),
(172.82608695652175, 35.21739130434783),
(172.82608695652175, 35.65217391304348),
(172.82608695652175, 36.08695652173913),
(172.82608695652175, 36.52173913043478),
(172.82608695652175, 36.95652173913044),
(172.82608695652175, 37.391304347826086),
(172.82608695652175, 37.82608695652174),
(172.82608695652175, 38.26086956521739),
(172.82608695652175, 38.69565217391305),
(172.82608695652175, 39.130434782608695),
(172.82608695652175, 39.565217391304344),
(172.82608695652175, 40.0),
(172.82608695652175, 40.434782608695656),
(172.82608695652175, 40.869565217391305),
(172.82608695652175, 41.30434782608695),
(172.82608695652175, 41.73913043478261),
(172.82608695652175, 42.17391304347826),
(172.82608695652175, 42.608695652173914),
(172.82608695652175, 43.04347826086956),
(172.82608695652175, 43.47826086956522),
(172.82608695652175, 43.91304347826087),
(172.82608695652175, 44.34782608695652),
(172.82608695652175, 44.78260869565217),
(172.82608695652175, 45.21739130434783),
(172.82608695652175, 45.65217391304348),
(172.82608695652175, 46.086956521739125),
(172.82608695652175, 46.52173913043478),
(172.82608695652175, 46.95652173913044),
(172.82608695652175, 47.391304347826086),
(172.82608695652175, 47.826086956521735),
(172.82608695652175, 48.26086956521739),
(172.82608695652175, 48.69565217391305),
(172.82608695652175, 49.130434782608695),
(172.82608695652175, 49.565217391304344),
(172.82608695652175, 50.0),
(172.82608695652175, 50.434782608695656),
(172.82608695652175, 50.869565217391305),
(172.82608695652175, 51.30434782608695),
(172.82608695652175, 51.73913043478261),
(172.82608695652175, 52.173913043478265),
(172.82608695652175, 52.608695652173914),
(172.82608695652175, 53.04347826086956),
(172.82608695652175, 53.47826086956522),
(172.82608695652175, 53.91304347826087),
(172.82608695652175, 54.347826086956516),
(172.82608695652175, 54.78260869565217),
(172.82608695652175, 55.21739130434783),
(172.82608695652175, 55.65217391304348),
(172.82608695652175, 56.086956521739125),
(172.82608695652175, 56.52173913043478),
(172.82608695652175, 56.95652173913044),
(172.82608695652175, 57.391304347826086),
(172.82608695652175, 57.826086956521735),
(172.82608695652175, 58.26086956521739),
(172.82608695652175, 58.69565217391305),
(172.82608695652175, 59.130434782608695),
(172.82608695652175, 59.565217391304344),
(172.82608695652175, 60.0),
(173.768115942029, 30.0),
(173.768115942029, 30.434782608695652),
(173.768115942029, 30.869565217391305),
(173.768115942029, 31.304347826086957),
(173.768115942029, 31.73913043478261),
(173.768115942029, 32.17391304347826),
(173.768115942029, 32.608695652173914),
(173.768115942029, 33.04347826086956),
(173.768115942029, 33.47826086956522),
(173.768115942029, 33.91304347826087),
(173.768115942029, 34.34782608695652),
(173.768115942029, 34.78260869565217),
(173.768115942029, 35.21739130434783),
(173.768115942029, 35.65217391304348),
(173.768115942029, 36.08695652173913),
(173.768115942029, 36.52173913043478),
(173.768115942029, 36.95652173913044),
(173.768115942029, 37.391304347826086),
(173.768115942029, 37.82608695652174),
(173.768115942029, 38.26086956521739),
(173.768115942029, 38.69565217391305),
(173.768115942029, 39.130434782608695),
(173.768115942029, 39.565217391304344),
(173.768115942029, 40.0),
(173.768115942029, 40.434782608695656),
(173.768115942029, 40.869565217391305),
(173.768115942029, 41.30434782608695),
(173.768115942029, 41.73913043478261),
(173.768115942029, 42.17391304347826),
(173.768115942029, 42.608695652173914),
(173.768115942029, 43.04347826086956),
(173.768115942029, 43.47826086956522),
(173.768115942029, 43.91304347826087),
(173.768115942029, 44.34782608695652),
(173.768115942029, 44.78260869565217),
(173.768115942029, 45.21739130434783),
(173.768115942029, 45.65217391304348),
(173.768115942029, 46.086956521739125),
(173.768115942029, 46.52173913043478),
(173.768115942029, 46.95652173913044),
(173.768115942029, 47.391304347826086),
(173.768115942029, 47.826086956521735),
(173.768115942029, 48.26086956521739),
(173.768115942029, 48.69565217391305),
(173.768115942029, 49.130434782608695),
(173.768115942029, 49.565217391304344),
(173.768115942029, 50.0),
(173.768115942029, 50.434782608695656),
(173.768115942029, 50.869565217391305),
(173.768115942029, 51.30434782608695),
(173.768115942029, 51.73913043478261),
(173.768115942029, 52.173913043478265),
(173.768115942029, 52.608695652173914),
(173.768115942029, 53.04347826086956),
(173.768115942029, 53.47826086956522),
(173.768115942029, 53.91304347826087),
(173.768115942029, 54.347826086956516),
(173.768115942029, 54.78260869565217),
(173.768115942029, 55.21739130434783),
(173.768115942029, 55.65217391304348),
(173.768115942029, 56.086956521739125),
(173.768115942029, 56.52173913043478),
(173.768115942029, 56.95652173913044),
(173.768115942029, 57.391304347826086),
(173.768115942029, 57.826086956521735),
(173.768115942029, 58.26086956521739),
(173.768115942029, 58.69565217391305),
(173.768115942029, 59.130434782608695),
(173.768115942029, 59.565217391304344),
(173.768115942029, 60.0),
(174.71014492753622, 30.0),
(174.71014492753622, 30.434782608695652),
(174.71014492753622, 30.869565217391305),
(174.71014492753622, 31.304347826086957),
(174.71014492753622, 31.73913043478261),
(174.71014492753622, 32.17391304347826),
(174.71014492753622, 32.608695652173914),
(174.71014492753622, 33.04347826086956),
(174.71014492753622, 33.47826086956522),
(174.71014492753622, 33.91304347826087),
(174.71014492753622, 34.34782608695652),
(174.71014492753622, 34.78260869565217),
(174.71014492753622, 35.21739130434783),
(174.71014492753622, 35.65217391304348),
(174.71014492753622, 36.08695652173913),
(174.71014492753622, 36.52173913043478),
(174.71014492753622, 36.95652173913044),
(174.71014492753622, 37.391304347826086),
(174.71014492753622, 37.82608695652174),
(174.71014492753622, 38.26086956521739),
(174.71014492753622, 38.69565217391305),
(174.71014492753622, 39.130434782608695),
(174.71014492753622, 39.565217391304344),
(174.71014492753622, 40.0),
(174.71014492753622, 40.434782608695656),
(174.71014492753622, 40.869565217391305),
(174.71014492753622, 41.30434782608695),
(174.71014492753622, 41.73913043478261),
(174.71014492753622, 42.17391304347826),
(174.71014492753622, 42.608695652173914),
(174.71014492753622, 43.04347826086956),
(174.71014492753622, 43.47826086956522),
(174.71014492753622, 43.91304347826087),
(174.71014492753622, 44.34782608695652),
(174.71014492753622, 44.78260869565217),
(174.71014492753622, 45.21739130434783),
(174.71014492753622, 45.65217391304348),
(174.71014492753622, 46.086956521739125),
(174.71014492753622, 46.52173913043478),
(174.71014492753622, 46.95652173913044),
(174.71014492753622, 47.391304347826086),
(174.71014492753622, 47.826086956521735),
(174.71014492753622, 48.26086956521739),
(174.71014492753622, 48.69565217391305),
(174.71014492753622, 49.130434782608695),
(174.71014492753622, 49.565217391304344),
(174.71014492753622, 50.0),
(174.71014492753622, 50.434782608695656),
(174.71014492753622, 50.869565217391305),
(174.71014492753622, 51.30434782608695),
(174.71014492753622, 51.73913043478261),
(174.71014492753622, 52.173913043478265),
(174.71014492753622, 52.608695652173914),
(174.71014492753622, 53.04347826086956),
(174.71014492753622, 53.47826086956522),
(174.71014492753622, 53.91304347826087),
(174.71014492753622, 54.347826086956516),
(174.71014492753622, 54.78260869565217),
(174.71014492753622, 55.21739130434783),
(174.71014492753622, 55.65217391304348),
(174.71014492753622, 56.086956521739125),
(174.71014492753622, 56.52173913043478),
(174.71014492753622, 56.95652173913044),
(174.71014492753622, 57.391304347826086),
(174.71014492753622, 57.826086956521735),
(174.71014492753622, 58.26086956521739),
(174.71014492753622, 58.69565217391305),
(174.71014492753622, 59.130434782608695),
(174.71014492753622, 59.565217391304344),
(174.71014492753622, 60.0),
(175.65217391304347, 30.0),
(175.65217391304347, 30.434782608695652),
(175.65217391304347, 30.869565217391305),
(175.65217391304347, 31.304347826086957),
(175.65217391304347, 31.73913043478261),
(175.65217391304347, 32.17391304347826),
(175.65217391304347, 32.608695652173914),
(175.65217391304347, 33.04347826086956),
(175.65217391304347, 33.47826086956522),
(175.65217391304347, 33.91304347826087),
(175.65217391304347, 34.34782608695652),
(175.65217391304347, 34.78260869565217),
(175.65217391304347, 35.21739130434783),
(175.65217391304347, 35.65217391304348),
(175.65217391304347, 36.08695652173913),
(175.65217391304347, 36.52173913043478),
(175.65217391304347, 36.95652173913044),
(175.65217391304347, 37.391304347826086),
(175.65217391304347, 37.82608695652174),
(175.65217391304347, 38.26086956521739),
(175.65217391304347, 38.69565217391305),
(175.65217391304347, 39.130434782608695),
(175.65217391304347, 39.565217391304344),
(175.65217391304347, 40.0),
(175.65217391304347, 40.434782608695656),
(175.65217391304347, 40.869565217391305),
(175.65217391304347, 41.30434782608695),
(175.65217391304347, 41.73913043478261),
(175.65217391304347, 42.17391304347826),
(175.65217391304347, 42.608695652173914),
(175.65217391304347, 43.04347826086956),
(175.65217391304347, 43.47826086956522),
(175.65217391304347, 43.91304347826087),
(175.65217391304347, 44.34782608695652),
(175.65217391304347, 44.78260869565217),
(175.65217391304347, 45.21739130434783),
(175.65217391304347, 45.65217391304348),
(175.65217391304347, 46.086956521739125),
(175.65217391304347, 46.52173913043478),
(175.65217391304347, 46.95652173913044),
(175.65217391304347, 47.391304347826086),
(175.65217391304347, 47.826086956521735),
(175.65217391304347, 48.26086956521739),
(175.65217391304347, 48.69565217391305),
(175.65217391304347, 49.130434782608695),
(175.65217391304347, 49.565217391304344),
(175.65217391304347, 50.0),
(175.65217391304347, 50.434782608695656),
(175.65217391304347, 50.869565217391305),
(175.65217391304347, 51.30434782608695),
(175.65217391304347, 51.73913043478261),
(175.65217391304347, 52.173913043478265),
(175.65217391304347, 52.608695652173914),
(175.65217391304347, 53.04347826086956),
(175.65217391304347, 53.47826086956522),
(175.65217391304347, 53.91304347826087),
(175.65217391304347, 54.347826086956516),
(175.65217391304347, 54.78260869565217),
(175.65217391304347, 55.21739130434783),
(175.65217391304347, 55.65217391304348),
(175.65217391304347, 56.086956521739125),
(175.65217391304347, 56.52173913043478),
(175.65217391304347, 56.95652173913044),
(175.65217391304347, 57.391304347826086),
(175.65217391304347, 57.826086956521735),
(175.65217391304347, 58.26086956521739),
(175.65217391304347, 58.69565217391305),
(175.65217391304347, 59.130434782608695),
(175.65217391304347, 59.565217391304344),
(175.65217391304347, 60.0),
(176.59420289855072, 30.0),
(176.59420289855072, 30.434782608695652),
(176.59420289855072, 30.869565217391305),
(176.59420289855072, 31.304347826086957),
(176.59420289855072, 31.73913043478261),
(176.59420289855072, 32.17391304347826),
(176.59420289855072, 32.608695652173914),
(176.59420289855072, 33.04347826086956),
(176.59420289855072, 33.47826086956522),
(176.59420289855072, 33.91304347826087),
(176.59420289855072, 34.34782608695652),
(176.59420289855072, 34.78260869565217),
(176.59420289855072, 35.21739130434783),
(176.59420289855072, 35.65217391304348),
(176.59420289855072, 36.08695652173913),
(176.59420289855072, 36.52173913043478),
(176.59420289855072, 36.95652173913044),
(176.59420289855072, 37.391304347826086),
(176.59420289855072, 37.82608695652174),
(176.59420289855072, 38.26086956521739),
(176.59420289855072, 38.69565217391305),
(176.59420289855072, 39.130434782608695),
(176.59420289855072, 39.565217391304344),
(176.59420289855072, 40.0),
(176.59420289855072, 40.434782608695656),
(176.59420289855072, 40.869565217391305),
(176.59420289855072, 41.30434782608695),
(176.59420289855072, 41.73913043478261),
(176.59420289855072, 42.17391304347826),
(176.59420289855072, 42.608695652173914),
(176.59420289855072, 43.04347826086956),
(176.59420289855072, 43.47826086956522),
(176.59420289855072, 43.91304347826087),
(176.59420289855072, 44.34782608695652),
(176.59420289855072, 44.78260869565217),
(176.59420289855072, 45.21739130434783),
(176.59420289855072, 45.65217391304348),
(176.59420289855072, 46.086956521739125),
(176.59420289855072, 46.52173913043478),
(176.59420289855072, 46.95652173913044),
(176.59420289855072, 47.391304347826086),
(176.59420289855072, 47.826086956521735),
(176.59420289855072, 48.26086956521739),
(176.59420289855072, 48.69565217391305),
(176.59420289855072, 49.130434782608695),
(176.59420289855072, 49.565217391304344),
(176.59420289855072, 50.0),
(176.59420289855072, 50.434782608695656),
(176.59420289855072, 50.869565217391305),
(176.59420289855072, 51.30434782608695),
(176.59420289855072, 51.73913043478261),
(176.59420289855072, 52.173913043478265),
(176.59420289855072, 52.608695652173914),
(176.59420289855072, 53.04347826086956),
(176.59420289855072, 53.47826086956522),
(176.59420289855072, 53.91304347826087),
(176.59420289855072, 54.347826086956516),
(176.59420289855072, 54.78260869565217),
(176.59420289855072, 55.21739130434783),
(176.59420289855072, 55.65217391304348),
(176.59420289855072, 56.086956521739125),
(176.59420289855072, 56.52173913043478),
(176.59420289855072, 56.95652173913044),
(176.59420289855072, 57.391304347826086),
(176.59420289855072, 57.826086956521735),
(176.59420289855072, 58.26086956521739),
(176.59420289855072, 58.69565217391305),
(176.59420289855072, 59.130434782608695),
(176.59420289855072, 59.565217391304344),
(176.59420289855072, 60.0),
(177.53623188405797, 30.0),
(177.53623188405797, 30.434782608695652),
(177.53623188405797, 30.869565217391305),
(177.53623188405797, 31.304347826086957),
(177.53623188405797, 31.73913043478261),
(177.53623188405797, 32.17391304347826),
(177.53623188405797, 32.608695652173914),
(177.53623188405797, 33.04347826086956),
(177.53623188405797, 33.47826086956522),
(177.53623188405797, 33.91304347826087),
(177.53623188405797, 34.34782608695652),
(177.53623188405797, 34.78260869565217),
(177.53623188405797, 35.21739130434783),
(177.53623188405797, 35.65217391304348),
(177.53623188405797, 36.08695652173913),
(177.53623188405797, 36.52173913043478),
(177.53623188405797, 36.95652173913044),
(177.53623188405797, 37.391304347826086),
(177.53623188405797, 37.82608695652174),
(177.53623188405797, 38.26086956521739),
(177.53623188405797, 38.69565217391305),
(177.53623188405797, 39.130434782608695),
(177.53623188405797, 39.565217391304344),
(177.53623188405797, 40.0),
(177.53623188405797, 40.434782608695656),
(177.53623188405797, 40.869565217391305),
(177.53623188405797, 41.30434782608695),
(177.53623188405797, 41.73913043478261),
(177.53623188405797, 42.17391304347826),
(177.53623188405797, 42.608695652173914),
(177.53623188405797, 43.04347826086956),
(177.53623188405797, 43.47826086956522),
(177.53623188405797, 43.91304347826087),
(177.53623188405797, 44.34782608695652),
(177.53623188405797, 44.78260869565217),
(177.53623188405797, 45.21739130434783),
(177.53623188405797, 45.65217391304348),
(177.53623188405797, 46.086956521739125),
(177.53623188405797, 46.52173913043478),
(177.53623188405797, 46.95652173913044),
(177.53623188405797, 47.391304347826086),
(177.53623188405797, 47.826086956521735),
(177.53623188405797, 48.26086956521739),
(177.53623188405797, 48.69565217391305),
(177.53623188405797, 49.130434782608695),
(177.53623188405797, 49.565217391304344),
(177.53623188405797, 50.0),
(177.53623188405797, 50.434782608695656),
(177.53623188405797, 50.869565217391305),
(177.53623188405797, 51.30434782608695),
(177.53623188405797, 51.73913043478261),
(177.53623188405797, 52.173913043478265),
(177.53623188405797, 52.608695652173914),
(177.53623188405797, 53.04347826086956),
(177.53623188405797, 53.47826086956522),
(177.53623188405797, 53.91304347826087),
(177.53623188405797, 54.347826086956516),
(177.53623188405797, 54.78260869565217),
(177.53623188405797, 55.21739130434783),
(177.53623188405797, 55.65217391304348),
(177.53623188405797, 56.086956521739125),
(177.53623188405797, 56.52173913043478),
(177.53623188405797, 56.95652173913044),
(177.53623188405797, 57.391304347826086),
(177.53623188405797, 57.826086956521735),
(177.53623188405797, 58.26086956521739),
(177.53623188405797, 58.69565217391305),
(177.53623188405797, 59.130434782608695),
(177.53623188405797, 59.565217391304344),
(177.53623188405797, 60.0),
(178.47826086956522, 30.0),
(178.47826086956522, 30.434782608695652),
(178.47826086956522, 30.869565217391305),
(178.47826086956522, 31.304347826086957),
(178.47826086956522, 31.73913043478261),
(178.47826086956522, 32.17391304347826),
(178.47826086956522, 32.608695652173914),
(178.47826086956522, 33.04347826086956),
(178.47826086956522, 33.47826086956522),
(178.47826086956522, 33.91304347826087),
(178.47826086956522, 34.34782608695652),
(178.47826086956522, 34.78260869565217),
(178.47826086956522, 35.21739130434783),
(178.47826086956522, 35.65217391304348),
(178.47826086956522, 36.08695652173913),
(178.47826086956522, 36.52173913043478),
(178.47826086956522, 36.95652173913044),
(178.47826086956522, 37.391304347826086),
(178.47826086956522, 37.82608695652174),
(178.47826086956522, 38.26086956521739),
(178.47826086956522, 38.69565217391305),
(178.47826086956522, 39.130434782608695),
(178.47826086956522, 39.565217391304344),
(178.47826086956522, 40.0),
(178.47826086956522, 40.434782608695656),
(178.47826086956522, 40.869565217391305),
(178.47826086956522, 41.30434782608695),
(178.47826086956522, 41.73913043478261),
(178.47826086956522, 42.17391304347826),
(178.47826086956522, 42.608695652173914),
(178.47826086956522, 43.04347826086956),
(178.47826086956522, 43.47826086956522),
(178.47826086956522, 43.91304347826087),
(178.47826086956522, 44.34782608695652),
(178.47826086956522, 44.78260869565217),
(178.47826086956522, 45.21739130434783),
(178.47826086956522, 45.65217391304348),
(178.47826086956522, 46.086956521739125),
(178.47826086956522, 46.52173913043478),
(178.47826086956522, 46.95652173913044),
(178.47826086956522, 47.391304347826086),
(178.47826086956522, 47.826086956521735),
(178.47826086956522, 48.26086956521739),
(178.47826086956522, 48.69565217391305),
(178.47826086956522, 49.130434782608695),
(178.47826086956522, 49.565217391304344),
(178.47826086956522, 50.0),
(178.47826086956522, 50.434782608695656),
(178.47826086956522, 50.869565217391305),
(178.47826086956522, 51.30434782608695),
(178.47826086956522, 51.73913043478261),
(178.47826086956522, 52.173913043478265),
(178.47826086956522, 52.608695652173914),
(178.47826086956522, 53.04347826086956),
(178.47826086956522, 53.47826086956522),
(178.47826086956522, 53.91304347826087),
(178.47826086956522, 54.347826086956516),
(178.47826086956522, 54.78260869565217),
(178.47826086956522, 55.21739130434783),
(178.47826086956522, 55.65217391304348),
(178.47826086956522, 56.086956521739125),
(178.47826086956522, 56.52173913043478),
(178.47826086956522, 56.95652173913044),
(178.47826086956522, 57.391304347826086),
(178.47826086956522, 57.826086956521735),
(178.47826086956522, 58.26086956521739),
(178.47826086956522, 58.69565217391305),
(178.47826086956522, 59.130434782608695),
(178.47826086956522, 59.565217391304344),
(178.47826086956522, 60.0),
(179.42028985507247, 30.0),
(179.42028985507247, 30.434782608695652),
(179.42028985507247, 30.869565217391305),
(179.42028985507247, 31.304347826086957),
(179.42028985507247, 31.73913043478261),
(179.42028985507247, 32.17391304347826),
(179.42028985507247, 32.608695652173914),
(179.42028985507247, 33.04347826086956),
(179.42028985507247, 33.47826086956522),
(179.42028985507247, 33.91304347826087),
(179.42028985507247, 34.34782608695652),
(179.42028985507247, 34.78260869565217),
(179.42028985507247, 35.21739130434783),
(179.42028985507247, 35.65217391304348),
(179.42028985507247, 36.08695652173913),
(179.42028985507247, 36.52173913043478),
(179.42028985507247, 36.95652173913044),
(179.42028985507247, 37.391304347826086),
(179.42028985507247, 37.82608695652174),
(179.42028985507247, 38.26086956521739),
(179.42028985507247, 38.69565217391305),
(179.42028985507247, 39.130434782608695),
(179.42028985507247, 39.565217391304344),
(179.42028985507247, 40.0),
(179.42028985507247, 40.434782608695656),
(179.42028985507247, 40.869565217391305),
(179.42028985507247, 41.30434782608695),
(179.42028985507247, 41.73913043478261),
(179.42028985507247, 42.17391304347826),
(179.42028985507247, 42.608695652173914),
(179.42028985507247, 43.04347826086956),
(179.42028985507247, 43.47826086956522),
(179.42028985507247, 43.91304347826087),
(179.42028985507247, 44.34782608695652),
(179.42028985507247, 44.78260869565217),
(179.42028985507247, 45.21739130434783),
(179.42028985507247, 45.65217391304348),
(179.42028985507247, 46.086956521739125),
(179.42028985507247, 46.52173913043478),
(179.42028985507247, 46.95652173913044),
(179.42028985507247, 47.391304347826086),
(179.42028985507247, 47.826086956521735),
(179.42028985507247, 48.26086956521739),
(179.42028985507247, 48.69565217391305),
(179.42028985507247, 49.130434782608695),
(179.42028985507247, 49.565217391304344),
(179.42028985507247, 50.0),
(179.42028985507247, 50.434782608695656),
(179.42028985507247, 50.869565217391305),
(179.42028985507247, 51.30434782608695),
(179.42028985507247, 51.73913043478261),
(179.42028985507247, 52.173913043478265),
(179.42028985507247, 52.608695652173914),
(179.42028985507247, 53.04347826086956),
(179.42028985507247, 53.47826086956522),
(179.42028985507247, 53.91304347826087),
(179.42028985507247, 54.347826086956516),
(179.42028985507247, 54.78260869565217),
(179.42028985507247, 55.21739130434783),
(179.42028985507247, 55.65217391304348),
(179.42028985507247, 56.086956521739125),
(179.42028985507247, 56.52173913043478),
(179.42028985507247, 56.95652173913044),
(179.42028985507247, 57.391304347826086),
(179.42028985507247, 57.826086956521735),
(179.42028985507247, 58.26086956521739),
(179.42028985507247, 58.69565217391305),
(179.42028985507247, 59.130434782608695),
(179.42028985507247, 59.565217391304344),
(179.42028985507247, 60.0),
(180.36231884057972, 30.0),
(180.36231884057972, 30.434782608695652),
(180.36231884057972, 30.869565217391305),
(180.36231884057972, 31.304347826086957),
(180.36231884057972, 31.73913043478261),
(180.36231884057972, 32.17391304347826),
(180.36231884057972, 32.608695652173914),
(180.36231884057972, 33.04347826086956),
(180.36231884057972, 33.47826086956522),
(180.36231884057972, 33.91304347826087),
(180.36231884057972, 34.34782608695652),
(180.36231884057972, 34.78260869565217),
(180.36231884057972, 35.21739130434783),
(180.36231884057972, 35.65217391304348),
(180.36231884057972, 36.08695652173913),
(180.36231884057972, 36.52173913043478),
(180.36231884057972, 36.95652173913044),
(180.36231884057972, 37.391304347826086),
(180.36231884057972, 37.82608695652174),
(180.36231884057972, 38.26086956521739),
(180.36231884057972, 38.69565217391305),
(180.36231884057972, 39.130434782608695),
(180.36231884057972, 39.565217391304344),
(180.36231884057972, 40.0),
(180.36231884057972, 40.434782608695656),
(180.36231884057972, 40.869565217391305),
(180.36231884057972, 41.30434782608695),
(180.36231884057972, 41.73913043478261),
(180.36231884057972, 42.17391304347826),
(180.36231884057972, 42.608695652173914),
(180.36231884057972, 43.04347826086956),
(180.36231884057972, 43.47826086956522),
(180.36231884057972, 43.91304347826087),
(180.36231884057972, 44.34782608695652),
(180.36231884057972, 44.78260869565217),
(180.36231884057972, 45.21739130434783),
(180.36231884057972, 45.65217391304348),
(180.36231884057972, 46.086956521739125),
(180.36231884057972, 46.52173913043478),
(180.36231884057972, 46.95652173913044),
(180.36231884057972, 47.391304347826086),
(180.36231884057972, 47.826086956521735),
(180.36231884057972, 48.26086956521739),
(180.36231884057972, 48.69565217391305),
(180.36231884057972, 49.130434782608695),
(180.36231884057972, 49.565217391304344),
(180.36231884057972, 50.0),
(180.36231884057972, 50.434782608695656),
(180.36231884057972, 50.869565217391305),
(180.36231884057972, 51.30434782608695),
(180.36231884057972, 51.73913043478261),
(180.36231884057972, 52.173913043478265),
(180.36231884057972, 52.608695652173914),
(180.36231884057972, 53.04347826086956),
(180.36231884057972, 53.47826086956522),
(180.36231884057972, 53.91304347826087),
(180.36231884057972, 54.347826086956516),
(180.36231884057972, 54.78260869565217),
(180.36231884057972, 55.21739130434783),
(180.36231884057972, 55.65217391304348),
(180.36231884057972, 56.086956521739125),
(180.36231884057972, 56.52173913043478),
(180.36231884057972, 56.95652173913044),
(180.36231884057972, 57.391304347826086),
(180.36231884057972, 57.826086956521735),
(180.36231884057972, 58.26086956521739),
(180.36231884057972, 58.69565217391305),
(180.36231884057972, 59.130434782608695),
(180.36231884057972, 59.565217391304344),
(180.36231884057972, 60.0),
(181.30434782608697, 30.0),
(181.30434782608697, 30.434782608695652),
(181.30434782608697, 30.869565217391305),
(181.30434782608697, 31.304347826086957),
(181.30434782608697, 31.73913043478261),
(181.30434782608697, 32.17391304347826),
(181.30434782608697, 32.608695652173914),
(181.30434782608697, 33.04347826086956),
(181.30434782608697, 33.47826086956522),
(181.30434782608697, 33.91304347826087),
(181.30434782608697, 34.34782608695652),
(181.30434782608697, 34.78260869565217),
(181.30434782608697, 35.21739130434783),
(181.30434782608697, 35.65217391304348),
(181.30434782608697, 36.08695652173913),
(181.30434782608697, 36.52173913043478),
(181.30434782608697, 36.95652173913044),
(181.30434782608697, 37.391304347826086),
(181.30434782608697, 37.82608695652174),
(181.30434782608697, 38.26086956521739),
(181.30434782608697, 38.69565217391305),
(181.30434782608697, 39.130434782608695),
(181.30434782608697, 39.565217391304344),
(181.30434782608697, 40.0),
(181.30434782608697, 40.434782608695656),
(181.30434782608697, 40.869565217391305),
(181.30434782608697, 41.30434782608695),
(181.30434782608697, 41.73913043478261),
(181.30434782608697, 42.17391304347826),
(181.30434782608697, 42.608695652173914),
(181.30434782608697, 43.04347826086956),
(181.30434782608697, 43.47826086956522),
(181.30434782608697, 43.91304347826087),
(181.30434782608697, 44.34782608695652),
(181.30434782608697, 44.78260869565217),
(181.30434782608697, 45.21739130434783),
(181.30434782608697, 45.65217391304348),
(181.30434782608697, 46.086956521739125),
(181.30434782608697, 46.52173913043478),
(181.30434782608697, 46.95652173913044),
(181.30434782608697, 47.391304347826086),
(181.30434782608697, 47.826086956521735),
(181.30434782608697, 48.26086956521739),
(181.30434782608697, 48.69565217391305),
(181.30434782608697, 49.130434782608695),
(181.30434782608697, 49.565217391304344),
(181.30434782608697, 50.0),
(181.30434782608697, 50.434782608695656),
(181.30434782608697, 50.869565217391305),
(181.30434782608697, 51.30434782608695),
(181.30434782608697, 51.73913043478261),
(181.30434782608697, 52.173913043478265),
(181.30434782608697, 52.608695652173914),
(181.30434782608697, 53.04347826086956),
(181.30434782608697, 53.47826086956522),
(181.30434782608697, 53.91304347826087),
(181.30434782608697, 54.347826086956516),
(181.30434782608697, 54.78260869565217),
(181.30434782608697, 55.21739130434783),
(181.30434782608697, 55.65217391304348),
(181.30434782608697, 56.086956521739125),
(181.30434782608697, 56.52173913043478),
(181.30434782608697, 56.95652173913044),
(181.30434782608697, 57.391304347826086),
(181.30434782608697, 57.826086956521735),
(181.30434782608697, 58.26086956521739),
(181.30434782608697, 58.69565217391305),
(181.30434782608697, 59.130434782608695),
(181.30434782608697, 59.565217391304344),
(181.30434782608697, 60.0),
(182.2463768115942, 30.0),
(182.2463768115942, 30.434782608695652),
(182.2463768115942, 30.869565217391305),
(182.2463768115942, 31.304347826086957),
(182.2463768115942, 31.73913043478261),
(182.2463768115942, 32.17391304347826),
(182.2463768115942, 32.608695652173914),
(182.2463768115942, 33.04347826086956),
(182.2463768115942, 33.47826086956522),
(182.2463768115942, 33.91304347826087),
(182.2463768115942, 34.34782608695652),
(182.2463768115942, 34.78260869565217),
(182.2463768115942, 35.21739130434783),
(182.2463768115942, 35.65217391304348),
(182.2463768115942, 36.08695652173913),
(182.2463768115942, 36.52173913043478),
(182.2463768115942, 36.95652173913044),
(182.2463768115942, 37.391304347826086),
(182.2463768115942, 37.82608695652174),
(182.2463768115942, 38.26086956521739),
(182.2463768115942, 38.69565217391305),
(182.2463768115942, 39.130434782608695),
(182.2463768115942, 39.565217391304344),
(182.2463768115942, 40.0),
(182.2463768115942, 40.434782608695656),
(182.2463768115942, 40.869565217391305),
(182.2463768115942, 41.30434782608695),
(182.2463768115942, 41.73913043478261),
(182.2463768115942, 42.17391304347826),
(182.2463768115942, 42.608695652173914),
(182.2463768115942, 43.04347826086956),
(182.2463768115942, 43.47826086956522),
(182.2463768115942, 43.91304347826087),
(182.2463768115942, 44.34782608695652),
(182.2463768115942, 44.78260869565217),
(182.2463768115942, 45.21739130434783),
(182.2463768115942, 45.65217391304348),
(182.2463768115942, 46.086956521739125),
(182.2463768115942, 46.52173913043478),
(182.2463768115942, 46.95652173913044),
(182.2463768115942, 47.391304347826086),
(182.2463768115942, 47.826086956521735),
(182.2463768115942, 48.26086956521739),
(182.2463768115942, 48.69565217391305),
(182.2463768115942, 49.130434782608695),
(182.2463768115942, 49.565217391304344),
(182.2463768115942, 50.0),
(182.2463768115942, 50.434782608695656),
(182.2463768115942, 50.869565217391305),
(182.2463768115942, 51.30434782608695),
(182.2463768115942, 51.73913043478261),
(182.2463768115942, 52.173913043478265),
(182.2463768115942, 52.608695652173914),
(182.2463768115942, 53.04347826086956),
(182.2463768115942, 53.47826086956522),
(182.2463768115942, 53.91304347826087),
(182.2463768115942, 54.347826086956516),
(182.2463768115942, 54.78260869565217),
(182.2463768115942, 55.21739130434783),
(182.2463768115942, 55.65217391304348),
(182.2463768115942, 56.086956521739125),
(182.2463768115942, 56.52173913043478),
(182.2463768115942, 56.95652173913044),
(182.2463768115942, 57.391304347826086),
(182.2463768115942, 57.826086956521735),
(182.2463768115942, 58.26086956521739),
(182.2463768115942, 58.69565217391305),
(182.2463768115942, 59.130434782608695),
(182.2463768115942, 59.565217391304344),
(182.2463768115942, 60.0),
(183.18840579710144, 30.0),
(183.18840579710144, 30.434782608695652),
(183.18840579710144, 30.869565217391305),
(183.18840579710144, 31.304347826086957),
(183.18840579710144, 31.73913043478261),
(183.18840579710144, 32.17391304347826),
(183.18840579710144, 32.608695652173914),
(183.18840579710144, 33.04347826086956),
(183.18840579710144, 33.47826086956522),
(183.18840579710144, 33.91304347826087),
(183.18840579710144, 34.34782608695652),
(183.18840579710144, 34.78260869565217),
(183.18840579710144, 35.21739130434783),
(183.18840579710144, 35.65217391304348),
(183.18840579710144, 36.08695652173913),
(183.18840579710144, 36.52173913043478),
(183.18840579710144, 36.95652173913044),
(183.18840579710144, 37.391304347826086),
(183.18840579710144, 37.82608695652174),
(183.18840579710144, 38.26086956521739),
...]
len(list(product(x,y)))
4900
Make a DataFrame
df_art(for “artificial”) containing all the possible pairs of coordinates fromxandy. (We chose 70 above sodf_artwill have 4900 rows, which is a good length for Altair.)
df_art = pd.DataFrame(list(product(x,y)))
df_art.head()
| 0 | 1 | |
|---|---|---|
| 0 | 170.0 | 30.000000 |
| 1 | 170.0 | 30.434783 |
| 2 | 170.0 | 30.869565 |
| 3 | 170.0 | 31.304348 |
| 4 | 170.0 | 31.739130 |
df_art.columns = cols
df_art.head()
| flipper_length_mm | bill_length_mm | |
|---|---|---|
| 0 | 170.0 | 30.000000 |
| 1 | 170.0 | 30.434783 |
| 2 | 170.0 | 30.869565 |
| 3 | 170.0 | 31.304348 |
| 4 | 170.0 | 31.739130 |
We’ve already fit our Logistic Regression model to the real data. Let’s predict on this sample data.
Add a corresponding “pred” column to
df_art.
df_art["pred"] = clf.predict(df_art[cols])
df_art
| flipper_length_mm | bill_length_mm | pred | |
|---|---|---|---|
| 0 | 170.0 | 30.000000 | Adelie |
| 1 | 170.0 | 30.434783 | Adelie |
| 2 | 170.0 | 30.869565 | Adelie |
| 3 | 170.0 | 31.304348 | Adelie |
| 4 | 170.0 | 31.739130 | Adelie |
| ... | ... | ... | ... |
| 4895 | 235.0 | 58.260870 | Gentoo |
| 4896 | 235.0 | 58.695652 | Gentoo |
| 4897 | 235.0 | 59.130435 | Gentoo |
| 4898 | 235.0 | 59.565217 | Gentoo |
| 4899 | 235.0 | 60.000000 | Gentoo |
4900 rows × 3 columns
This is saying that if there were a penguin with the measurements (170,30), it predicts that it would be an Adelie penguin. Note: we don’t expect a real penguin to have any of these measurements exactly.
When we predicted on df_art, it’s important that the column names matched the names of the column of df where we fit the model. We would get a warning message if this was not the case.
Make another Altair scatter plot of the predicted species, this time using
df_art.
c4 = alt.Chart(df_art).mark_point(filled=True).encode(
x=alt.X(cols[0]).scale(zero=False),
y=alt.Y(cols[1]).scale(zero=False),
color="pred",
shape="pred"
).properties(title="artificial data")
c4
c2 | c4
Here we can really clearly see the decision boundaries! Notice that they are lines!!
A loss function for classification#
So far, the only way we’ve seen to measure performance of our logistic regression model is using accuracy (e.g. how many predictions did our model get correct). Accuracy is not a loss function - think back to our examples from linear regression with mean squared error and absolute squared error. For loss functions, a smaller number is better, while for accuracy, a higher number is better.
Key Takeaway: Accuracy is too rough of a measure. Here’s an example:
Imagine our model has two predictions for [Adelie, Chinstrap, Gentoo]: [1,0,0] and [0.34, 0.33, 0.33]. In both cases, our model will predict that we have an Adelie penguin. But! In the first example, it thinks this is with probability 1, while in this second case, it thinks all options (basically) equally likely. There’s a big difference between these two cases! Suppose the model got both of these correct, just checking accuracy wouldn’t tell us how to distinguish between these two cases.
This is where we got to in lecture today, but I’ll fill in the notes below so that you can read up on your own :)
A commonly used loss function for logistic regression is called log loss (sometimes called cross entropy).
Definition: Suppose we have \(n\) observations \((X_1,y_1) \dots (X_n,y_n)\). Suppose our model predicts with probability \(\pi_{y_i}(X_i)\) that \(y_i\) is the output corresponding to the input \(X_i\). The corresponding log loss is as follows:
This definition might be a little strange at first, but let me try to convince you that this is a good definition with some nice properties.
Suppose our model predicted values perfectly. Then each \(\pi_{y_i}(X_i) = 1\), so the entire sum is zero. This is just like our performance measures being zero in the polynomial regression examples from earlier lectures.
Suppose our model makes the worst possible prediction. This would be like saying \(\pi_{y_i}(X_i)\) is zero, which means our logarithm is undefined. You can imagine this being infinite, or in the implementation of scikit-learn being a very large positive number.
Here is some example data. Say we have three possible outputs, the three classes of penguin, Adelie, Chinstrap, and Gentoo. Say we have three data points:
(X_1, Adelie), with predicted probabilities [prob of Adelie 0.8, prob of Chinstrap 0.1, prob of Gentoo 0.1]
(X_2, Gentoo), with predicted probabilities [0.1, 0.5, 0.4]
(X_3, Adelie), with predicted probabilities [0.6, 0.3, 0.1]
pred_probs = [[0.8,0.1,0.1],[0.1,0.5,0.4],[0.6,0.3,0.1]]
n = 3
Let’s compute the log loss in this case.
(1/n)*(-np.log(0.8)+ -np.log(0.4) + -np.log(0.6))
0.5500866356514518
Next we create a list which holds the true species of each penguin.
y_true = ["Adelie","Gentoo","Adelie"]
In practice, we’d never compute the log loss by hand. Here’s how we use scikit-learn.
from sklearn.metrics import log_loss
#This will give an error! The Error message gives a nice hint...
log_loss(y_true,pred_probs)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [8], line 2
1 #This will give an error! The Error message gives a nice hint...
----> 2 log_loss(y_true,pred_probs)
File /shared-libs/python3.9/py/lib/python3.9/site-packages/sklearn/metrics/_classification.py:2447, in log_loss(y_true, y_pred, eps, normalize, sample_weight, labels)
2445 if len(lb.classes_) != y_pred.shape[1]:
2446 if labels is None:
-> 2447 raise ValueError(
2448 "y_true and y_pred contain different number of "
2449 "classes {0}, {1}. Please provide the true "
2450 "labels explicitly through the labels argument. "
2451 "Classes found in "
2452 "y_true: {2}".format(
2453 transformed_labels.shape[1], y_pred.shape[1], lb.classes_
2454 )
2455 )
2456 else:
2457 raise ValueError(
2458 "The number of classes in labels is different "
2459 "from that in y_pred. Classes found in "
2460 "labels: {0}".format(lb.classes_)
2461 )
ValueError: y_true and y_pred contain different number of classes 2, 3. Please provide the true labels explicitly through the labels argument. Classes found in y_true: ['Adelie' 'Chinstrap']
Notice! y_true has just two penguins, Adelie and Chinstrap, while the probabilities have three distinct classes. We can fix this as follows:
log_loss(y_true, pred_probs, labels=["Adelie","Chinstrap","Gentoo"])
0.5500866356514518
Notice this is the same result we got above! A few comments:
The order we type for the labels doesn’t matter - scikit-learn will alphabetize them
The order of
pred_probsmust appear in the order the scikit-learn sorts the labels in, that is, alphabetically.