【阿里天池-医学影像报告异常检测】4 机器学习模型调参

简介: 本文提供了对医学影像报告异常检测任务中使用的机器学习模型(如XGBoost和LightGBM)进行参数调整的方法,并分享了特征提取和模型调优的最佳实践。

引言

(1)先对idtdf提取特征的ngram大小和feature调参,最终ngram=(1,2)feature=500,最佳
(2)对LogisticRegression、XGBClassifier、LGBMClassifier三个模型单独调参,本人仅仅对XGB的几个参数进行了调整,工作量太庞大,就没有所有参数调整对比分析。这里仅仅提出调参的例子,提供模型调参的思路学习
(3)开源源码https://github.com/823316627bandeng/TIANCHI-2021-AI-Compition

实现

(1)导入包

import os
import numpy as np
import pandas as pd
from sklearn.decomposition import NMF, TruncatedSVD, PCA
from sklearn.linear_model import LogisticRegression
from sklearn.multiclass import OneVsRestClassifier
from sklearn.preprocessing import StandardScaler
from xgboost import XGBClassifier
from utils import *
from lightgbm import LGBMClassifier
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics import roc_auc_score
#加载数据
label= np.array(pd.read_csv('./data/label.csv'))
train = pd.read_csv('./temp/train.csv',header = None,names=['id','text','label'])
adjust_model()
AI 代码解读

(2)模型的调参

def adjust_model():
    Tdf = TfidfVectorizer(ngram_range=(1,2),max_features=500)
    tdf_data = Tdf.fit_transform(train['text'])
    X_train,X_test,y_train,y_test = train_test_split(tdf_data,label,test_size=0.3)
    paralist = []
    score_dict = {"list_n":[],"list_f":[],"loss":[]}
    # for n in paralist
    param_test1 = {'estimator__max_depth':range(2,8,2)}
    '''
    model = OneVsRestClassifier(XGBClassifier(eval_metric= 'mlogloss',
                                            max_depth = 11,
                                            min_child_weight =1,
                                            use_label_encoder=False,
                                            learning_rate =0.01,
                                            n_estimators=150,
                                            gamma=0,
                                            subsample=0.8,
                                            colsample_bytree=0.8,
                                            nthread=100,
                                            scale_pos_weight=1,
                                            seed=27,
                                            verbose=True
                                            ))
    '''
    '''
    model = OneVsRestClassifier(LGBMClassifier(is_unbalance = True,
                                                metric = 'binary_logloss,auc',
                                                # max_depth = 6,
                                                num_leaves = 40,
                                                learning_rate = 0.1,
                                                feature_fraction = 0.7,
                                                min_child_samples=21,
                                                min_child_weight=0.001,
                                                bagging_fraction = 1,
                                                bagging_freq = 2,
                                                reg_alpha = 0.001,
                                                reg_lambda = 8,
                                                cat_smooth = 0,
                                                # num_iterations = 200
                                                ))
    '''
    # model = OneVsRestClassifier(LGBMClassifier())
    model = OneVsRestClassifier(XGBClassifier(eval_metric= 'mlogloss',use_label_encoder=False,n_estimators=150))
    model.fit(X_train, y_train)

    predict = model.predict_proba(X_test)
    score = roc_auc_score(y_test,predict)
    print(score)
AI 代码解读

XGB
{‘estimator__max_depth’: 9, ‘estimator__min_child_weight’: 1}
{‘estimator__max_depth’: 11}0.9812110365828264
{‘estimator__n_estimators’: 150} 0.9834881407453535
调参后:0.9726861215062805
LGB
{‘estimator__max_depth’: 6}最佳得分 0.9811430144134826

(3)idtdf提取特征调参

#list_ngram = [1,2,3,4]
#list_feature = [100,200,300,400]
def adjust_idtdf():
    list_ngram = [1,2,3,4,5]
    list_feature = [100,200,300,400,500]
    #分数记录字典
    score_dict = {"list_n":[],"list_f":[],"loss":[]}
    #创建方法进行验证
    def para_Tdf(data_x):
        for n in list_ngram:
            for fea in list_feature:
                Tdf = TfidfVectorizer(ngram_range=(1,n),max_features=fea)
                tdf_data = Tdf.fit_transform(data_x)
                # tdf_data = tdf_data.toarray()
                X_train,X_test,y_train,y_test = train_test_split(tdf_data,label,test_size=0.3)
                model = OneVsRestClassifier(XGBClassifier(eval_metric= 'mlogloss',use_label_encoder=False,n_estimators=50))
                model.fit(X_train, y_train)
                predict = model.predict_proba(X_test)
                loss = Mutilogloss(y_test,predict)
                score_dict["list_n"].append(n)
                score_dict['list_f'].append(fea)
                score_dict['loss'].append(loss)
                print("n={0},feature={1},loss={2}".format(n,fea,loss))
    #方法调用
    para_Tdf(train['text'])
    #以DataFrame形式显示分数
    print(score_dict)
AI 代码解读

