iOS AVAudioPlayer使用

本文详细介绍如何使用AVAudioPlayer实现音频播放功能,包括后台播放、输出改变监听、歌词同步显示及定时器管理等高级功能。
文章目录

   一、AVAudioPlayer

   1、简介

   2、优缺点

   3、如何使用

   4、扩展功能

  (1) 如何做后台播放

  (2) 如何做输出改变监听(拔出耳机音乐暂停播放)

  (3) 歌词轮播实现思路

  (4) 关于NSTimer(循环引用、NSRunLoopMode)

一、AVAudioPlayer

1、简介

  播放较大的音频或者要对音频有精确的,这种情况会选择使用AVFoundation.framework中的AVAudioPlayer来实现。

2、优缺点

缺点:AVAudioPlayer不支持加载网络媒体流,只能播放本地文件
优点:能够精确控制播放进度、音量、播放速度等属性

3、如何使用

(1) 初始化AVAudioPlayer对象,此时通常指定本地文件路径
(2) 设置播放器属性,例如重复次数、音量大小等
(3) 调用play方法播放

4、扩展功能

先上效果图
这里写图片描述
.
.
完整代码如下:



//
//  MainViewController.m
//  2.音乐播放
//
//  Created by cherish on 2018/4/8.
//  Copyright © 2018年 Cherish. All rights reserved.
//

#import "MainViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "SDAutoLayout.h"
#import "Configure.h"
#import "CustomSlider.h"
#import "TimerWeakTarget.h"

@interface MainViewController ()<AVAudioPlayerDelegate>

//播放器
@property (nonatomic,strong) AVAudioPlayer *audioPlayer;

//歌手名字
@property (nonatomic,strong) UILabel *singerName;

//下载
@property (nonatomic,strong) UIButton *downLoad;

//收藏
@property (nonatomic,strong) UIButton *collection;

//进度条
@property (nonatomic,strong) CustomSlider *progressView;

//上一首
@property (nonatomic,strong) UIButton *lastSong;

//播放或暂停
@property (nonatomic,strong) UIButton *playOrPause;

//下一首
@property (nonatomic,strong) UIButton *nextSong;

//定时器
@property (nonatomic,strong) NSTimer *timer;

//音乐总时长
@property (nonatomic,strong) UILabel *duration;

//播放时间
@property (nonatomic,strong) UILabel *playTime;

@end

@implementation MainViewController

#pragma mark - ViewController Life
- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = kMusicTitle;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:103/255.0 green:103/255.0 blue:103/255.0 alpha:1];

    [self setUI];


    self.duration.text = [self getMinuteSecondWithTime:self.audioPlayer.duration];

}


