学习笔记 Day 44(模型保存,逻辑回归,聚类算法)

博客探讨了逻辑回归模型的训练、保存和加载过程,包括数据预处理、模型构建和评估。同时,介绍了k-means聚类算法,详细阐述了其非监督学习的过程,并讨论了评估标准和实际效果。

模型保存和加载:

分类算法 -- 逻辑回归:

代码实现:

def logitic():

    # 构造列标签名字
    column = ['Sample code number','Clump Thickness', 'Uniformity of Cell Size','Uniformity of Cell Shape','Marginal Adhesion', 'Single Epithelial Cell Size','Bare Nuclei','Bland Chromatin','Normal Nucleoli','Mitoses','Class']

    # 获取数据
    df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data',names=column)

    # print(df.head())
    # 数据处理
    df = df.replace(to_replace='?',value=np.nan)

    df = df.dropna()


    print(df)
    # 分割数据集
    x_train,x_test,y_train,y_test = train_test_split(df.iloc[:,1:10],df.iloc[:,-1],test_size=0.2,random_state=22)

    # 标准化
    scaler = StandardScaler()

    x_train = scaler.fit_transform(x_train)
    x_test = scaler.transform(x_test)

    # 机器学习
    estimator = LogisticRegression()

    estimator.fit(x_train,y_train)

    print(estimator.coef_)

    y_pre = estimator.predict(x_test)

    print('查全率为:\n',classification_report(y_test,y_pre,labels=[2,4],target_names=['良性','恶性']))

判别模型和生成模型:

k-means:非监督学习

过程:

 

评估标准:

 

效果:

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

happydog007

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值