最佳是n=2,features = 500
n=1,feature=100,loss=0.09694388171340544
n=1,feature=200,loss=0.07941648607131963
n=1,feature=300,loss=0.0780516995282797
n=1,feature=400,loss=0.07654529189186797
n=1,feature=500,loss=0.07875673493941672
n=2,feature=100,loss=0.10700796997032506
n=2,feature=200,loss=0.0872626769884241
n=2,feature=300,loss=0.08134605319231948
n=2,feature=400,loss=0.07927331816025636
n=2,feature=500,loss=0.07391725763363112
n=3,feature=100,loss=0.10642417486808319
n=3,feature=200,loss=0.0932806660865527
n=3,feature=300,loss=0.0821267581008504
n=3,feature=400,loss=0.08258777666414407
n=3,feature=500,loss=0.07525704598697901
n=4,feature=100,loss=0.10395870861632356
n=4,feature=200,loss=0.09252871191998951
n=4,feature=300,loss=0.08208295772650118
n=4,feature=400,loss=0.08249975725295985
n=4,feature=500,loss=0.07920155662551372
n=5,feature=100,loss=0.10649166642764825
n=5,feature=200,loss=0.09238465463657325
n=5,feature=300,loss=0.08104836900458223
n=5,feature=400,loss=0.07833574743241475
n=5,feature=500,loss=0.07796380784547806

目录
打赏
0
10
13
0
156
分享
相关文章
【解决方案】DistilQwen2.5-R1蒸馏小模型在PAI-ModelGallery的训练、评测、压缩及部署实践
阿里云的人工智能平台 PAI,作为一站式的机器学习和深度学习平台,对DistilQwen2.5-R1模型系列提供了全面的技术支持。无论是开发者还是企业客户,都可以通过 PAI-ModelGallery 轻松实现 Qwen2.5 系列模型的训练、评测、压缩和快速部署。本文详细介绍在 PAI 平台使用 DistilQwen2.5-R1 蒸馏模型的全链路最佳实践。
【解决方案】DistilQwen2.5-DS3-0324蒸馏小模型在PAI-ModelGallery的训练、评测、压缩及部署实践
DistilQwen 系列是阿里云人工智能平台 PAI 推出的蒸馏语言模型系列,包括 DistilQwen2、DistilQwen2.5、DistilQwen2.5-R1 等。本文详细介绍DistilQwen2.5-DS3-0324蒸馏小模型在PAI-ModelGallery的训练、评测、压缩及部署实践。
PAI-Model Gallery云上一键部署阶跃星辰新模型Step1X-Edit
4月27日,阶跃星辰正式发布并开源图像编辑大模型 Step1X-Edit,性能达到开源 SOTA。Step1X-Edit模型总参数量为19B,实现 MLLM 与 DiT 的深度融合,在编辑精度与图像保真度上实现大幅提升,具备语义精准解析、身份一致性保持、高精度区域级控制三项关键能力;支持文字替换、风格迁移等11 类高频图像编辑任务类型。在最新发布的图像编辑基准 GEdit-Bench 中,Step1X-Edit 在语义一致性、图像质量与综合得分三项指标上全面领先现有开源模型,比肩 GPT-4o 与 Gemin。PAI-ModelGallery 支持Step1X-Edit一键部署方案。
基于PAI+专属网关+私网连接:构建全链路Deepseek云上私有化部署与模型调用架构
本文介绍了阿里云通过PAI+专属网关+私网连接方案,帮助企业实现DeepSeek-R1模型的私有化部署。方案解决了算力成本高、资源紧张、部署复杂和数据安全等问题,支持全链路零公网暴露及全球低延迟算力网络,最终实现技术可控、成本优化与安全可靠的AI部署路径,满足企业全球化业务需求。
PAI 重磅发布模型权重服务,大幅降低模型推理冷启动与扩容时长
阿里云人工智能平台PAI 平台推出模型权重服务,通过分布式缓存架构、RDMA高速传输、智能分片等技术,显著提升大语言模型部署效率,解决模型加载耗时过长的业界难题。实测显示,Qwen3-32B冷启动时间从953秒降至82秒(降幅91.4%),扩容时间缩短98.2%。
【新模型速递】PAI-Model Gallery云上一键部署MiniMax-M1模型
MiniMax公司6月17日推出4560亿参数大模型M1,采用混合专家架构和闪电注意力机制,支持百万级上下文处理,高效的计算特性使其特别适合需要处理长输入和广泛思考的复杂任务。阿里云PAI-ModelGallery现已接入该模型,提供一键部署、API调用等企业级解决方案,简化AI开发流程。
DistilQwen-ThoughtX 蒸馏模型在 PAI-ModelGallery 的训练、评测、压缩及部署实践
通过 PAI-ModelGallery,可一站式零代码完成 DistilQwen-ThoughtX 系列模型的训练、评测、压缩和部署。
PAI Model Gallery 支持云上一键部署 DeepSeek-V3、DeepSeek-R1 系列模型
DeepSeek 系列模型以其卓越性能在全球范围内备受瞩目,多次评测中表现优异,性能接近甚至超越国际顶尖闭源模型(如OpenAI的GPT-4、Claude-3.5-Sonnet等)。企业用户和开发者可使用 PAI 平台一键部署 DeepSeek 系列模型,实现 DeepSeek 系列模型与现有业务的高效融合。
阿里云PAI-全模态模型Qwen2.5-Omni-7B推理浅试
阿里云PAI-全模态模型Qwen2.5-Omni-7B推理浅试
348 12
【新模型速递】PAI一键云上零门槛部署DeepSeek-V3-0324、Qwen2.5-VL-32B
PAI-Model Gallery 集成国内外 AI 开源社区中优质的预训练模型,涵盖了 LLM、AIGC、CV、NLP 等各个领域,用户可以通过 PAI 以零代码方式实现从训练到部署再到推理的全过程,获得更快、更高效、更便捷的 AI 开发和应用体验。 现阿里云PAI-Model Gallery已同步接入DeepSeek-V3-0324、Qwen2.5-VL-32B-Instruct两大新模型,提供企业级部署方案。

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问