#pragma mark - Private Methods
- (void)setUI
{

    //背景图片
    UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    bgImageView.layer.masksToBounds = YES;
    bgImageView.userInteractionEnabled = YES;
    bgImageView.image = [UIImage imageNamed:@"bgImage"];
    [self.view addSubview:bgImageView];



    // 底部工具栏背景
    UILabel *panLable = [[UILabel alloc]initWithFrame:CGRectMake(0, KSCreenHeight-230, KSCreenWidth, 230)];
    panLable.backgroundColor = [UIColor colorWithRed:103/255.0 green:103/255.0 blue:103/255.0 alpha:1];
    panLable.userInteractionEnabled = YES;
    [bgImageView addSubview:panLable];


    //歌手名字
    self.singerName = [[UILabel alloc]init];
    self.singerName.font = [UIFont systemFontOfSize:16.0f];
    self.singerName.textAlignment = NSTextAlignmentCenter;
    self.singerName.textColor = [UIColor whiteColor];
    self.singerName.text = kMusicSinger;


    //下载按钮
    self.downLoad = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.downLoad setImage:[UIImage imageNamed:@"download"] forState:UIControlStateNormal];
    [self.downLoad addTarget:self action:@selector(downloadAction) forControlEvents:UIControlEventTouchUpInside];

    //收藏
    self.collection = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.collection setImage:[UIImage imageNamed:@"collection"] forState:UIControlStateNormal];
    [self.collection addTarget:self action:@selector(collectionAction) forControlEvents:UIControlEventTouchUpInside];



    //进度条
    self.progressView = [[CustomSlider alloc]init];
    self.progressView.value = 0.0;
    self.progressView.maximumTrackTintColor = [UIColor whiteColor];
    self.progressView.alpha = 0.5;
    //监听value变化
    [self.progressView addTarget:self action:@selector(progressValueChanged) forControlEvents:UIControlEventValueChanged];


    //播放时长
    self.playTime = [[UILabel alloc]init];
    self.playTime.textColor = [UIColor whiteColor];
    self.playTime.font = [UIFont systemFontOfSize:12.0f];
    self.playTime.textAlignment = NSTextAlignmentLeft;
    self.playTime.text = @"00:00";




    //总时长
    self.duration = [[UILabel alloc]init];
    self.duration.textColor = [UIColor whiteColor];
    self.duration.font = [UIFont systemFontOfSize:12.0f];
    self.duration.textAlignment = NSTextAlignmentRight;





    //播放按钮
    self.playOrPause = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playOrPause setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
    [self.playOrPause setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateSelected];
    [self.playOrPause addTarget:self action:@selector(playOrPauseAction:) forControlEvents:UIControlEventTouchUpInside];


    //上一首
    self.lastSong = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.lastSong setImage:[UIImage imageNamed:@"last"] forState:UIControlStateNormal];
    [self.lastSong addTarget:self action:@selector(lastSongAction:) forControlEvents:UIControlEventTouchUpInside];


    //下一首
    self.nextSong = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.nextSong setImage:[UIImage imageNamed:@"next"] forState:UIControlStateNormal];
    [self.nextSong addTarget:self action:@selector(nestSongAction:) forControlEvents:UIControlEventTouchUpInside];





    [panLable sd_addSubviews:@[self.singerName,self.downLoad,self.collection, self.progressView,self.playOrPause,self.lastSong,self.nextSong,self.duration,self.playTime]];


    self.singerName.sd_layout
    .leftSpaceToView(panLable, 10)
    .topSpaceToView(panLable, 20)
    .autoHeightRatio(0);
    [self.singerName setSingleLineAutoResizeWithMaxWidth:140];

    self.collection.sd_layout
    .widthIs(40)
    .heightEqualToWidth()
    .topSpaceToView(panLable, 10)
    .rightSpaceToView(panLable, 10);

    self.downLoad.sd_layout
    .widthIs(40)
    .heightEqualToWidth()
    .topSpaceToView(panLable, 10)
    .rightSpaceToView(self.collection, 10);


    self.progressView.sd_layout
    .leftSpaceToView(panLable, 0)
    .topSpaceToView(self.downLoad, 20)
    .rightSpaceToView(panLable, 0)
    .heightIs(2);


    self.playTime.sd_layout
    .leftSpaceToView(panLable, 10)
    .topSpaceToView(self.progressView, 30)
    .widthIs(100)
    .autoHeightRatio(0);



    self.duration.sd_layout
    .rightSpaceToView(panLable, 10)
    .topSpaceToView(self.progressView, 30)
    .widthIs(KSCreenWidth/2.0)
    .autoHeightRatio(0);



    self.playOrPause.sd_layout
    .centerXEqualToView(panLable)
    .widthIs(65)
    .heightEqualToWidth()
    .topSpaceToView(self.progressView, 40);


    self.lastSong.sd_layout
    .widthIs(40)
    .heightEqualToWidth()
    .topSpaceToView(self.progressView, 40+12.5)
    .rightSpaceToView(self.playOrPause, 30);


    self.nextSong.sd_layout
    .leftSpaceToView(self.playOrPause, 30)
    .widthIs(40)
    .heightIs(40)
    .topEqualToView(self.lastSong);






}


