基于逻辑回归实现乳腺癌预测
将乳腺癌数据集拆分成训练集和测试集,搭建一个逻辑回归模型,对训练集进行训练,然后分别对训练集和测试集进行预测。输出以下结果:
该模型在训练集上的准确率,在测试集上的准确率、召回率和精确率。文章来源:https://www.toymoban.com/news/detail-838464.html
源码
from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import recall_score,precision_score,classification_report,accuracy_score
cancer = load_breast_cancer()
x_train,x_test,y_train,y_test = train_test_split(cancer.data,cancer.target,test_size=0.2)
model = LogisticRegression(max_iter=10000)
model.fit(x_train,y_train)
train_score = model.score(x_train,y_train)
test_score = model.score(x_test,y_test)
print("1 基于逻辑回归实现乳腺癌预测")
print("李思强 20201107148")
print("训练集")
print("准确率:",train_score)
y_pred = model.predict(x_test)
accuracy_score_value = accuracy_score(y_test,y_pred)
recall_score_value = recall_score(y_test,y_pred)
precision_score_value = precision_score(y_test,y_pred)
print("测试集")
print("准确率:",accuracy_score_value)
print("召回率:",recall_score_value)
print("精确率:",precision_score_value)
运行结果
文章来源地址https://www.toymoban.com/news/detail-838464.html
到了这里,关于基于逻辑回归实现乳腺癌预测(机械学习与大数据)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!