当前位置:网站首页>动手学数据分析 数据建模和模型评估
动手学数据分析 数据建模和模型评估
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
边栏推荐
猜你喜欢
随机推荐
【直播回顾】2022腾讯云未来社区城市运营方招募会暨SaaS 2.0新品发布会!
TC对象结构和简称
[live review] 2022 Tencent cloud future community city operator recruitment conference and SaaS 2.0 new product launch!
WinXP内核驱动调试
Tianshu night reading notes -- disassembly engine xde32
ImageView shows network pictures
Danish Technical University pioneered the application of quantum computing to power flow modeling of energy system
This national day! Tencent cloud wecity will accompany you to travel and light up the city landmark
LLVM TargetPassConfig
Start service 11111
Deep learning LSTM model for stock analysis and prediction
腾讯完成全面上云 打造国内最大云原生实践
这个国庆!腾讯云WeCity陪您一同出行,点亮城市地标...
VB 学习笔记
Ecological escort cloud service providers wave "Intel flag"
Première application de l'informatique quantique à la modélisation des flux de puissance dans les systèmes énergétiques à l'Université technique danoise
C language boundary calculation and asymmetric boundary
Reading notes at night -- deep into virtual function
PMP考试“临门一脚”如何踢得漂亮?
网上开户选哪个证券公司?网上开户安全么?









