本次实验数据集为 Breast cancer dataset
通过sklearn.datasets获取数据
cancer = load_breast_cancer()
cancer_x=cancer.data
cancer_y=cancer.target
查看数据大小即部分数据:
print("加载完毕,数据大小:")
print(cancer_x.shape)
print(cancer_y.shape)
print("前5个数据:")
for i in range(5):
print(cancer_x[i],cancer_y[i])

breast cancer 的影响因素有30个,结果为0,1,表示是否患病
对数据进行拆分, test_size=0.2:
x_train,x_test,y_train, y_test=train_test_split(cancer_x,cancer_y,test_size=0.3)
用到 logistic regression 算法
logistic sigmoid function


函数图形,结果若大于0.5,归类为1,若小于0.5,归类为0

the likelihood function

the error function

用梯度下降算法求出误差最小的w
LogisticRegression
模型判断准确率为0.974左右,准确率很高,说明LogisticRegression模型效果很好