中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

怎樣創(chuàng)建網(wǎng)站詳細步驟seo技術優(yōu)化服務

怎樣創(chuàng)建網(wǎng)站詳細步驟,seo技術優(yōu)化服務,網(wǎng)推怎么推廣,wordpress url title文章目錄 一、基礎知識點(1)邏輯回歸表達式(2)sigmoid函數(shù)的導數(shù)損失函數(shù)(Cross-entropy, 交叉熵損失函數(shù))交叉熵求導準確率計算評估指標 二、導入庫和數(shù)據(jù)集導入庫讀取數(shù)據(jù) 三、分析與訓練四、模型評價ROC曲線KS值再做特征篩選生成報告 五、行為評分卡模型表現(xiàn)總結(jié) 一、基礎知…

文章目錄

  • 一、基礎知識點
    • (1)邏輯回歸表達式
    • (2)sigmoid函數(shù)的導數(shù)
    • 損失函數(shù)(Cross-entropy, 交叉熵損失函數(shù))
    • 交叉熵求導
    • 準確率計算
    • 評估指標
  • 二、導入庫和數(shù)據(jù)集
    • 導入庫
    • 讀取數(shù)據(jù)
  • 三、分析與訓練
  • 四、模型評價
    • ROC曲線
    • KS值
    • 再做特征篩選
    • 生成報告
  • 五、行為評分卡模型表現(xiàn)
  • 總結(jié)

一、基礎知識點

(1)邏輯回歸表達式

在這里插入圖片描述
in:

import numpy as np
import matplotlib.pyplot as plt
import tqdm
import osfile = 'testSet.txt'
if os.path.exists(file):data = np.loadtxt(file)
features = data[:, :2]
labels = data[:, -1]print(features.shape, labels.shape)

out:
在這里插入圖片描述
in:

print('特征的維度: {0}'.format(features.shape[1]))
print('總共有{0}個類別'.format(len(np.unique(labels))))

out:
特征的維度: 2
總共有2個類別

figure = plt.figure()
plt.scatter([x[0] for x in features], [x[1] for x in features])
plt.show()

在這里插入圖片描述

(2)sigmoid函數(shù)的導數(shù)

在這里插入圖片描述

損失函數(shù)(Cross-entropy, 交叉熵損失函數(shù))

在這里插入圖片描述

def loss(Y_t, Y_p):'''算交叉熵損失函數(shù)Y_t: 獨熱編碼之后的真實值向量Y_p: 預測的值向量        '''trans = np.zeros(shape=Y_t.shape)for sample_idx in range(len(trans)):# print(trans[sample_idx], [Y_p[sample_idx], 1.0 - Y_p[sample_idx]])# 避免出現(xiàn)0trans[sample_idx] = [Y_p[0][sample_idx] , 1.0 - Y_p[0][sample_idx] + 1e-5]log_y_p = np.log(trans)return -np.sum(np.multiply(Y_t, log_y_p))Y_t = np.array([[0, 1], [1, 0]])
Y_p = np.array([[0.8, 1]])loss(Y_t=Y_t, Y_p=Y_p)

交叉熵求導

在這里插入圖片描述

def delta_cross_entropy(Y_t, Y_p):trans = np.zeros(shape=Y_t.shape)for sample_idx in range(len(trans)):trans[sample_idx] = [Y_p[0][sample_idx] + 1e-8, 1.0 - Y_p[0][sample_idx] + 1e-8]Y_t[Y_t == 0] += 1e-8error = Y_t * (1 / trans)error[:, 0] = -error[:, 0]return np.sum(error, axis=1, keepdims=True)Y_t = np.array([[0, 1], [1, 0]], dtype=np.float)
Y_p = np.array([[0.8, 1]])
delta_cross_entropy(Y_t=Y_t, Y_p=Y_p)

準確率計算

在這里插入圖片描述

def accuracy(Y_p, Y_t):Y_p[Y_p >= 0.5] = 1Y_p[Y_p < 0.5] = 0predict = np.sum(Y_p == Y_t)return predict /  len(Y_t)

評估指標

在這里插入圖片描述

def recall(Y_p, Y_t):return np.sum(np.argmax(Y_p) == np.argmax(Y_t)) / np.sum(Y_p == 1)

