Using statistics to define normal behavior
In the previous exercises we saw that fraud is more prevalent in certain transaction categories, but that there is no obvious way to segment our data into for example age groups. This time, let's investigate the average amounts spend in normal transactions versus fraud transactions. This gives you an idea of how fraudulent transactions differ structurally from normal transactions.
本练习是课程的一部分
Fraud Detection in Python
练习说明
- Create two new dataframes from fraud and non-fraud observations. Locate the data in
dfwith.locand assign the condition "where fraud is 1" and "where fraud is 0" for creation of the new dataframes. - Plot the
amountcolumn of the newly created dataframes in the histogram plot functions and assign the labelsfraudandnonfraudrespectively to the plots.
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create two dataframes with fraud and non-fraud data
df_fraud = df.____[df.____ == ____]
df_non_fraud = df.____[df.____ == ____]
# Plot histograms of the amounts in fraud and non-fraud data
plt.hist(____.____, alpha=0.5, label='____')
plt.hist(____.____, alpha=0.5, label='____')
plt.legend()
plt.show()