Python全系列 教程
3567个小节阅读:5929.8k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
121# 获取训练集和测试集的特征
2colums = list(set(test_ad_cate_user.columns) & set(train_ad_cate_user.columns))
3colums.remove('label')
4colums.remove('hometown')
5colums.remove('clickTime')
6colums.remove('appCategory')
7colums
8
9# 获取训练集数据、标签、测试数据集
10x_train = train_ad_cate_user[colums].values
11y_train = train_ad_cate_user['label'].values
12x_test = test_ad_cate_user[colums].values
xxxxxxxxxx
161from sklearn.ensemble import RandomForestRegressor
2from sklearn.metrics import mean_squared_error,mean_absolute_error
3
4# n_estimators=100意味着随机森林中将有100棵树
5# random_state=0是设置随机种子,确保每次运行时的结果是可重复的
6# n_jobs=-1意味着训练过程将使用计算机上的所有核心。这有助于加速训练,特别是当您有大量的树或大型数据集时。
7rf = RandomForestRegressor(n_estimators=100,random_state=0,n_jobs=-1)
8# 模型的训练
9rf.fit(x_train,y_train)
10# 模型的预测
11pred = rf.predict(x_test)
12# 模型的评估
13# 均方误差, 值 越小越好
14print('均方误差:',mean_squared_error(y_test,pred))
15# 平均绝对误差 值 越小越好
16print('平均绝对误差:',mean_absolute_error(y_test,pred))