import numpy as np
import pandas as pd
from sklearn import linear_model
#X represents the size of a tumor in centimeters.
X = np.array([3.78, 2.44, 2.09, 0.14, 1.72, 1.65, 4.92, 4.37, 4.96, 4.52, 3.69, 5.88]).r
#Note: X has to be reshaped into a column from a row for the LogisticRegression() functi
#y represents whether or not the tumor is cancerous (@ for "No", 1 for "Yes").
y = np.array([0,0,0,0,0, 0, 1, 1, 1, 1, 1, 1])
In [3]:
X
Out[3]:
array([[3.78],
[2.44],
[2.09],
[e.14],
[1.72],
[1.65],
[4.92],
[4.37],
[4.96],
[4.52],
[3.69],
[5.88]1)
In [4]: |
y
out[4]:
array([0, ©, ©, 0, 0, 0, 1, 1, 1, 1, 1, 1])
In [5]: M
logr = linear_model.LogisticRegression()
logr.fit(X,y)
Out[5]:
LogisticRegression()
In [6]:
#predict if tumor is cancerous where the size is 3.46mm:
predicted = logr.predict(np.array([3.46]).reshape(-1,1))
predicted
out[6]:
array([0])