日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

神经网络贷款风险评估(base on keras and python ) 原创 2017年08月18日 14:35:17 标签: python / 神经网络 / keras 300 用我

發布時間:2025/3/21 python 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 神经网络贷款风险评估(base on keras and python ) 原创 2017年08月18日 14:35:17 标签: python / 神经网络 / keras 300 用我 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

神經網絡貸款風險評估(base on keras and python )

原創 2017年08月18日 14:35:17
  • 300
  • 編輯
  • 刪除

????用我兒子的話說,有一天啊,小烏龜遇見小兔子………

????有一天,我在網上看到這樣一片文章,決策書做貸款決策分析。

貸還是不貸:如何用Python和機器學習幫你決策?

import pandas as pd df = pd.read_csv('loans.csv')#print(df.head())X = df.drop('safe_loans', axis=1)y = df.safe_loans#change categoricalfrom sklearn.preprocessing import LabelEncoder from collections import defaultdict d = defaultdict(LabelEncoder) X_trans = X.apply(lambda x: d[x.name].fit_transform(x)) X_trans.head()#X_trans.to_excel('X_trans.xls') #random take train and testfrom sklearn.cross_validation import train_test_split X_train, X_test, y_train, y_test = train_test_split(X_trans, y, random_state=1) #call decision tree from sklearn import tree clf = tree.DecisionTreeClassifier(max_depth=8) clf = clf.fit(X_train, y_train)test_rec = X_test.iloc[1,:] clf.predict([test_rec])y_test.iloc[1] from sklearn.metrics import accuracy_score print(accuracy_score(y_test, clf.predict(X_test)))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

????這篇文章寫的非常好,從中學到好多,但是計算的正確率不太高,8層的決策樹正確率才能達到0.645

0.645480347467
  • 1

????我用神經網絡重新做了計算

#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Aug 17 21:14:08 2017@author: luogan """#read data import pandas as pd df = pd.read_csv('loans.csv')#print(df.head())#X = df.drop('safe_loans', axis=1)X = df.drop(['safe_loans' ],axis=1) y = df.safe_loans#change categoricalfrom sklearn.preprocessing import LabelEncoder from collections import defaultdict d = defaultdict(LabelEncoder) X_trans = X.apply(lambda x: d[x.name].fit_transform(x)) X_trans.head()#X_trans.to_excel('X_trans.xls') ############## data_train=X_trans data_max = data_train.max() data_min = data_train.min() data_mean = data_train.mean() # # data_std = data_train.std() X_train1 = (data_train-data_max)/(data_max-data_min)y=0.5*(y+1) #random take train and testfrom sklearn.cross_validation import train_test_split x_train, x_test, y_train, y_test = train_test_split(X_train1, y, random_state=1)#x_train.to_excel('xx_trans.xls') #y_train.to_excel('y_trans.xls') #call decision tree #from sklearn import tree #clf = tree.DecisionTreeClassifier(max_depth=10) #clf = clf.fit(X_train, y_train)from keras.models import Sequential from keras.layers.core import Dense, Dropout, Activationmodel = Sequential() #建立模型 model.add(Dense(input_dim = 12, output_dim = 48)) #添加輸入層、隱藏層的連接 model.add(Activation('tanh')) #以Relu函數為激活函數model.add(Dense(input_dim = 48, output_dim = 48)) #添加隱藏層、隱藏層的連接 model.add(Activation('relu')) #以Relu函數為激活函數 model.add(Dropout(0.2))model.add(Dense(input_dim = 48, output_dim = 36)) #添加隱藏層、隱藏層的連接 model.add(Activation('relu')) #以Relu函數為激活函數 model.add(Dropout(0.2)) model.add(Dense(input_dim = 36, output_dim = 36)) #添加隱藏層、隱藏層的連接 model.add(Activation('relu')) #以Relu函數為激活函數model.add(Dense(input_dim = 36, output_dim = 12)) #添加隱藏層、隱藏層的連接 model.add(Activation('relu')) #以Relu函數為激活函數 model.add(Dense(input_dim = 12, output_dim = 12)) #添加隱藏層、隱藏層的連接 model.add(Activation('relu')) #以Relu函數為激活函數model.add(Dense(input_dim = 12, output_dim = 1)) #添加隱藏層、輸出層的連接 model.add(Activation('sigmoid')) #以sigmoid函數為激活函數 #編譯模型,損失函數為binary_crossentropy,用adam法求解 model.compile(loss='mean_squared_error', optimizer='adam') model.fit(x_train.values, y_train.values, nb_epoch = 70, batch_size = 2000) #訓練模型r = pd.DataFrame(model.predict_classes(x_test.values)) ''' r = pd.DataFrame(model.predict(x_test.values)) rr=r.values tr=rr.flatten()for i in range(tr.shape[0]):if tr[i]>0.5:tr[i]=1else:tr[i]=0 ''' from sklearn.metrics import accuracy_score print(accuracy_score(y_test, r))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
0.650640749978
  • 1

????我對神經網絡進行了各種優化,正確率一直上不去,計算結果還不如我的神經網絡股票預測代碼

????我不高興,非常不高興,65%的正確率是我無法容忍的,讓我郁悶的是,我一直深愛的神經網絡居然也這么無力
不能這樣下去,下回我們將采用傳說中的xgboost試一下

百度云代碼下載

提取碼 ???? jc5x

總結

以上是生活随笔為你收集整理的神经网络贷款风险评估(base on keras and python ) 原创 2017年08月18日 14:35:17 标签: python / 神经网络 / keras 300 用我的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。