I’m trying to create a logistic regression similar to the ISLR’s example, but using python instead
JavaScript
x
16
16
1
data=pd.read_csv("data/Default.csv")
2
3
#first we'll have to convert the strings "No" and "Yes" to numeric values
4
data.loc[data["default"]=="No", "default"]=0
5
data.loc[data["default"]=="Yes", "default"]=1
6
X = data["balance"].values.reshape(-1,1)
7
Y = data["default"].values.reshape(-1,1)
8
9
LogR = LogisticRegression()
10
LogR.fit(X,np.ravel(Y.astype(int)))
11
12
#matplotlib scatter funcion w/ logistic regression
13
plt.scatter(X,Y)
14
plt.xlabel("Credit Balance")
15
plt.ylabel("Probability of Default")
16
But I keep getting the graph on the left, when I want the one on the right:
Edit: plt.scatter(x,LogR.predict(x))
was my second, and also wrong guess.
Advertisement
Answer
you use predict(X)
which gives out the prediction of the class.
replace predict(X)
with predict_proba(X)[:,1]
which would gives out the probability of which the data belong to class 1.