python之区块链异常交易

区块链非法交易预测分析

import pandas as pd
import numpy as np 
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn.utils import shuffle
from sklearn.metrics import confusion_matrix
import seaborn as sns
from sklearn.preprocessing import StandardScaler
edges = pd.read_csv("/home/kesci/input/first4634/elliptic_txs_edgelist.csv")
features = pd.read_csv("/home/kesci/input/first4634/elliptic_txs_features.csv",header=None)
classes = pd.read_csv("/home/kesci/input/first4634/elliptic_txs_classes.csv")
tx_features = ["tx_feat_"+str(i) for i in range(2,95)]
agg_features = ["agg_feat_"+str(i) for i in range(1,73)]
features.columns = ["txId","time_step"] + tx_features + agg_features
features = pd.merge(features,classes,left_on="txId",right_on="txId",how='left')
features['class'] = features['class'].apply(lambda x: '0' if x == "unknown" else x)

 异常交易相关性特征分析


fig, axes = plt.subplots(3,2, figsize=(10,10))


grouped = features.groupby(['time_step', 'class'])['tx_feat_2'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_2', hue='class', data=grouped, ax = axes[0][0])
plt.legend(loc=(1.0, 0.8))
plt.ylabel('tx_feat_2')



grouped = features.groupby(['time_step', 'class'])['tx_feat_6'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_6', hue='class', data=grouped, ax = axes[0][1])
plt.legend(loc=(1.0, 0.8))
plt.ylabel('tx_feat_6')

grouped = features.groupby(['time_step', 'class'])['tx_feat_9'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_9', hue='class', data=grouped, ax = axes[1][0])
plt.legend(loc=(1.0, 0.8))
plt.ylabel('tx_feat_9')

grouped = features.groupby(['time_step', 'class'])['tx_feat_10'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_10', hue='class', data=grouped, ax = axes[1][1])
plt.legend(loc=(1.0, 0.8))
plt.ylabel('tx_feat_10')

grouped = features.groupby(['time_step', 'class'])['tx_feat_12'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_12', hue='class', data=grouped, ax = axes[2][0])
plt.legend(loc=(1.0, 0.8))
plt.ylabel('tx_feat_12')

grouped = features.groupby(['time_step', 'class'])['tx_feat_18'].mean().reset_index()
sns.lineplot(x='time_step', y='tx_feat_18', hue='class', data=grouped, ax = axes[2][1])
plt.legend(loc="upper right")
plt.ylabel('tx_feat_18')

plt.show()

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值