- 分桶
- 按照取值范围均分成几个区间
import pandas.core.algorithms as algos
import pandas as pd
bins = algos.quantile(numpy.unique(train_data[item]), numpy.linspace(0, 1, 10))
train_data[item] = pd.tools.tile._bins_to_cuts(train_data[item], bins, include_lowest=True)
- 按照分位数分成几个区间
train_data[item] = train_data[item].apply(own_bins,args=(train_data[item],))
def own_bins(x, origin_data):
for i in range(0, 11, 1):
if x <= origin_data.quantile(i*0.1):
return i + 1
return 10
- 按照4分位做最大值和最小值限制
print train_data[item].quantile(0.75)
print train_data[item].quantile(0.25)
upper = train_data[item].quantile(0.25) - 1.5 * (
train_data[item].quantile(0.75) - train_data[item].quantile(0.25))
lower = train_data[item].quantile(0.75) + 1.5 * (
train_data[item].quantile(0.75) - train_data[item].quantile(0.25))
train_data[item] = numpy.clip(train_data[item], upper, lower)
print train_data[item].describe()
print train_data[item].dtypes