-(NSString *)getMinuteSecondWithTime:(NSTimeInterval)time
{

    int minute = (int)time / 60;
    int second = (int)time % 60;

    if (second > 9) 
    {

        return [NSString stringWithFormat:@"%d:%d",minute,second];

    }
    return [NSString stringWithFormat:@"%d:0%d",minute,second];

}//通过获取时间展示"分钟:秒钟"


#pragma mark - OverRide Methods
-(NSTimer*)timer
{
    if (!_timer) 
    {

        _timer = [TimerWeakTarget scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
    }

    return _timer;
}


- (AVAudioPlayer*)audioPlayer
{
    if (!_audioPlayer) {

        //获取本地播放文件路径
        NSString *path = [[NSBundle mainBundle] pathForResource:kMusicFile ofType:nil];

        NSError *error = nil;

        //初始化播放器
        _audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] error:&error];

        //是否循环播放
        _audioPlayer.numberOfLoops = 0;

        //把播放文件加载到缓存中(注意:即使在播放之前音频文件没有加载到缓冲区程序也会隐式调用此方法。)
        [_audioPlayer prepareToPlay];

        //设置代理,监听播放状态(例如:播放完成)
        _audioPlayer.delegate = self;


        // 设置音频会话模式,后台播放
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
        [audioSession setActive:YES error:nil];


        // 添加通知(输出改变通知)  ios 6.0 后
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChange:) name:AVAudioSessionRouteChangeNotification object:nil];



        if (error) {

            NSAssert(YES,"音乐初始化过程报错");

        }


    }
    return _audioPlayer;
}


- (void)dealloc
{

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}//移除通知


#pragma mark - Action Methods
- (void)downloadAction
{
    NSLog(@"下载");

}//下载

- (void)collectionAction
{
    NSLog(@"收藏");
}//收藏


- (void)lastSongAction:(UIButton*)sender
{

}//上一首


- (void)playOrPauseAction:(UIButton*)sender
{

    sender.selected = !sender.selected;

    if (sender.selected) {

        [self playMusic];

    }else{

        [self pauseMusic];

    }


}//播放或暂停


- (void)nestSongAction:(UIButton*)sender
{

}//下一首


- (void)updateProgress
{

    //更新进度条值
    self.progressView.value = self.audioPlayer.currentTime/self.audioPlayer.duration;

    //当前播放时长
    self.playTime.text = [self getMinuteSecondWithTime:self.audioPlayer.currentTime];

}//更新进度条


- (void)playMusic
{

    if (!self.audioPlayer.isPlaying) 
    {

        [self.audioPlayer play];
        //开始计时
        self.timer.fireDate = [NSDate distantPast];

    }

}//播放


- (void)pauseMusic
{

    if (self.audioPlayer.isPlaying) 
    {

        [self.audioPlayer pause];
        //暂停定时器
        self.timer.fireDate = [NSDate distantFuture];

    }

}//暂停


#pragma mark - Notification Method
- (void)progressValueChanged
{

    self.audioPlayer.currentTime = self.progressView.value *self.audioPlayer.duration;

    self.playOrPause.selected = NO;

    [self playOrPauseAction:self.playOrPause];

}//监听progress值变化(拖动进度条到对应时间后,开始播放)


- (void)routeChange:(NSNotification*)notification
{

    NSDictionary *dic = notification.userInfo;

    int changeReason = [dic[AVAudioSessionRouteChangeReasonKey] intValue];

    //等于AVAudioSessionRouteChangeReasonOldDeviceUnavailable表示旧输出不可用
    if (changeReason == AVAudioSessionRouteChangeReasonOldDeviceUnavailable)
    {
        AVAudioSessionRouteDescription *routeDescription=dic[AVAudioSessionRouteChangePreviousRouteKey];
        AVAudioSessionPortDescription *portDescription= [routeDescription.outputs firstObject];
        //原设备为耳机则暂停
        if ([portDescription.portType isEqualToString:@"Headphones"])
        {
            //这边必须回调到主线程
            dispatch_async(dispatch_get_main_queue(), ^{

                self.playOrPause.selected = NO;

            });

            [self pauseMusic];
        }
    }

}//输出改变通知



