- 博客(8)
- 收藏
- 关注
原创 woe编码对于少部分离散变量和大部分的离散变量
from woe_bin import woe_bin import sys def woe_bin(merge_data,label): wb = woe_bin(indata = merge_data, target=label, min_group_rate=0.05, max_bin=6, bin_method='mono', alg_method='iv') #print(wb) mapiv = wb.split_data() #print(mapiv) .
2022-02-15 17:51:07 511
原创 离散值分箱
def chi12(np_regroup,confidence=4,bins=20): #设定自由度为1,卡方阈值为3.841,最大分箱数20 #对相邻两个区间的值进行卡方计算 chi_table = np.array([]) #创建一个数组保存相邻两个区间的卡方值 index = [] for i in np.arange(np_regroup.shape[0]-1): for j in np.arange(i+1,np_regr...
2021-12-21 16:33:12 329
原创 连续值分箱
def chi_bins(df,col,target,confidence=3.841,bins=20): #设定自由度为1,卡方阈值为3.841,最大分箱数20 total = df[target].count() #计算总样本数 bad = df[target].sum() #计算坏样本总数 good = total - bad #计算好样本总数 total_bin = df.groupby([col])[target].count() #...
2021-12-21 16:32:05 187
原创 python向前逐步回归
一,向前逐步回归,相除多重共线性 import statsmodels.formula.api as smf def forward_selected(data, response): """Linear model designed by forward selection. Parameters: ----------- data : pandas DataFrame with all possible predictors and respons...
2021-12-21 16:15:40 703
原创 交叉验证方法
num = np.zeros(15,dtype = np.float64) i = 0 kf = KFold(n_splits = 5,shuffle = True ,random_state = 2021) for n_fold, (trn_idx, val_idx) in enumerate(kf.split(X_data)): x_train, y_train = X.iloc[trn_idx], Y.iloc[trn_idx] x_test, y_test = X.iloc[val...
2021-11-12 20:24:30 1271
原创 python时间戳转化成日期数据,日期数据与当前日期加减
import time import datetime import numpy as np #n = len(X_train['create_time']) #np.zeros(n,dtype = np.int32) ####################单个转换时间戳为时间 def changetime(x): timeArray = time.localtime(x) otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeAr...
2021-11-11 22:59:29 911
原创 logistic SVM RF 的运行代码
from sklearn.linear_model import LogisticRegression from sklearn.preprocessing import StandardScaler from sklearn.pipeline import make_pipeline from sklearn.metrics import mean_squared_error from sklearn.metrics import roc_auc_score ###########logistic .
2021-11-11 11:11:46 967
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人