Week 7 Videos
Contents
Week 7 Videos¶
Trying to use linear regression for classification¶
With respect to the penguins dataset, write a linear function to model the following.
Input: bill length
Output: 1 if the species is “Adelie”, 0 otherwise
import numpy as np
import pandas as pd
import altair as alt
import seaborn as sns
df = sns.load_dataset("penguins").dropna()
df["isAdelie_bool"] = (df["species"] == "Adelie")
df.head()
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isAdelie_bool | |
---|---|---|---|---|---|---|---|---|
0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | True |
1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | True |
2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | True |
4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | True |
5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | True |
(df["species"] == "Adelie")
0 True
1 True
2 True
4 True
5 True
...
338 False
340 False
341 False
342 False
343 False
Name: species, Length: 333, dtype: bool
(df["species"] == "Adelie").astype(float)
0 1.0
1 1.0
2 1.0
4 1.0
5 1.0
...
338 0.0
340 0.0
341 0.0
342 0.0
343 0.0
Name: species, Length: 333, dtype: float64
df["isAdelie_float"] = (df["species"] == "Adelie").astype(float)
df.tail()
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isAdelie_bool | isAdelie_float | |
---|---|---|---|---|---|---|---|---|---|
338 | Gentoo | Biscoe | 47.2 | 13.7 | 214.0 | 4925.0 | Female | False | 0.0 |
340 | Gentoo | Biscoe | 46.8 | 14.3 | 215.0 | 4850.0 | Female | False | 0.0 |
341 | Gentoo | Biscoe | 50.4 | 15.7 | 222.0 | 5750.0 | Male | False | 0.0 |
342 | Gentoo | Biscoe | 45.2 | 14.8 | 212.0 | 5200.0 | Female | False | 0.0 |
343 | Gentoo | Biscoe | 49.9 | 16.1 | 213.0 | 5400.0 | Male | False | 0.0 |
alt.Chart(df).mark_circle().encode(
x="bill_length_mm",
y="isAdelie_bool"
)
alt.Chart(df).mark_circle().encode(
x="bill_length_mm",
y="isAdelie_float"
)
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(df[["bill_length_mm"]], df["isAdelie_float"])
LinearRegression()
c = alt.Chart(df).mark_circle().encode(
x="bill_length_mm",
y="isAdelie_float"
)
df["Pred"] = reg.predict(df[["bill_length_mm"]])
df.head()
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isAdelie_bool | isAdelie_float | Pred | |
---|---|---|---|---|---|---|---|---|---|---|
0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | True | 1.0 | 0.810316 |
1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | True | 1.0 | 0.779914 |
2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | True | 1.0 | 0.719110 |
4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | True | 1.0 | 0.992728 |
5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | True | 1.0 | 0.795115 |
c1 = alt.Chart(df).mark_line(color="red").encode(
x="bill_length_mm",
y="Pred"
)
c+c1
Logistic Regression, Part 1¶
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression()
clf.fit(df[["bill_length_mm"]], df["isAdelie_float"])
LogisticRegression()
df["Pred2"] = clf.predict(df[["bill_length_mm"]])
c2 = alt.Chart(df).mark_point(color="red").encode(
x="bill_length_mm",
y="Pred2"
)
c+c2
Logistic Regression, Part 2¶
clf.predict(df[["bill_length_mm"]])
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0.,
1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 0., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 0., 1., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
clf.classes_
array([0., 1.])
clf.predict_proba(df[["bill_length_mm"]])
array([[1.30799652e-02, 9.86920035e-01],
[2.05066613e-02, 9.79493339e-01],
[4.96495104e-02, 9.50350490e-01],
[8.52199486e-04, 9.99147801e-01],
[1.63845452e-02, 9.83615455e-01],
[1.04348115e-02, 9.89565189e-01],
[1.46406871e-02, 9.85359313e-01],
[1.15331850e-01, 8.84668150e-01],
[7.42806258e-03, 9.92571937e-01],
[7.73377420e-05, 9.99922662e-01],
[7.60219551e-04, 9.99239780e-01],
[8.32007603e-03, 9.91679924e-01],
[3.92426682e-01, 6.07573318e-01],
[6.15338273e-05, 9.99938466e-01],
[9.72443311e-01, 2.75566890e-02],
[2.99002877e-03, 9.97009971e-01],
[2.66792391e-03, 9.97332076e-01],
[3.41684610e-04, 9.99658315e-01],
[4.71511319e-03, 9.95284887e-01],
[9.31820304e-03, 9.90681797e-01],
[1.72125733e-04, 9.99827874e-01],
[6.85661583e-02, 9.31433842e-01],
[6.16163575e-02, 9.38383643e-01],
[3.35089145e-03, 9.96649109e-01],
[6.16163575e-02, 9.38383643e-01],
[2.05066613e-02, 9.79493339e-01],
[1.50822829e-03, 9.98491772e-01],
[2.05066613e-02, 9.79493339e-01],
[9.39774090e-02, 9.06022591e-01],
[6.04953631e-04, 9.99395046e-01],
[1.46406871e-02, 9.85359313e-01],
[9.31820304e-03, 9.90681797e-01],
[3.14311397e-01, 6.85688603e-01],
[2.38043539e-03, 9.97619565e-01],
[2.86545644e-02, 9.71345436e-01],
[6.78160493e-04, 9.99321840e-01],
[8.46861273e-02, 9.15313873e-01],
[3.83044879e-04, 9.99616955e-01],
[8.00873634e-01, 1.99126366e-01],
[1.20037389e-03, 9.98799626e-01],
[2.29329565e-02, 9.77067043e-01],
[1.15331850e-01, 8.84668150e-01],
[3.83044879e-04, 9.99616955e-01],
[3.39452733e-01, 6.60547267e-01],
[2.29329565e-02, 9.77067043e-01],
[3.99079674e-02, 9.60092033e-01],
[1.22163331e-04, 9.99877837e-01],
[2.67244087e-01, 7.32755913e-01],
[6.89847197e-05, 9.99931015e-01],
[1.55187227e-01, 8.44812773e-01],
[1.16836461e-02, 9.88316354e-01],
[6.85661583e-02, 9.31433842e-01],
[6.78160493e-04, 9.99321840e-01],
[2.38043539e-03, 9.97619565e-01],
[2.71876281e-04, 9.99728124e-01],
[1.40784653e-01, 8.59215347e-01],
[2.38043539e-03, 9.97619565e-01],
[1.15331850e-01, 8.84668150e-01],
[6.04953631e-04, 9.99395046e-01],
[1.87570877e-01, 8.12429123e-01],
[2.16327149e-04, 9.99783673e-01],
[1.15331850e-01, 8.84668150e-01],
[3.41684610e-04, 9.99658315e-01],
[2.24913098e-01, 7.75086902e-01],
[2.19963788e-05, 9.99978004e-01],
[2.56388105e-02, 9.74361190e-01],
[2.29329565e-02, 9.77067043e-01],
[9.65608720e-01, 3.43912804e-02],
[2.16327149e-04, 9.99783673e-01],
[4.76465682e-01, 5.23534318e-01],
[9.39774090e-02, 9.06022591e-01],
[1.50822829e-03, 9.98491772e-01],
[4.81383675e-04, 9.99518616e-01],
[2.90214026e-01, 7.09785974e-01],
[7.73377420e-05, 9.99922662e-01],
[5.05024465e-01, 4.94975535e-01],
[8.52199486e-04, 9.99147801e-01],
[1.36954610e-04, 9.99863045e-01],
[1.69055764e-03, 9.98309442e-01],
[1.40784653e-01, 8.59215347e-01],
[5.39645121e-04, 9.99460355e-01],
[1.07085493e-03, 9.98929145e-01],
[5.28307085e-03, 9.94716929e-01],
[1.04348115e-02, 9.89565189e-01],
[2.71876281e-04, 9.99728124e-01],
[1.15331850e-01, 8.84668150e-01],
[3.89542535e-05, 9.99961046e-01],
[2.29329565e-02, 9.77067043e-01],
[4.81383675e-04, 9.99518616e-01],
[8.46861273e-02, 9.15313873e-01],
[4.20795564e-03, 9.95792044e-01],
[4.96495104e-02, 9.50350490e-01],
[1.39247000e-05, 9.99986075e-01],
[5.89770033e-01, 4.10229967e-01],
[1.22163331e-04, 9.99877837e-01],
[1.04172061e-01, 8.95827939e-01],
[2.66792391e-03, 9.97332076e-01],
[2.99002877e-03, 9.97009971e-01],
[3.35089145e-03, 9.96649109e-01],
[2.56388105e-02, 9.74361190e-01],
[7.42806258e-03, 9.92571937e-01],
[4.71511319e-03, 9.95284887e-01],
[4.20795564e-03, 9.95792044e-01],
[5.89770033e-01, 4.10229967e-01],
[4.20795564e-03, 9.95792044e-01],
[9.57153705e-01, 4.28462951e-02],
[2.56388105e-02, 9.74361190e-01],
[3.14311397e-01, 6.85688603e-01],
[2.29329565e-02, 9.77067043e-01],
[4.48059973e-01, 5.51940027e-01],
[7.42806258e-03, 9.92571937e-01],
[1.69055764e-03, 9.98309442e-01],
[2.71876281e-04, 9.99728124e-01],
[1.15331850e-01, 8.84668150e-01],
[4.81383675e-04, 9.99518616e-01],
[2.66792391e-03, 9.97332076e-01],
[4.45254267e-02, 9.55474573e-01],
[1.55187227e-01, 8.44812773e-01],
[1.53536510e-04, 9.99846463e-01],
[6.85661583e-02, 9.31433842e-01],
[9.31820304e-03, 9.90681797e-01],
[1.70770372e-01, 8.29229628e-01],
[1.16836461e-02, 9.88316354e-01],
[8.00873634e-01, 1.99126366e-01],
[6.63104436e-03, 9.93368956e-01],
[5.61858807e-01, 4.38141193e-01],
[9.55297552e-04, 9.99044702e-01],
[2.12385991e-03, 9.97876140e-01],
[4.20795564e-03, 9.95792044e-01],
[1.15331850e-01, 8.84668150e-01],
[2.42516818e-04, 9.99757483e-01],
[4.45254267e-02, 9.55474573e-01],
[1.20037389e-03, 9.98799626e-01],
[2.56388105e-02, 9.74361190e-01],
[4.45254267e-02, 9.55474573e-01],
[6.85661583e-02, 9.31433842e-01],
[4.43984538e-06, 9.99995560e-01],
[7.62361538e-02, 9.23763846e-01],
[1.69055764e-03, 9.98309442e-01],
[1.16836461e-02, 9.88316354e-01],
[1.46406871e-02, 9.85359313e-01],
[7.60219551e-04, 9.99239780e-01],
[3.83044879e-04, 9.99616955e-01],
[2.99002877e-03, 9.97009971e-01],
[3.83044879e-04, 9.99616955e-01],
[1.70770372e-01, 8.29229628e-01],
[9.84250837e-01, 1.57491628e-02],
[9.99707216e-01, 2.92783827e-04],
[9.99933733e-01, 6.62669098e-05],
[9.46734708e-01, 5.32652921e-02],
[9.99986624e-01, 1.33760758e-05],
[9.33956925e-01, 6.60430749e-02],
[9.75346452e-01, 2.46535485e-02],
[9.99933733e-01, 6.62669098e-05],
[9.72443311e-01, 2.75566890e-02],
[9.99933733e-01, 6.62669098e-05],
[9.85928037e-01, 1.40719630e-02],
[9.99958049e-01, 4.19506246e-05],
[9.91045646e-01, 8.95435438e-03],
[9.99970227e-01, 2.97726220e-05],
[9.69209096e-01, 3.07909037e-02],
[9.99834655e-01, 1.65345120e-04],
[9.99792194e-01, 2.07805655e-04],
[9.99999969e-01, 3.12821989e-08],
[9.82377309e-01, 1.76226906e-02],
[9.99269711e-01, 7.30288862e-04],
[3.65533037e-01, 6.34466963e-01],
[9.98375942e-01, 1.62405804e-03],
[5.89770033e-01, 4.10229967e-01],
[9.99852512e-01, 1.47488081e-04],
[9.87428905e-01, 1.25710946e-02],
[9.99970227e-01, 2.97726220e-05],
[9.99834655e-01, 1.65345120e-04],
[9.99481606e-01, 5.18394187e-04],
[9.82377309e-01, 1.76226906e-02],
[9.99988069e-01, 1.19312827e-05],
[9.39774090e-02, 9.06022591e-01],
[9.99997592e-01, 2.40824297e-06],
[3.92426682e-01, 6.07573318e-01],
[9.99906629e-01, 9.33709082e-05],
[9.99587502e-01, 4.12497870e-04],
[9.94924025e-01, 5.07597504e-03],
[9.95469820e-01, 4.53017987e-03],
[9.99970227e-01, 2.97726220e-05],
[9.89972196e-01, 1.00278038e-02],
[9.99994640e-01, 5.36036675e-06],
[9.99082307e-01, 9.17693479e-04],
[9.77950677e-01, 2.20493235e-02],
[9.99895324e-01, 1.04676426e-04],
[9.52213195e-01, 4.77868053e-02],
[9.99895324e-01, 1.04676426e-04],
[9.99882649e-01, 1.17350675e-04],
[9.99738833e-01, 2.61167184e-04],
[9.99082307e-01, 9.17693479e-04],
[9.99947275e-01, 5.27251927e-05],
[9.99632041e-01, 3.67958508e-04],
[9.97436923e-01, 2.56307744e-03],
[9.99940890e-01, 5.91095448e-05],
[9.61604029e-01, 3.83959708e-02],
[9.99868441e-01, 1.31559324e-04],
[3.92426682e-01, 6.07573318e-01],
[9.99976312e-01, 2.36883768e-05],
[9.33956925e-01, 6.60430749e-02],
[9.99348542e-01, 6.51458454e-04],
[9.99767036e-01, 2.32963909e-04],
[9.57153705e-01, 4.28462951e-02],
[9.99966622e-01, 3.33778017e-05],
[9.88771519e-01, 1.12284806e-02],
[9.61604029e-01, 3.83959708e-02],
[9.99999613e-01, 3.86745960e-07],
[6.69501446e-01, 3.30498554e-01],
[9.99537574e-01, 4.62425984e-04],
[9.99882649e-01, 1.17350675e-04],
[9.99767036e-01, 2.32963909e-04],
[9.75346452e-01, 2.46535485e-02],
[9.99707216e-01, 2.92783827e-04],
[9.98707409e-01, 1.29259147e-03],
[9.99707216e-01, 2.92783827e-04],
[9.95469820e-01, 4.53017987e-03],
[9.84250837e-01, 1.57491628e-02],
[9.46734708e-01, 5.32652921e-02],
[9.87428905e-01, 1.25710946e-02],
[6.17114881e-01, 3.82885119e-01],
[9.88771519e-01, 1.12284806e-02],
[9.39774090e-02, 9.06022591e-01],
[9.99082307e-01, 9.17693479e-04],
[9.52213195e-01, 4.77868053e-02],
[9.98179636e-01, 1.82036449e-03],
[9.65608720e-01, 3.43912804e-02],
[9.99348542e-01, 6.51458454e-04],
[2.67244087e-01, 7.32755913e-01],
[9.99269711e-01, 7.30288862e-04],
[9.77950677e-01, 2.20493235e-02],
[9.98707409e-01, 1.29259147e-03],
[9.99767036e-01, 2.32963909e-04],
[9.26546911e-01, 7.34530888e-02],
[9.84250837e-01, 1.57491628e-02],
[9.80285370e-01, 1.97146298e-02],
[5.05024465e-01, 4.94975535e-01],
[9.75346452e-01, 2.46535485e-02],
[9.96392276e-01, 3.60772375e-03],
[9.97713139e-01, 2.28686099e-03],
[9.99707216e-01, 2.92783827e-04],
[9.93628553e-01, 6.37144659e-03],
[4.76465682e-01, 5.23534318e-01],
[9.26546911e-01, 7.34530888e-02],
[9.99999995e-01, 5.02367911e-09],
[9.99181350e-01, 8.18650412e-04],
[9.98179636e-01, 1.82036449e-03],
[4.19989202e-01, 5.80010798e-01],
[8.50010040e-01, 1.49989960e-01],
[7.82016783e-01, 2.17983217e-01],
[9.98707409e-01, 1.29259147e-03],
[4.48059973e-01, 5.51940027e-01],
[9.99537574e-01, 4.62425984e-04],
[9.40667279e-01, 5.93327208e-02],
[9.99537574e-01, 4.62425984e-04],
[9.99834655e-01, 1.65345120e-04],
[6.94286531e-01, 3.05713469e-01],
[9.52213195e-01, 4.77868053e-02],
[9.99834655e-01, 1.65345120e-04],
[9.09389788e-01, 9.06102122e-02],
[9.33956925e-01, 6.60430749e-02],
[9.85928037e-01, 1.40719630e-02],
[9.98375942e-01, 1.62405804e-03],
[9.26546911e-01, 7.34530888e-02],
[9.99738833e-01, 2.61167184e-04],
[9.84250837e-01, 1.57491628e-02],
[9.18378155e-01, 8.16218450e-02],
[7.40553486e-01, 2.59446514e-01],
[9.52213195e-01, 4.77868053e-02],
[5.89770033e-01, 4.10229967e-01],
[9.99814636e-01, 1.85363789e-04],
[9.40667279e-01, 5.93327208e-02],
[9.77950677e-01, 2.20493235e-02],
[9.61604029e-01, 3.83959708e-02],
[9.99997852e-01, 2.14811834e-06],
[9.65608720e-01, 3.43912804e-02],
[9.99632041e-01, 3.67958508e-04],
[9.99481606e-01, 5.18394187e-04],
[6.69501446e-01, 3.30498554e-01],
[9.99868441e-01, 1.31559324e-04],
[9.95957167e-01, 4.04283295e-03],
[9.82377309e-01, 1.76226906e-02],
[9.97713139e-01, 2.28686099e-03],
[9.84250837e-01, 1.57491628e-02],
[9.82377309e-01, 1.76226906e-02],
[9.98551110e-01, 1.44889037e-03],
[9.94924025e-01, 5.07597504e-03],
[9.99916714e-01, 8.32863349e-05],
[9.33956925e-01, 6.60430749e-02],
[9.33956925e-01, 6.60430749e-02],
[9.99181350e-01, 8.18650412e-04],
[9.99983188e-01, 1.68117008e-05],
[9.94312848e-01, 5.68715183e-03],
[9.99707216e-01, 2.92783827e-04],
[9.09389788e-01, 9.06102122e-02],
[9.99882649e-01, 1.17350675e-04],
[6.43738052e-01, 3.56261948e-01],
[9.99933733e-01, 6.62669098e-05],
[9.94924025e-01, 5.07597504e-03],
[9.99973443e-01, 2.65568321e-05],
[9.94924025e-01, 5.07597504e-03],
[9.99976312e-01, 2.36883768e-05],
[9.52213195e-01, 4.77868053e-02],
[9.99481606e-01, 5.18394187e-04],
[8.64007912e-01, 1.35992088e-01],
[9.99882649e-01, 1.17350675e-04],
[9.99418868e-01, 5.81132379e-04],
[9.89972196e-01, 1.00278038e-02],
[9.98179636e-01, 1.82036449e-03],
[9.99916714e-01, 8.32863349e-05],
[9.98375942e-01, 1.62405804e-03],
[9.99999655e-01, 3.44971798e-07],
[9.92862513e-01, 7.13748666e-03],
[9.99181350e-01, 8.18650412e-04],
[9.88771519e-01, 1.12284806e-02],
[2.05614390e-01, 7.94385610e-01],
[9.99993991e-01, 6.00947364e-06],
[6.17114881e-01, 3.82885119e-01],
[9.97436923e-01, 2.56307744e-03],
[9.99834655e-01, 1.65345120e-04],
[9.99632041e-01, 3.67958508e-04],
[6.69501446e-01, 3.30498554e-01],
[9.99947275e-01, 5.27251927e-05],
[9.77950677e-01, 2.20493235e-02],
[9.99999139e-01, 8.60837276e-07],
[9.98846866e-01, 1.15313383e-03],
[9.92862513e-01, 7.13748666e-03],
[9.88771519e-01, 1.12284806e-02],
[9.99814636e-01, 1.85363789e-04],
[9.33956925e-01, 6.60430749e-02],
[9.99671773e-01, 3.28226694e-04]])
A = clf.predict_proba(df[["bill_length_mm"]])
df["Pred3"] = A[:,1]
c3 = alt.Chart(df).mark_line(color="red").encode(
x="bill_length_mm",
y="Pred3"
)
c+c3
Logistic Regression, Part 3¶
clf = LogisticRegression()
clf.fit(df[["bill_length_mm"]], df["species"])
LogisticRegression()
df["Pred4"] = clf.predict(df[["bill_length_mm"]])
df.head()
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | isAdelie_bool | isAdelie_float | Pred | Pred2 | Pred3 | Pred4 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Adelie | Torgersen | 39.1 | 18.7 | 181.0 | 3750.0 | Male | True | 1.0 | 0.810316 | 1.0 | 0.986920 | Adelie |
1 | Adelie | Torgersen | 39.5 | 17.4 | 186.0 | 3800.0 | Female | True | 1.0 | 0.779914 | 1.0 | 0.979493 | Adelie |
2 | Adelie | Torgersen | 40.3 | 18.0 | 195.0 | 3250.0 | Female | True | 1.0 | 0.719110 | 1.0 | 0.950350 | Adelie |
4 | Adelie | Torgersen | 36.7 | 19.3 | 193.0 | 3450.0 | Female | True | 1.0 | 0.992728 | 1.0 | 0.999148 | Adelie |
5 | Adelie | Torgersen | 39.3 | 20.6 | 190.0 | 3650.0 | Male | True | 1.0 | 0.795115 | 1.0 | 0.983615 | Adelie |
df["Pred4"].value_counts()
Gentoo 173
Adelie 150
Chinstrap 10
Name: Pred4, dtype: int64
df["species"].value_counts()
Adelie 146
Gentoo 119
Chinstrap 68
Name: species, dtype: int64
alt.Chart(df).mark_circle().encode(
x="bill_length_mm",
y="flipper_length_mm",
color="species"
)
clf.score(df[["bill_length_mm"]], df["species"])
0.7537537537537538
clf.classes_
array(['Adelie', 'Chinstrap', 'Gentoo'], dtype=object)
clf.predict_proba(df[["bill_length_mm"]])
array([[9.87130539e-01, 2.03702100e-03, 1.08324397e-02],
[9.79823354e-01, 3.32737771e-03, 1.68492686e-02],
[9.51091028e-01, 8.74667922e-03, 4.01622930e-02],
[9.99155737e-01, 1.03813470e-04, 7.40449484e-04],
[9.83879892e-01, 2.60453202e-03, 1.35155762e-02],
[9.89731718e-01, 1.59210500e-03, 8.67617683e-03],
[9.85595436e-01, 2.30357815e-03, 1.21009863e-02],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.92687793e-01, 1.09904848e-03, 6.21315814e-03],
[9.99922311e-01, 7.60039974e-06, 7.00890612e-05],
[9.99246476e-01, 9.16663201e-05, 6.61857479e-04],
[9.91810870e-01, 1.24370214e-03, 6.94542752e-03],
[6.09053113e-01, 8.67181448e-02, 3.04228742e-01],
[9.99938084e-01, 5.92483944e-06, 5.59907528e-05],
[2.66195596e-02, 2.96191724e-01, 6.77188717e-01],
[9.97051092e-01, 4.07619342e-04, 2.54128862e-03],
[9.97367925e-01, 3.60005733e-04, 2.27206934e-03],
[9.99659963e-01, 3.83535901e-05, 3.01683390e-04],
[9.95354809e-01, 6.69651256e-04, 3.97553948e-03],
[9.90829578e-01, 1.40724538e-03, 7.76317677e-03],
[9.99828013e-01, 1.81710040e-05, 1.53816186e-04],
[9.32396091e-01, 1.24586679e-02, 5.51452412e-02],
[9.39268175e-01, 1.10809609e-02, 4.96508640e-02],
[9.96696188e-01, 4.61512552e-04, 2.84229904e-03],
[9.39268175e-01, 1.10809609e-02, 4.96508640e-02],
[9.79823354e-01, 3.32737771e-03, 1.68492686e-02],
[9.98509253e-01, 1.93370119e-04, 1.29737734e-03],
[9.79823354e-01, 3.32737771e-03, 1.68492686e-02],
[9.07235027e-01, 1.76133118e-02, 7.51516615e-02],
[9.99399734e-01, 7.14676829e-05, 5.28798601e-04],
[9.85595436e-01, 2.30357815e-03, 1.21009863e-02],
[9.90829578e-01, 1.40724538e-03, 7.76317677e-03],
[6.87456097e-01, 6.73673912e-02, 2.45176512e-01],
[9.97650756e-01, 3.17942955e-04, 2.03130121e-03],
[9.71799414e-01, 4.79491595e-03, 2.34056702e-02],
[9.99327459e-01, 8.09397098e-05, 5.91601522e-04],
[9.16440769e-01, 1.57087730e-02, 6.78504582e-02],
[9.99619038e-01, 4.34381771e-05, 3.37523498e-04],
[1.97772093e-01, 2.06515863e-01, 5.95712044e-01],
[9.98812506e-01, 1.50783751e-04, 1.03671027e-03],
[9.77434756e-01, 3.75945979e-03, 1.88057838e-02],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99619038e-01, 4.34381771e-05, 3.37523498e-04],
[6.62242915e-01, 7.35030621e-02, 2.64254023e-01],
[9.77434756e-01, 3.75945979e-03, 1.88057838e-02],
[9.60705250e-01, 6.88722989e-03, 3.24075197e-02],
[9.99877665e-01, 1.25069220e-05, 1.09827836e-04],
[7.34596951e-01, 5.61160615e-02, 2.09286988e-01],
[9.99930645e-01, 6.71052818e-06, 6.26445753e-05],
[8.46438601e-01, 3.06290427e-02, 1.22932356e-01],
[9.88503728e-01, 1.80100898e-03, 9.69526338e-03],
[9.32396091e-01, 1.24586679e-02, 5.51452412e-02],
[9.99327459e-01, 8.09397098e-05, 5.91601522e-04],
[9.97650756e-01, 3.17942955e-04, 2.03130121e-03],
[9.99729087e-01, 2.98998736e-05, 2.41013096e-04],
[8.60765593e-01, 2.75004317e-02, 1.11733975e-01],
[9.97650756e-01, 3.17942955e-04, 2.03130121e-03],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99399734e-01, 7.14676829e-05, 5.28798601e-04],
[8.14181518e-01, 3.77942648e-02, 1.48024217e-01],
[9.99784150e-01, 2.33091572e-05, 1.92541244e-04],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99659963e-01, 3.83535901e-05, 3.01683390e-04],
[7.76917396e-01, 4.62643226e-02, 1.76818281e-01],
[9.99977688e-01, 1.93171761e-06, 2.03798022e-05],
[9.74770157e-01, 4.24642287e-03, 2.09834203e-02],
[9.77434756e-01, 3.75945979e-03, 1.88057838e-02],
[3.33380066e-02, 2.89164505e-01, 6.77497488e-01],
[9.99784150e-01, 2.33091572e-05, 1.92541244e-04],
[5.24525805e-01, 1.08510489e-01, 3.66963706e-01],
[9.07235027e-01, 1.76133118e-02, 7.51516615e-02],
[9.98509253e-01, 1.93370119e-04, 1.29737734e-03],
[9.99521805e-01, 5.57180676e-05, 4.22476497e-04],
[7.11601582e-01, 6.15684636e-02, 2.26829954e-01],
[9.99922311e-01, 7.60039974e-06, 7.00890612e-05],
[4.95769837e-01, 1.16163131e-01, 3.88067032e-01],
[9.99155737e-01, 1.03813470e-04, 7.40449484e-04],
[9.99862956e-01, 1.41653531e-05, 1.22878650e-04],
[9.98329720e-01, 2.18975043e-04, 1.45130473e-03],
[8.60765593e-01, 2.75004317e-02, 1.11733975e-01],
[9.99464237e-01, 6.31036357e-05, 4.72659002e-04],
[9.98940147e-01, 1.33145560e-04, 9.26707128e-04],
[9.94796445e-01, 7.58033402e-04, 4.44552206e-03],
[9.89731718e-01, 1.59210500e-03, 8.67617683e-03],
[9.99729087e-01, 2.98998736e-05, 2.41013096e-04],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99960669e-01, 3.60041859e-06, 3.57309482e-05],
[9.77434756e-01, 3.75945979e-03, 1.88057838e-02],
[9.99521805e-01, 5.57180676e-05, 4.22476497e-04],
[9.16440769e-01, 1.57087730e-02, 6.78504582e-02],
[9.95853432e-01, 5.91538266e-04, 3.55502929e-03],
[9.51091028e-01, 8.74667922e-03, 4.01622930e-02],
[9.99985821e-01, 1.17385315e-06, 1.30053464e-05],
[4.10381095e-01, 1.39709393e-01, 4.49909512e-01],
[9.99877665e-01, 1.25069220e-05, 1.09827836e-04],
[8.97126806e-01, 1.97268797e-02, 8.31463146e-02],
[9.97367925e-01, 3.60005733e-04, 2.27206934e-03],
[9.97051092e-01, 4.07619342e-04, 2.54128862e-03],
[9.96696188e-01, 4.61512552e-04, 2.84229904e-03],
[9.74770157e-01, 4.24642287e-03, 2.09834203e-02],
[9.92687793e-01, 1.09904848e-03, 6.21315814e-03],
[9.95354809e-01, 6.69651256e-04, 3.97553948e-03],
[9.95853432e-01, 5.91538266e-04, 3.55502929e-03],
[4.10381095e-01, 1.39709393e-01, 4.49909512e-01],
[9.95853432e-01, 5.91538266e-04, 3.55502929e-03],
[4.16744871e-02, 2.81779191e-01, 6.76546322e-01],
[9.74770157e-01, 4.24642287e-03, 2.09834203e-02],
[6.87456097e-01, 6.73673912e-02, 2.45176512e-01],
[9.77434756e-01, 3.75945979e-03, 1.88057838e-02],
[5.53113537e-01, 1.01026614e-01, 3.45859849e-01],
[9.92687793e-01, 1.09904848e-03, 6.21315814e-03],
[9.98329720e-01, 2.18975043e-04, 1.45130473e-03],
[9.99729087e-01, 2.98998736e-05, 2.41013096e-04],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99521805e-01, 5.57180676e-05, 4.22476497e-04],
[9.97367925e-01, 3.60005733e-04, 2.27206934e-03],
[9.56149314e-01, 7.76360593e-03, 3.60870798e-02],
[8.46438601e-01, 3.06290427e-02, 1.22932356e-01],
[9.99846476e-01, 1.60436654e-05, 1.37480045e-04],
[9.32396091e-01, 1.24586679e-02, 5.51452412e-02],
[9.90829578e-01, 1.40724538e-03, 7.76317677e-03],
[8.30923598e-01, 3.40551192e-02, 1.35021283e-01],
[9.88503728e-01, 1.80100898e-03, 9.69526338e-03],
[1.97772093e-01, 2.06515863e-01, 5.95712044e-01],
[9.93471306e-01, 9.71127263e-04, 5.55756640e-03],
[4.38511077e-01, 1.31806090e-01, 4.29682833e-01],
[9.99054066e-01, 1.17569011e-04, 8.28364796e-04],
[9.97903222e-01, 2.80786191e-04, 1.81599154e-03],
[9.95853432e-01, 5.91538266e-04, 3.55502929e-03],
[8.86053128e-01, 2.20672226e-02, 9.18796490e-02],
[9.99758182e-01, 2.63996787e-05, 2.15418445e-04],
[9.56149314e-01, 7.76360593e-03, 3.60870798e-02],
[9.98812506e-01, 1.50783751e-04, 1.03671027e-03],
[9.74770157e-01, 4.24642287e-03, 2.09834203e-02],
[9.56149314e-01, 7.76360593e-03, 3.60870798e-02],
[9.32396091e-01, 1.24586679e-02, 5.51452412e-02],
[9.99995431e-01, 3.37897086e-07, 4.23079675e-06],
[9.24807084e-01, 1.39960557e-02, 6.11968599e-02],
[9.98329720e-01, 2.18975043e-04, 1.45130473e-03],
[9.88503728e-01, 1.80100898e-03, 9.69526338e-03],
[9.85595436e-01, 2.30357815e-03, 1.21009863e-02],
[9.99246476e-01, 9.16663201e-05, 6.61857479e-04],
[9.99619038e-01, 4.34381771e-05, 3.37523498e-04],
[9.97051092e-01, 4.07619342e-04, 2.54128862e-03],
[9.99619038e-01, 4.34381771e-05, 3.37523498e-04],
[8.30923598e-01, 3.40551192e-02, 1.35021283e-01],
[1.50734727e-02, 3.12609464e-01, 6.72317064e-01],
[2.56853183e-04, 4.16285225e-01, 5.83457921e-01],
[5.56740091e-05, 4.55451451e-01, 5.44492875e-01],
[5.19773563e-02, 2.73959359e-01, 6.74063285e-01],
[1.06517664e-05, 4.98170638e-01, 5.01818711e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[2.37725245e-02, 2.99592341e-01, 6.76635134e-01],
[5.56740091e-05, 4.55451451e-01, 5.44492875e-01],
[2.66195596e-02, 2.96191724e-01, 6.77188717e-01],
[5.56740091e-05, 4.55451451e-01, 5.44492875e-01],
[1.34421366e-02, 3.15747889e-01, 6.70809975e-01],
[3.47353090e-05, 4.67621164e-01, 5.32344100e-01],
[8.48492539e-03, 3.27984696e-01, 6.63530379e-01],
[2.43746285e-05, 4.76772336e-01, 5.23203290e-01],
[2.97962369e-02, 2.92718468e-01, 6.77485295e-01],
[1.42765442e-04, 4.31266665e-01, 5.68590569e-01],
[1.80592146e-04, 4.25260411e-01, 5.74558997e-01],
[1.90487199e-08, 6.54997778e-01, 3.45002203e-01],
[1.68988576e-02, 3.09430272e-01, 6.73670870e-01],
[6.55949478e-04, 3.92563248e-01, 6.06780802e-01],
[6.36066614e-01, 7.99602349e-02, 2.83973151e-01],
[1.48639418e-03, 3.72040137e-01, 6.26473469e-01],
[4.10381095e-01, 1.39709393e-01, 4.49909512e-01],
[1.26928742e-04, 4.34276293e-01, 5.65596779e-01],
[1.19848187e-02, 3.18850405e-01, 6.69164777e-01],
[2.43746285e-05, 4.76772336e-01, 5.23203290e-01],
[1.42765442e-04, 4.31266665e-01, 5.68590569e-01],
[4.61649723e-04, 4.01422652e-01, 5.98115698e-01],
[1.68988576e-02, 3.09430272e-01, 6.73670870e-01],
[9.46230292e-06, 5.01229574e-01, 4.98760964e-01],
[9.07235027e-01, 1.76133118e-02, 7.51516615e-02],
[1.79614722e-06, 5.43937084e-01, 4.56061119e-01],
[6.09053113e-01, 8.67181448e-02, 3.04228742e-01],
[7.92758219e-05, 4.46354890e-01, 5.53565834e-01],
[3.65186708e-04, 4.07353037e-01, 5.92281776e-01],
[4.75835460e-03, 3.42830226e-01, 6.52411420e-01],
[4.23717382e-03, 3.45765718e-01, 6.49997109e-01],
[2.43746285e-05, 4.76772336e-01, 5.23203290e-01],
[9.52169712e-03, 3.24964983e-01, 6.65513320e-01],
[4.12636088e-06, 5.22625381e-01, 4.77370493e-01],
[8.28856143e-04, 3.86679999e-01, 6.12491145e-01],
[2.12226872e-02, 3.02927797e-01, 6.75849516e-01],
[8.91806163e-05, 4.43329533e-01, 5.56581286e-01],
[4.65562644e-02, 2.77928722e-01, 6.75515014e-01],
[8.91806163e-05, 4.43329533e-01, 5.56581286e-01],
[1.00319096e-04, 4.40307875e-01, 5.59591806e-01],
[2.28405596e-04, 4.19272265e-01, 5.80499329e-01],
[8.28856143e-04, 3.86679999e-01, 6.12491145e-01],
[4.39789310e-05, 4.61531090e-01, 5.38424931e-01],
[3.24779965e-04, 4.10325566e-01, 5.89349654e-01],
[2.36934680e-03, 3.60371994e-01, 6.37258659e-01],
[4.94830887e-05, 4.58489869e-01, 5.41460648e-01],
[3.72834685e-02, 2.85521169e-01, 6.77195363e-01],
[1.12844430e-04, 4.37290078e-01, 5.62597078e-01],
[6.09053113e-01, 8.67181448e-02, 3.04228742e-01],
[1.92442390e-05, 4.82881408e-01, 5.17099348e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[5.83494391e-04, 3.95511652e-01, 6.03904853e-01],
[2.03100660e-04, 4.22264023e-01, 5.77532876e-01],
[4.16744871e-02, 2.81779191e-01, 6.76546322e-01],
[2.74303974e-05, 4.73720077e-01, 5.26252492e-01],
[1.06834381e-02, 3.21921431e-01, 6.67395131e-01],
[3.72834685e-02, 2.85521169e-01, 6.77195363e-01],
[2.66519367e-07, 5.91928306e-01, 4.08071428e-01],
[3.30018182e-01, 1.63239846e-01, 5.06741972e-01],
[4.10603666e-04, 4.04385402e-01, 5.95203995e-01],
[1.00319096e-04, 4.40307875e-01, 5.59591806e-01],
[2.03100660e-04, 4.22264023e-01, 5.77532876e-01],
[2.37725245e-02, 2.99592341e-01, 6.76635134e-01],
[2.56853183e-04, 4.16285225e-01, 5.83457921e-01],
[1.17689631e-03, 3.77885911e-01, 6.20937193e-01],
[2.56853183e-04, 4.16285225e-01, 5.83457921e-01],
[4.23717382e-03, 3.45765718e-01, 6.49997109e-01],
[1.50734727e-02, 3.12609464e-01, 6.72317064e-01],
[5.19773563e-02, 2.73959359e-01, 6.74063285e-01],
[1.19848187e-02, 3.18850405e-01, 6.69164777e-01],
[3.82818908e-01, 1.47609731e-01, 4.69571361e-01],
[1.06834381e-02, 3.21921431e-01, 6.67395131e-01],
[9.07235027e-01, 1.76133118e-02, 7.51516615e-02],
[8.28856143e-04, 3.86679999e-01, 6.12491145e-01],
[4.65562644e-02, 2.77928722e-01, 6.75515014e-01],
[1.67030730e-03, 3.69121063e-01, 6.29208630e-01],
[3.33380066e-02, 2.89164505e-01, 6.77497488e-01],
[5.83494391e-04, 3.95511652e-01, 6.03904853e-01],
[7.34596951e-01, 5.61160615e-02, 2.09286988e-01],
[6.55949478e-04, 3.92563248e-01, 6.06780802e-01],
[2.12226872e-02, 3.02927797e-01, 6.75849516e-01],
[1.17689631e-03, 3.77885911e-01, 6.20937193e-01],
[2.03100660e-04, 4.22264023e-01, 5.77532876e-01],
[7.20105181e-02, 2.61226867e-01, 6.66762615e-01],
[1.50734727e-02, 3.12609464e-01, 6.72317064e-01],
[1.89404443e-02, 3.06204991e-01, 6.74854565e-01],
[4.95769837e-01, 1.16163131e-01, 3.88067032e-01],
[2.37725245e-02, 2.99592341e-01, 6.76635134e-01],
[3.35891584e-03, 3.51618302e-01, 6.45022782e-01],
[2.10884632e-03, 3.63287690e-01, 6.34603464e-01],
[2.56853183e-04, 4.16285225e-01, 5.83457921e-01],
[5.99911028e-03, 3.36932145e-01, 6.57068745e-01],
[5.24525805e-01, 1.08510489e-01, 3.66963706e-01],
[7.20105181e-02, 2.61226867e-01, 6.66762615e-01],
[2.76706867e-09, 6.97794537e-01, 3.02205460e-01],
[7.37368695e-04, 3.89619418e-01, 6.09643213e-01],
[1.67030730e-03, 3.69121063e-01, 6.29208630e-01],
[5.81347935e-01, 9.37506515e-02, 3.24901414e-01],
[1.48457761e-01, 2.25237845e-01, 6.26304393e-01],
[2.16726718e-01, 1.99810134e-01, 5.83463148e-01],
[1.17689631e-03, 3.77885911e-01, 6.20937193e-01],
[5.53113537e-01, 1.01026614e-01, 3.45859849e-01],
[4.10603666e-04, 4.04385402e-01, 5.95203995e-01],
[5.79896156e-02, 2.69860198e-01, 6.72150186e-01],
[4.10603666e-04, 4.04385402e-01, 5.95203995e-01],
[1.42765442e-04, 4.31266665e-01, 5.68590569e-01],
[3.05043407e-01, 1.70896552e-01, 5.24060040e-01],
[4.65562644e-02, 2.77928722e-01, 6.75515014e-01],
[1.42765442e-04, 4.31266665e-01, 5.68590569e-01],
[8.90909626e-02, 2.51935204e-01, 6.58973834e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[1.34421366e-02, 3.15747889e-01, 6.70809975e-01],
[1.48639418e-03, 3.72040137e-01, 6.26473469e-01],
[7.20105181e-02, 2.61226867e-01, 6.66762615e-01],
[2.28405596e-04, 4.19272265e-01, 5.80499329e-01],
[1.50734727e-02, 3.12609464e-01, 6.72317064e-01],
[8.01374021e-02, 2.56669234e-01, 6.63193364e-01],
[2.58445525e-01, 1.85740827e-01, 5.55813648e-01],
[4.65562644e-02, 2.77928722e-01, 6.75515014e-01],
[4.10381095e-01, 1.39709393e-01, 4.49909512e-01],
[1.60571852e-04, 4.28261330e-01, 5.71578098e-01],
[5.79896156e-02, 2.69860198e-01, 6.72150186e-01],
[2.12226872e-02, 3.02927797e-01, 6.75849516e-01],
[3.72834685e-02, 2.85521169e-01, 6.77195363e-01],
[1.59468037e-06, 5.46970287e-01, 4.53028118e-01],
[3.33380066e-02, 2.89164505e-01, 6.77497488e-01],
[3.24779965e-04, 4.10325566e-01, 5.89349654e-01],
[4.61649723e-04, 4.01422652e-01, 5.98115698e-01],
[3.30018182e-01, 1.63239846e-01, 5.06741972e-01],
[1.12844430e-04, 4.37290078e-01, 5.62597078e-01],
[3.77273387e-03, 3.48694560e-01, 6.47532706e-01],
[1.68988576e-02, 3.09430272e-01, 6.73670870e-01],
[2.10884632e-03, 3.63287690e-01, 6.34603464e-01],
[1.50734727e-02, 3.12609464e-01, 6.72317064e-01],
[1.68988576e-02, 3.09430272e-01, 6.73670870e-01],
[1.32265821e-03, 3.74961590e-01, 6.23715752e-01],
[4.75835460e-03, 3.42830226e-01, 6.52411420e-01],
[7.04684142e-05, 4.49383779e-01, 5.50545752e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[7.37368695e-04, 3.89619418e-01, 6.09643213e-01],
[1.34965344e-05, 4.92053195e-01, 5.07933308e-01],
[5.34311805e-03, 3.39886348e-01, 6.54770534e-01],
[2.56853183e-04, 4.16285225e-01, 5.83457921e-01],
[8.90909626e-02, 2.51935204e-01, 6.58973834e-01],
[1.00319096e-04, 4.40307875e-01, 5.59591806e-01],
[3.55983968e-01, 1.55465990e-01, 4.88550042e-01],
[5.56740091e-05, 4.55451451e-01, 5.44492875e-01],
[4.75835460e-03, 3.42830226e-01, 6.52411420e-01],
[2.16584589e-05, 4.79826183e-01, 5.20152158e-01],
[4.75835460e-03, 3.42830226e-01, 6.52411420e-01],
[1.92442390e-05, 4.82881408e-01, 5.17099348e-01],
[4.65562644e-02, 2.77928722e-01, 6.75515014e-01],
[4.61649723e-04, 4.01422652e-01, 5.98115698e-01],
[1.34435539e-01, 2.31012723e-01, 6.34551738e-01],
[1.00319096e-04, 4.40307875e-01, 5.59591806e-01],
[5.19019850e-04, 3.98464756e-01, 6.01016224e-01],
[9.52169712e-03, 3.24964983e-01, 6.65513320e-01],
[1.67030730e-03, 3.69121063e-01, 6.29208630e-01],
[7.04684142e-05, 4.49383779e-01, 5.50545752e-01],
[1.48639418e-03, 3.72040137e-01, 6.26473469e-01],
[2.36486122e-07, 5.94879966e-01, 4.05119797e-01],
[6.73487116e-03, 3.33965453e-01, 6.59299676e-01],
[7.37368695e-04, 3.89619418e-01, 6.09643213e-01],
[1.06834381e-02, 3.21921431e-01, 6.67395131e-01],
[7.96184325e-01, 4.18602324e-02, 1.61955443e-01],
[4.64628626e-06, 5.19572196e-01, 4.80423157e-01],
[3.82818908e-01, 1.47609731e-01, 4.69571361e-01],
[2.36934680e-03, 3.60371994e-01, 6.37258659e-01],
[1.42765442e-04, 4.31266665e-01, 5.68590569e-01],
[3.24779965e-04, 4.10325566e-01, 5.89349654e-01],
[3.30018182e-01, 1.63239846e-01, 5.06741972e-01],
[4.39789310e-05, 4.61531090e-01, 5.38424931e-01],
[2.12226872e-02, 3.02927797e-01, 6.75849516e-01],
[6.14821506e-07, 5.71091816e-01, 4.28907569e-01],
[1.04714425e-03, 3.80813522e-01, 6.18139334e-01],
[6.73487116e-03, 3.33965453e-01, 6.59299676e-01],
[1.06834381e-02, 3.21921431e-01, 6.67395131e-01],
[1.60571852e-04, 4.28261330e-01, 5.71578098e-01],
[6.46480424e-02, 2.65619915e-01, 6.69732042e-01],
[2.88832350e-04, 4.13302974e-01, 5.86408194e-01]])
clf2 = LogisticRegression()
clf2.fit(df[["bill_length_mm","flipper_length_mm"]], df["species"])
LogisticRegression()
clf2.score(df[["bill_length_mm","flipper_length_mm"]], df["species"])
0.9579579579579579
clf2.predict(df[["bill_length_mm","flipper_length_mm"]])
array(['Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Chinstrap', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Chinstrap', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Gentoo',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Chinstrap', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Gentoo', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie', 'Adelie',
'Adelie', 'Adelie', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Adelie', 'Chinstrap', 'Adelie',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Adelie', 'Chinstrap', 'Adelie',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Gentoo', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Gentoo',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Adelie', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Chinstrap', 'Adelie', 'Chinstrap', 'Chinstrap', 'Chinstrap',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Chinstrap', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo',
'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo', 'Gentoo'], dtype=object)
clf2.predict(df[["bill_length_mm","flipper_length_mm"]]) == df["species"]
0 True
1 True
2 True
4 True
5 True
...
338 True
340 True
341 True
342 True
343 True
Name: species, Length: 333, dtype: bool
(clf2.predict(df[["bill_length_mm","flipper_length_mm"]]) == df["species"]).mean()
0.9579579579579579