当前位置:网站首页>动手学数据分析 数据建模和模型评估
动手学数据分析 数据建模和模型评估
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
边栏推荐
猜你喜欢
随机推荐
Introduction to bi-sql wildcards
Zuckerberg demonstrated four VR head display prototypes, and meta revealed the "family" of metauniverse
Transform BeanUtils to achieve list data copy gracefully
mysql查询时间戳转换成日期格式
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source! (high performance + high customization)
AUTOCAD——两种延伸方式
天书夜读笔记——反汇编引擎xde32
PMP考试“临门一脚”如何踢得漂亮?
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 和 小程序 实现 长久订阅消息推送
ContentResolver,拿到手机短信内容
Which securities company should I choose to open an account online? Is it safe to open an account online?
Install mysql5.6 under linux64bit - the root password cannot be modified
脱氧核糖核酸酶I中英文说明书
Bi skill - judge 0 and null
天书夜读笔记——深入虚函数virtual
Deep learning LSTM model for stock analysis and prediction
LLVM TargetPassConfig
Bi-sql - different join
Using bindservice method to pause music playing









