当前位置:网站首页>动手学数据分析 数据建模和模型评估
动手学数据分析 数据建模和模型评估
2022-06-24 21:00:00 【includeSteven】
数据建模与评估
介绍
在对数据进行处理和初步的可视化分析之后,我们就可以使用数据来获取想要的信息。而对数据的分析第一步就是建模,建模完成之后还需要评估我们的模型是否可靠。
数据建模
这里使用的建模库是sklearn,其中包含机器学习的很多算法,对应的模型算法选择路径可以参考下图:

划分数据集
首先需要将数据集划分为训练集和测试集,这里使用的是sklearn.model_selection.train_test_split方法,可以通过jupyter的train_test_split?查看方法的文档。
这里需要注意在切割数据集默认是使用随机选取,需要根据实际情况进行判定。
模型创建
在sklearn中,所有的估计器都继承自estimator,均通过fit方法来构建模型,使用predict来预测结果。
针对分类问题,可以使用逻辑回归或随机森林,对应下面两个类:
- sklearn.liner_model.LogisticRegression
- sklearn.ensemble.RandomForestClassifier
模型预测
模型构建完成后,可以通过predict方法来预测模型,输入特征值x,会给出对应的标签y值。
还可以通过predict_proba来得到模型预测对应的每个标签的概率是多少。
模型的评估
交叉验证
sklearn.model_selection.cross_val_score(estimator, X_train, y_train, cv=10):输出每次交叉验证的分数
混淆矩阵和对应概率计算
- sklearn.metrics.confusion_matrix
- sklearn.metrics.classification_report
绘制ROC曲线
sklearn.metrics.roc_curve,返回值为false positive rate、true positive rate和thresholds
边栏推荐
- Reading notes at night -- deep into virtual function
- MySQL common basic statements (collation)
- Danish Technical University pioneered the application of quantum computing to power flow modeling of energy system
- VB 学习笔记
- [live review] 2022 Tencent cloud future community city operator recruitment conference and SaaS 2.0 new product launch!
- 网上开户选哪个证券公司?网上开户安全么?
- Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise
- 2种常见的设备稼动率OEE监测方法
- MySQL multi condition matching fuzzy query
- Tianshu night reading notes -- disassembly engine xde32
猜你喜欢

汇编语言(3)16位汇编基础框架与加减循环

Danish Technical University pioneered the application of quantum computing to power flow modeling of energy system

Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise

JVM directive

Bi-sql top

"One good programmer is worth five ordinary programmers!"

Assembly language (4) function transfer parameters

Deep learning LSTM model for stock analysis and prediction

重磅:国产IDE发布,由阿里研发,完全开源!(高性能+高定制性)

Install mysql5.6 under linux64bit - the root password cannot be modified
随机推荐
lnmp环境安装ffmpeg,并在Yii2中使用
中金财富证券开户佣金多少呢?股票开户交易安全靠谱吗?
Bi-sql create
Introduction to bi-sql wildcards
What to learn in VB [easy to understand]
Abnova丨A4GNT多克隆抗体中英文说明
Welcome to the new world of Lenovo smart screen
Go language operators (under Lesson 8)
腾讯云WeCity丨你好 2022!
WinXP内核驱动调试
期望与方差
Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise
php easywechat 和 小程序 实现 长久订阅消息推送
vb学习什么[通俗易懂]
JS Chapter 1 Summary
Bi skill - judge 0 and null
Matlab rounding
新一代可级联的以太网远程I/O数据采集模块
天书夜读笔记——反汇编引擎xde32
对技术的乐观,正让戴尔取得比想象中更多的成就