逻辑回归 Sigmoid
利用Logistics回归进行分类的主要思想是:根据现有数据对分类边界线建立回归公式,以此进行分类。这里的“回归” 一词源于最佳拟合,表示要找到最佳拟合参数
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
# 测试数据
test = pd.read_table('./data/horseColicTest.txt', header=None)
test.head()
X_test = test.iloc[:, :-1]
y_test = test.iloc[:, 21]
# 训练数据
train = pd.read_table('./data/horseColicTraining.txt', header=None)
X_train = train.iloc[:, :-1]
y_train = train[21]
from sklearn.linear_model import LogisticRegression
logistic = LogisticRegression()
logistic.fit(X_train, y_train)
y_ = logistic.predict(X_test)
logistic.score(X_train, y_train)
logistic.score(X_test, y_test)
pd.crosstab(index=y_, columns=y_test, rownames=['预测'],colnames=['真实'])