#pragma mark - AVAudioPlayer Delegate
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{

    self.playOrPause.selected = NO;
    //关闭会话
    [[AVAudioSession sharedInstance]setActive:NO error:nil];

}//播放完成

@end

UI 绘制这边就做说明了,主要讲几个小知识点

(1) 如何做后台播放

1> 在plist文件下添加 key : Required background modes,并设置item0 = App plays audio or streams audio/video using AirPlay

这里写图片描述

2> 设置AVAudioSession的类型为AVAudioSessionCategoryPlayback并且调用setActive::方法启动会话。

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
 正常来说,当app退到后台,程序处于悬挂状态,即暂停播放。
 在iOS中每个应用都有一个音频会话,这个会话就通过AVAudioSession来表示。
 AVAudioSession同样存在于AVFoundation框架中,它是单例模式设计,通过sharedInstance进行访问。在使用Apple设备时大家会发现有些应用只要打开其他音频播放就会终止,而有些应用却可以和其他应用同时播放,在多种音频环境中如何去控制播放的方式就是通过音频会话来完成的。

下面是音频会话的几种会话模式:

这里写图片描述

注意 : 前面的代码中也提到设置完音频会话类型之后需要调用setActive::方法将会话激活才能起作用。

(2) 如何做输出改变监听(拔出耳机音乐暂停播放)

ios6.0后还可以监听输出改变通知。通俗来说,就是拔出耳机,音乐播放暂停。
代码如下:

//添加观察者
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeChange:) name:AVAudioSessionRouteChangeNotification object:nil];

// 通知方法
- (void)routeChange:(NSNotification*)notification
{

    NSDictionary *dic = notification.userInfo;

    int changeReason = [dic[AVAudioSessionRouteChangeReasonKey] intValue];

    //等于AVAudioSessionRouteChangeReasonOldDeviceUnavailable表示旧输出不可用
    if (changeReason == AVAudioSessionRouteChangeReasonOldDeviceUnavailable)
    {
        AVAudioSessionRouteDescription *routeDescription=dic[AVAudioSessionRouteChangePreviousRouteKey];
        AVAudioSessionPortDescription *portDescription= [routeDescription.outputs firstObject];
        //原设备为耳机则暂停
        if ([portDescription.portType isEqualToString:@"Headphones"])
        {
            //这边必须回调到主线程
            dispatch_async(dispatch_get_main_queue(), ^{

                self.playOrPause.selected = NO;

            });

            [self pauseMusic];
        }
    }

}//输出改变通知

(3) 歌词轮播实现思路

歌词应该是 时间 和 对应歌词 的字典类型数据结构。用UITableView实现。获取播放器当前播放时间,查找字典找到对应的key,进而找到对应的NSIndexPath,滚动到当前cell在屏幕中央即可。

(4) 关于定时器的小细节

创建定时器的2种常用类方法

这里写图片描述

1、timerWithTimeInterval开头的构造方法,我们可以创建一个定时器,但是默认没有添加到runloop中,我们需要在创建定时器后,需要手动将其添加到NSRunLoop中,否则将不会循环执行。
2、scheduledTimerWithTimeInterval开头的构造方法,从此构造方法创建的定时器,它会默认将其指定到一个默认的runloop中,并且timerInterval时候后,定时器会自启动。

注意 :NSTimer的创建和释放必须放在同一个线程中。

主要讲下 scheduledTimerWithTimeInterval 开头的构造方法创建定时器。

问题简述:

这里写图片描述

我们使用scheduledTimerWithTimeInterval创建一个NSTimer实例后,timer会自动添加到runloop中,此时会被runloop强引用,而timer又会对 target 强引用,这样就形成强引用循环了。如果不手动失效 timer,那么self这个VC将不能被释放,尤其是当我们这个VC是push进来的,pop将不会被释放。

这里写图片描述
.
.
这里写图片描述