二、導入庫和數(shù)據(jù)集

導入庫

import pandas as pd
from sklearn.metrics import roc_auc_score,roc_curve,auc
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.linear_model import LogisticRegression
import numpy as np
import random
import math

讀取數(shù)據(jù)

data = pd.read_csv('Acard.txt')
data.head()

在這里插入圖片描述
在這里插入圖片描述

三、分析與訓練

#這是我們?nèi)康淖兞?#xff0c;info結(jié)尾的是自己做的無監(jiān)督系統(tǒng)輸出的個人表現(xiàn),score結(jié)尾的是收費的外部征信數(shù)據(jù)
feature_lst = ['person_info','finance_info','credit_info','act_info','td_score','jxl_score','mj_score','rh_score']
x = train[feature_lst]
y = train['bad_ind']val_x =  val[feature_lst]
val_y = val['bad_ind']lr_model = LogisticRegression(C=0.1)
lr_model.fit(x,y)

四、模型評價

ROC曲線

描繪的是不同的截斷點時,并以FPR和TPR為橫縱坐標軸,描述隨著截斷點的變小,TPR隨著FPR的變化。
縱軸:TPR=正例分對的概率 = TP/(TP+FN),其實就是查全率
橫軸:FPR=負例分錯的概率 = FP/(FP+TN)

作圖步驟:

根據(jù)學習器的預測結(jié)果(注意,是正例的概率值,非0/1變量)對樣本進行排序(從大到小)-----這就是截斷點依次選取的順序 按順序選取截斷點,并計算TPR和FPR—也可以只選取n個截斷點,分別在1/n,2/n,3/n等位置 連接所有的點(TPR,FPR)即為ROC圖

在這里插入代碼片

KS值

作圖步驟:

根據(jù)學習器的預測結(jié)果(注意,是正例的概率值,非0/1變量)對樣本進行排序(從大到小)-----這就是截斷點依次選取的順序
按順序選取截斷點,并計算TPR和FPR —也可以只選取n個截斷點,分別在1/n,2/n,3/n等位置
橫軸為樣本的占比百分比(最大100%),縱軸分別為TPR和FPR,可以得到KS曲線
TPR和FPR曲線分隔最開的位置就是最好的”截斷點“,最大間隔距離就是KS值,通常>0.2即可認為模型有比較好偶的預測準確性。

y_pred = lr_model.predict_proba(x)[:,1]
fpr_lr_train,tpr_lr_train,_ = roc_curve(y,y_pred)
train_ks = abs(fpr_lr_train - tpr_lr_train).max()
print('train_ks : ',train_ks)y_pred = lr_model.predict_proba(val_x)[:,1]
fpr_lr,tpr_lr,_ = roc_curve(val_y,y_pred)
val_ks = abs(fpr_lr - tpr_lr).max()
print('val_ks : ',val_ks)from matplotlib import pyplot as plt
plt.plot(fpr_lr_train,tpr_lr_train,label = 'train LR')
plt.plot(fpr_lr,tpr_lr,label = 'evl LR')
plt.plot([0,1],[0,1],'k--')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.title('ROC Curve')
plt.legend(loc = 'best')
plt.show()

train_ks : 0.4151676259891534
val_ks : 0.3856283523530577
在這里插入圖片描述

再做特征篩選

#再做特征篩選
from statsmodels.stats.outliers_influence import variance_inflation_factor
X = np.array(x)
for i in range(X.shape[1]):print(variance_inflation_factor(X,i))

在這里插入圖片描述

import lightgbm as lgb
from sklearn.model_selection import train_test_split
train_x,test_x,train_y,test_y = train_test_split(x,y,random_state=0,test_size=0.2)
def  lgb_test(train_x,train_y,test_x,test_y):clf =lgb.LGBMClassifier(boosting_type = 'gbdt',objective = 'binary',metric = 'auc',learning_rate = 0.1,n_estimators = 24,max_depth = 5,num_leaves = 20,max_bin = 45,min_data_in_leaf = 6,bagging_fraction = 0.6,bagging_freq = 0,feature_fraction = 0.8,)clf.fit(train_x,train_y,eval_set = [(train_x,train_y),(test_x,test_y)],eval_metric = 'auc')return clf,clf.best_score_['valid_1']['auc'],
lgb_model , lgb_auc  = lgb_test(train_x,train_y,test_x,test_y)
feature_importance = pd.DataFrame({'name':lgb_model.booster_.feature_name(),'importance':lgb_model.feature_importances_}).sort_values(by=['importance'],ascending=False)
feature_importance

在這里插入圖片描述

feature_lst = ['person_info','finance_info','credit_info','act_info']
x = train[feature_lst]
y = train['bad_ind']val_x =  val[feature_lst]
val_y = val['bad_ind']lr_model = LogisticRegression(C=0.1,class_weight='balanced')
lr_model.fit(x,y)
y_pred = lr_model.predict_proba(x)[:,1]
fpr_lr_train,tpr_lr_train,_ = roc_curve(y,y_pred)
train_ks = abs(fpr_lr_train - tpr_lr_train).max()
print('train_ks : ',train_ks)y_pred = lr_model.predict_proba(val_x)[:,1]
fpr_lr,tpr_lr,_ = roc_curve(val_y,y_pred)
val_ks = abs(fpr_lr - tpr_lr).max()
print('val_ks : ',val_ks)
from matplotlib import pyplot as plt
plt.plot(fpr_lr_train,tpr_lr_train,label = 'train LR')
plt.plot(fpr_lr,tpr_lr,label = 'evl LR')
plt.plot([0,1],[0,1],'k--')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.title('ROC Curve')
plt.legend(loc = 'best')
plt.show()

在這里插入圖片描述

# 系數(shù)
print('變量名單:',feature_lst)
print('系數(shù):',lr_model.coef_)
print('截距:',lr_model.intercept_)

在這里插入圖片描述

生成報告

#生成報告
model = lr_model
row_num, col_num = 0, 0
bins = 20
Y_predict = [s[1] for s in model.predict_proba(val_x)]
Y = val_y
nrows = Y.shape[0]
lis = [(Y_predict[i], Y[i]) for i in range(nrows)]
ks_lis = sorted(lis, key=lambda x: x[0], reverse=True)
bin_num = int(nrows/bins+1)
bad = sum([1 for (p, y) in ks_lis if y > 0.5])
good = sum([1 for (p, y) in ks_lis if y <= 0.5])
bad_cnt, good_cnt = 0, 0
KS = []
BAD = []
GOOD = []
BAD_CNT = []
GOOD_CNT = []
BAD_PCTG = []
BADRATE = []
dct_report = {}
for j in range(bins):ds = ks_lis[j*bin_num: min((j+1)*bin_num, nrows)]bad1 = sum([1 for (p, y) in ds if y > 0.5])good1 = sum([1 for (p, y) in ds if y <= 0.5])bad_cnt += bad1good_cnt += good1bad_pctg = round(bad_cnt/sum(val_y),3)badrate = round(bad1/(bad1+good1),3)ks = round(math.fabs((bad_cnt / bad) - (good_cnt / good)),3)KS.append(ks)BAD.append(bad1)GOOD.append(good1)BAD_CNT.append(bad_cnt)GOOD_CNT.append(good_cnt)BAD_PCTG.append(bad_pctg)BADRATE.append(badrate)dct_report['KS'] = KSdct_report['BAD'] = BADdct_report['GOOD'] = GOODdct_report['BAD_CNT'] = BAD_CNTdct_report['GOOD_CNT'] = GOOD_CNTdct_report['BAD_PCTG'] = BAD_PCTGdct_report['BADRATE'] = BADRATE
val_repot = pd.DataFrame(dct_report)
val_repot

在這里插入圖片描述

五、行為評分卡模型表現(xiàn)

from pyecharts.charts import *
from pyecharts import options as opts
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
np.set_printoptions(suppress=True)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
line = (Line().add_xaxis(list(val_repot.index)).add_yaxis("分組壞人占比",list(val_repot.BADRATE),yaxis_index=0,color="red",).set_global_opts(title_opts=opts.TitleOpts(title="行為評分卡模型表現(xiàn)"),).extend_axis(yaxis=opts.AxisOpts(name="累計壞人占比",type_="value",min_=0,max_=0.5,position="right",axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color="red")),axislabel_opts=opts.LabelOpts(formatter="{value}"),)).add_xaxis(list(val_repot.index)).add_yaxis("KS",list(val_repot['KS']),yaxis_index=1,color="blue",label_opts=opts.LabelOpts(is_show=False),)
)
line.render_notebook()

