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

问题描述

我正在训练一个包含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。 有人可以帮忙吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)