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

歡迎訪問 生活随笔!

生活随笔

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

python

python数据分析练手小项目-汽车销售偷漏纳税人识别

發布時間:2023/12/18 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python数据分析练手小项目-汽车销售偷漏纳税人识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本項目主要掌握數據預處理和神經網絡、決策樹建模以及利用roc曲線進行模型評價。

import pandas as pd data=pd.read_excel(data/cardata.xls',index_col=0)#數據探索 import matplotlib.pyplot as plt data.describe()

pd.value_counts(data[u'銷售類型']) pd.value_counts(data[u'銷售模式']) pd.crosstab(data[u'輸出'],data[u'銷售類型']) pd.crosstab(data[u'輸出'],data[u'銷售模式'])for col in data.columns:if not col in [u'銷售類型',u'銷售模式',u'輸出']:fig = plt.figure()data[col].hist(bins=20, by = data[u'輸出'])fig.show()#數據預處理 data=pd.merge(data,pd.get_dummies(data[u'銷售模式']),left_index=True,right_index=True) data=pd.merge(data,pd.get_dummies(data[u'銷售類型']),left_index=True,right_index=True) data['type']=pd.get_dummies(data[u'輸出'])[u'正常'] data = data.iloc[:,3:] del data[u'輸出'] from random import shuffle data_2=datadata[:5]

data = data.as_matrix() #將表格轉換為矩陣 shuffle(data)p = 0.8 #設置訓練數據比例 train = data[:int(len(data)*p),:] #前80%為訓練集 test = data[int(len(data)*p):,:] #后20%為測試集 #混淆矩陣函數 def cm_plot(y, yp):from sklearn.metrics import confusion_matrixcm = confusion_matrix(y, yp) import matplotlib.pyplot as plt plt.matshow(cm, cmap=plt.cm.Greens) plt.colorbar() for x in range(len(cm)): for y in range(len(cm)):plt.annotate(cm[x,y], xy=(x, y), horizontalalignment='center', verticalalignment='center')plt.ylabel('True label') plt.xlabel('Predicted label') return plt#構建CART決策樹模型 from sklearn.tree import DecisionTreeClassifier #導入決策樹模型treefile = 'output/cartree.pkl' #模型輸出名字 tree = DecisionTreeClassifier() #建立決策樹模型 tree.fit(train[:,:25], train[:,25]) #訓練,除了最后一列#保存模型 from sklearn.externals import joblib joblib.dump(tree, treefile) cm_plot(train[:,25], tree.predict(train[:,:25])).show() #顯示混淆矩陣可視化結果 #注意到Scikit-Learn使用predict方法直接給出預測結果; #分類準確率有62+37人

from sklearn.metrics import roc_curve #導入ROC曲線函數fpr, tpr, thresholds = roc_curve(test[:,25], tree.predict_proba(test[:,:25])[:,1], pos_label=1) plt.plot(fpr, tpr, linewidth=2, label = 'ROC of CART', color = 'green') #作出ROC曲線 plt.xlabel('False Positive Rate') #坐標軸標簽 plt.ylabel('True Positive Rate') #坐標軸標簽 plt.ylim(0,1.05) #邊界范圍 plt.xlim(0,1.05) #邊界范圍 plt.legend(loc=4) #圖例 plt.show() #顯示作圖結果

總結

以上是生活随笔為你收集整理的python数据分析练手小项目-汽车销售偷漏纳税人识别的全部內容,希望文章能夠幫你解決所遇到的問題。

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