在這里插入圖片描述

from pyecharts.charts import *
from pyecharts import options as opts
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
np.set_printoptions(suppress=True)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
line = (Line().add_xaxis(list(val_repot.index)).add_yaxis("分組壞人占比",list(val_repot.BADRATE),yaxis_index=0,color="red",).set_global_opts(title_opts=opts.TitleOpts(title="行為評分卡模型表現(xiàn)"),).extend_axis(yaxis=opts.AxisOpts(name="累計壞人占比",type_="value",min_=0,max_=0.5,position="right",axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(color="red")),axislabel_opts=opts.LabelOpts(formatter="{value}"),)).add_xaxis(list(val_repot.index)).add_yaxis("KS",list(val_repot['KS']),yaxis_index=1,color="blue",label_opts=opts.LabelOpts(is_show=False),)
)
line.render_notebook()

在這里插入圖片描述

import seaborn as sns
sns.distplot(val.score,kde=True)val = val.sort_values('score',ascending=True).reset_index(drop=True)
df2=val.bad_ind.groupby(val['level']).sum()
df3=val.bad_ind.groupby(val['level']).count()
print(df2/df3) 

在這里插入圖片描述

總結(jié)

http://www.risenshineclean.com/news/48901.html

相關文章:

  • 有經(jīng)驗的南昌網(wǎng)站制作百度關鍵詞優(yōu)化策略
  • 廣告網(wǎng)站模板下載 迅雷下載安裝網(wǎng)站維護費一年多少錢
  • WordPress網(wǎng)站論文微信小程序開發(fā)文檔
  • 免費模板建站寧德市醫(yī)院東僑院區(qū)
  • 做網(wǎng)站自動賺錢網(wǎng)絡推廣都需要做什么
  • 佛山專注網(wǎng)站制作細節(jié)長沙縣網(wǎng)絡營銷咨詢
  • 網(wǎng)站開發(fā)工程師培訓seo是什么職業(yè)
  • 兼職網(wǎng)站開發(fā)全部視頻支持代表手機瀏覽器
  • 三河建設局網(wǎng)站熱門seo推廣排名穩(wěn)定
  • 網(wǎng)站備案 修改優(yōu)化seo廠家
  • 網(wǎng)站制作 徐州晉江怎么交換友情鏈接
  • 怎樣到國外做合法博彩法網(wǎng)站河南鄭州最新消息
  • 錦州做網(wǎng)站全網(wǎng)營銷與seo
  • 幫別人做設計圖的網(wǎng)站渠道推廣策略
  • 旺旺號查詢網(wǎng)站怎么做百度推廣個人怎么開戶
  • 公司網(wǎng)站怎么做才能有官網(wǎng)二字推廣營銷軟件app
  • 上海網(wǎng)站建設公司介紹seo關鍵詞排名軟件流量詞
  • 免費軟件網(wǎng)站下載深圳靠譜網(wǎng)站建設公司
  • 品牌網(wǎng)站建設的要點培訓心得體會1000字通用
  • wordpress的小程序網(wǎng)站優(yōu)化哪家好
  • iis php服務器搭建網(wǎng)站杭州優(yōu)化外包
  • 國內(nèi)免費saas crm正在seo sem
  • 愛城市網(wǎng)官方下載武漢網(wǎng)站推廣優(yōu)化
  • wordpress登陸鏈接seo兼職
  • 微信公眾號接口開發(fā)西安seo關鍵詞排名
  • 吉林網(wǎng)站模板系統(tǒng)優(yōu)化助手
  • c 網(wǎng)站開發(fā)商城網(wǎng)站建設
  • 內(nèi)江市網(wǎng)站建設如何發(fā)布自己的html網(wǎng)站
  • 室內(nèi)在線設計網(wǎng)站今日最新消息新聞報道
  • 阜陽html5網(wǎng)站建設貴陽做網(wǎng)絡推廣的公司