补充说明,按钮添加添加点击事件的方法,其中的target会不会被强引用呢?答案肯定是不会的咯。
这里写图片描述

如何解决循环引用 ?

方案一 : 在vc的dealloc中释放timer?

由于已经存在循环引用了,vc的dealloc方法将不被调用。所以此方案pass掉。

方案二 :在viewdidDisappear 释放timer ?

- (void)viewWillDisappear:(Bool)animated
{
    [super viewWillDisappear:animated];

    //将定时器从当前rooloop移除。不可恢复。
    [self.timer invalidate]; 
}

一定程度上能够解决问题,但是如果当前vc有继续push到新的页面,当返回的时候,timer已经挂了。显然也不是好的解决方案。pass掉。

方案三 :弱引用 ?__weak typeof(self) weakSelf = self; 替换target

 __weak typeof(self) weakSelf = self; 不能解决
 _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:weakSelf selector:@selector(updateProgress) userInfo:nil repeats:YES];

虽然我们将weakSelf传入timer构造方法中,虽然我们看似弱引用的self对象,但target的说明中明确提到是强引用了这个target,也就是说timer强引用了一个弱引用的变量,结果还是强引用,这和你直接传self进来效果是一样的,并不能解除强引用循环。这样的做唯一作用是如果在timer运行期间self被释放了,timer的target也就置为nil,仅此而已。

此方案pass掉。

方案四 :包装一个target,让target是另一个对象,而不是ViewController即可。

//接口文件
@interface TimerWeakTarget : NSObject

@property (nonatomic, assign) SEL selector;
@property (nonatomic, weak) NSTimer *timer;
@property (nonatomic, weak) id target;


+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)interval
                                      target:(id)aTarget
                                    selector:(SEL)aSelector
                                    userInfo:(id)userInfo
                                     repeats:(BOOL)repeats;



//实现文件 
@implementation TimerWeakTarget


+ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)interval
                                      target:(id)aTarget
                                    selector:(SEL)aSelector
                                    userInfo:(id)userInfo
                                     repeats:(BOOL)repeats
{
    TimerWeakTarget * timer = [TimerWeakTarget new];
    timer.target = aTarget;
    timer.selector = aSelector;
    //此处的target已经被换掉了不是原来的VIewController而是TimerWeakTarget类的对象timer
    timer.timer = [NSTimer scheduledTimerWithTimeInterval:interval target:timer selector:@selector(fire:) userInfo:userInfo repeats:repeats];
    return timer.timer;
}

-(void)fire:(NSTimer *)timer{

    if (self.target) {
        [self.target performSelector:self.selector withObject:timer.userInfo];
    } else {

        [self.timer invalidate];
    }
}

@end

此时你会发现,self对timer强引用了,但是timer并没有对self,因为此时timer的target对象被替换成TimerWeakTarget实例。这样就解决了循环引用问题。

关于NSLoopMode的问题

由于+ (NSTimer *)scheduledTimerWithTimeInterval:..; 此时的timer会被加入到当前线程的runloop中,默认为NSDefaultRunLoopMode。如果当前线程是主线程,某些事件,如UIScrollView的拖动时,会将runloop切换到NSEventTrackingRunLoopMode模式,在拖动的过程中,默认的NSDefaultRunLoopMode模式中注册的事件是不会被执行的。从而此时的timer也就不会触发。

解决方案:把创建好的timer手动添加到指定模式中,此处为NSRunLoopCommonModes,这个模式其实就是NSDefaultRunLoopMode与NSEventTrackingRunLoopMode的结合。

