<jupyter_start><jupyter_text>scikit-plotabs 패키지1.confusion plot2.roc-curve3.mlxtend<jupyter_code>fpr1, tpr1, thresholds1 = roc_curve(y, model1.decision_function(X))
fpr2, tpr2, thresholds1 = roc_curve(y, model2.decision_function(X))

plt.plot(fpr1, tpr1, 'o-', ms=2, label="Logistic Regression")
plt.plot(fpr2, tpr2, 'o-', ms=2, label="Kernel SVM")
plt.legend()
plt.plot([0, 1], [0, 1], 'k--', label="random guess")
plt.show()
from sklearn.datasets import load_iris
iris = load_iris()
iris
X = iris.data
y = iris.target
dfX = pd.DataFrame(X, columns = iris.feature_names)
dfy = pd.DataFrame(y, columns = ["species"])
df = pd.concat([dfX,dfy], axis = 1)
df = df[["sepal length (cm)", "species"]]
df = df[df.species.isin([0,1])]
df = df.rename(columns = {"sepal length (cm)": "sepal_length"})
df
import statsmodels.api as sm
model = sm.Logit.from_formula("species ~ sepal_length", data = df)
result = model.fit()
print(result.summary())
y_pred = result.predict(df.sepal_length) >= 0.5
plt.plot(y_pred, "o")

from sklearn.metrics import confusion_matrix, classification_report

confusion_matrix(df.species, y_pred)
from sklearn.metrics import classification_report

print(classification_report(df.species, y_pred))
from sklearn.metrics import roc_curve

fpr, tpr, thresholds = roc_curve(df.species, result.predict(df.sepal_length) )
plt.plot(fpr, tpr)
plt.show()
from sklearn.metrics import auc
auc(fpr, tpr)
plt.show()
iris
X = iris.data
y = iris.target
dfX = pd.DataFrame(X, columns = iris.feature_names)
dfy = pd.DataFrame(y, columns = ["species"])
df = pd.concat([dfX,dfy], axis = 1)
#df = df[["sepal length (cm)", "species"]]
df = df[df.species.isin([1,2])]
df["species"] -= 1
df = df.rename(columns = {"sepal length (cm)": "sepal_length", "sepal width (cm)":"sepal_width", "petal length (cm)":"petal_length", "petal width (cm)":"petal_width"})
df
import statsmodels.api as sm
model = sm.Logit.from_formula("species ~ sepal_length + sepal_width + petal_length + petal_width", data = df)
result = model.fit()
print(result.summary())
df.columns
y_pred = result.predict(df) >= 0.5
plt.plot(y_pred, "o")

from sklearn.metrics import confusion_matrix, classification_report

confusion_matrix(df.species, y_pred)
from sklearn.metrics import classification_report

print(classification_report(df.species, y_pred))
from sklearn.metrics import roc_curve

fpr, tpr, thresholds = roc_curve(df.species, result.predict(df) )
plt.plot(fpr, tpr)
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup