逻辑回归 Sigmoid 预测疝气病死马率

逻辑回归 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=['真实'])

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。