[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

本文代码下载

标题SpringBoot智能在线预约挂号系统研究AI更换标题第1章引言介绍智能在线预约挂号系统的研究背景、意义、国内外研究现状及论文创新点。1.1研究背景意义阐述智能在线预约挂号系统对提升医疗服务效率的重要性。1.2国内外研究现状分析国内外智能在线预约挂号系统的研究应用情况。1.3研究方法及创新点概述本文采用的技术路线、研究方法及主要创新点。第2章相关理论总结智能在线预约挂号系统相关理论,包括系统架构、开发技术等。2.1系统架构设计理论介绍系统架构设计的基本原则和常用方法。2.2SpringBoot开发框架理论阐述SpringBoot框架的特点、优势及其在系统开发中的应用。2.3数据库设计管理理论介绍数据库设计原则、数据模型及数据库管理系统。2.4网络安全数据保护理论讨论网络安全威胁、数据保护技术及其在系统中的应用。第3章SpringBoot智能在线预约挂号系统设计详细介绍系统的设计方案,包括功能模块划分、数据库设计等。3.1系统功能模块设计划分系统功能模块,如用户管理、挂号管理、医生排班等。3.2数据库设计实现设计数据库表结构,确定字段类型、主键及外键关系。3.3用户界面设计设计用户友好的界面,提升用户体验。3.4系统安全设计阐述系统安全策略,包括用户认证、数据加密等。第4章系统实现测试介绍系统的实现过程,包括编码、测试及优化等。4.1系统编码实现采用SpringBoot框架进行系统编码实现。4.2系统测试方法介绍系统测试的方法、步骤及测试用例设计。4.3系统性能测试分析对系统进行性能测试,分析测试结果并提出优化建议。4.4系统优化改进根据测试结果对系统进行优化和改进,提升系统性能。第5章研究结果呈现系统实现后的效果,包括功能实现、性能提升等。5.1系统功能实现效果展示系统各功能模块的实现效果,如挂号成功界面等。5.2系统性能提升效果对比优化前后的系统性能
在金融行业中,对信用风险的判断是核心环节之一,其结果对机构的信贷政策和风险控制策略有直接影响。本文将围绕如何借助机器学习方法,尤其是Sklearn工具包,建立用于判断信用状况的预测系统。文中将涵盖逻辑回归、支持向量机等常见方法,并通过实际操作流程进行说明。 一、机器学习基本概念 机器学习属于人工智能的子领域,其基本理念是通过数据自动学习规律,而非依赖人工设定规则。在信贷分析中,该技术可用于挖掘历史数据中的潜在规律,进而对未来的信用表现进行预测。 二、Sklearn工具包概述 Sklearn(Scikit-learn)是Python语言中广泛使用的机器学习模块,提供多种数据处理和建模功能。它简化了数据清洗、特征提取、模型构建、验证优化等流程,是数据科学项目中的常用工具。 三、逻辑回归模型 逻辑回归是一种常用于分类任务的线性模型,特别适用于二类问题。在信用评估中,该模型可用于判断借款人是否可能违约。其通过逻辑函数将输出映射为0到1之间的概率值,从而表示违约的可能性。 四、支持向量机模型 支持向量机是一种用于监督学习的算法,适用于数据维度高、样本量小的情况。在信用分析中,该方法能够通过寻找最佳分割面,区分违约非违约客户。通过选用不同核函数,可应对复杂的非线性关系,提升预测精度。 五、数据预处理步骤 在建模前,需对原始数据进行清理转换,包括处理缺失值、识别异常点、标准化数值、筛选有效特征等。对于信用评分,常见的输入变量包括收入水平、负债比例、信用历史记录、职业稳定性等。预处理有助于减少噪声干扰,增强模型的适应性。 六、模型构建验证 借助Sklearn,可以将数据集划分为训练集和测试集,并通过交叉验证调整参数以提升模型性能。常用评估指标包括准确率、召回率、F1值以及AUC-ROC曲线。在处理不平衡数据时,更应关注模型的召回率特异性。 七、集成学习方法 为提升模型预测能力,可采用集成策略,如结合多个模型的预测结果。这有助于降低单一模型的偏差方差,增强整体预测的稳定性准确性。 综上,基于机器学习的信用评估系统可通过Sklearn中的多种算法,结合合理的数据处理模型优化,实现对借款人信用状况的精准判断。在实际应用中,需持续调整模型以适应市场变化,保障预测结果的长期有效性。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值