让我所有的预测都偏向于二进制分类

如何解决让我所有的预测都偏向于二进制分类

我正在训练一个包含8个特征的模型,这些特征使我们能够预测房间出售的可能性。

  • 区域:房间所属的区域(整数,取值介于1到10之间)

  • 日期:停留日期(1-365之间的整数,这里我们只考虑一日请求)

  • 工作日:星期几(1到7之间的整数)

  • 公寓:房间是整个公寓(1)还是仅一个房间(0)

  • #beds:房间中的床位数(1-4之间的整数)

  • 评论:卖家的平均评论(1到5之间的连续变量)

  • 图片质量:房间图片的质量(0到1之间的连续变量)

  • 价格:房间的历史价格(连续变量)

  • 接受:此帖子最后是否被接受(有人接受,为1)或不接受(0)*

“接受”列为“ y”。因此,这是一个二进制分类。


  1. 我已经完成了OneHotEncoder的分类数据。
  2. 我已对数据进行归一化。
  3. 我修改了以下RandomRofrest参数:
  • Max_depth:在16点达到峰值
  • n_estimators:峰值为300
  • min_samples_leaf: 高峰在2
  • max_features:对AUC没有影响。

AUC达到0.7889的峰值。我还能做些什么来增加它?


这是我的代码

import pandas as pd
import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.preprocessing import OneHotEncoder
from sklearn.pipeline import make_pipeline
from sklearn.compose import make_column_transformer
from sklearn.model_selection import train_test_split
df_train = pd.read_csv('case2_training.csv')

# Exclude ID since it is not a feature
X,y = df_train.iloc[:,1:-1],df_train.iloc[:,-1]
y = y.astype(np.float32)

# Split the data
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.05,shuffle=False)

ohe = OneHotEncoder(sparse = False)
column_trans = make_column_transformer(
(OneHotEncoder(),['Region','Weekday','Apartment']),remainder='passthrough')
X_train = column_trans.fit_transform(X_train)
X_test = column_trans.fit_transform(X_test)

# Normalization
from sklearn.preprocessing import MaxAbsScaler
mabsc = MaxAbsScaler()

X_train = mabsc.fit_transform(X_train)
X_test = mabsc.transform(X_test)

X_train = X_train.astype(np.float32)
X_test = X_test.astype(np.float32)

from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score

RF =  RandomForestClassifier(min_samples_leaf=2,random_state=0,n_estimators=300,max_depth = 16,n_jobs=-1,oob_score=True,max_features=i)
cross_val_score(RF,X_train,cv=5,scoring = 'roc_auc').mean()
RF.fit(X_train,y_train)
yhat = RF.predict_proba(X_test)

print("AUC:",roc_auc_score(y_test,yhat[:,-1]))

# Run the prediction on the given test set.
testset = pd.read_csv('case2_testing.csv')
testset = testset.iloc[:,1:] # exclude the 'ID' column
testset = column_trans.fit_transform(testset)
testset = mabsc.transform(testset)


yhat_2 = RF.predict_proba(testset)
final_prediction = yhat[:,-1]

但是,所有来自“ final_prediction”的概率均低于0.45,基本上,该模型认为所有样本均为0。 有人可以帮忙吗?

解决方法

您正在测试集上使用column_trans.fit_transform,这将完全覆盖训练期间安装的功能。基本上,数据现在采用的是您的训练模型无法理解的格式。

一旦在训练集上进行了训练,则之后只需使用column_trans.transform

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-