1. 程式人生 > 其它 >異常點分析

異常點分析

import matplotlib.pyplot as plt
import plotly.express as px
import plotly
plotly.offline.init_notebook_mode(connected=True)

bath_room = pd.concat([train["Sold Price"], train["Bathrooms"]], axis=1)

fig, ax = plt.subplots(9, 1, figsize=(30, 80))

fig = px.scatter(bath_room, x="Sold Price", y="Bathrooms")

for i in range(train.shape[0]):

plt.text(train.iloc[i].at['Sold Price'], train.iloc[i].at['Bathrooms'], train.iloc[i].at['Id'])

fig.show()

full_bath_room = pd.concat([train["Sold Price"], train["Full bathrooms"]], axis=1)
fig = px.scatter(full_bath_room, x="Sold Price", y="Full bathrooms")

for i in range(train.shape[0]):

plt.text(train.iloc[i].at['Sold Price'], train.iloc[i].at['Bathrooms'], train.iloc[i].at['Id'])

fig.show()

elementary_school_score = pd.concat([train["Sold Price"], train["Elementary School Score"]], axis=1)
fig = px.scatter(elementary_school_score, x="Sold Price", y="Elementary School Score")

for i in range(train.shape[0]):

plt.text(train.iloc[i].at['Sold Price'], train.iloc[i].at['Bathrooms'], train.iloc[i].at['Id'])

fig.show()

tax_assessed_value = pd.concat([train["Sold Price"], train["Tax assessed value"]], axis=1)
fig = px.scatter(tax_assessed_value, x="Sold Price", y="Tax assessed value")
for i in range(train.shape[0]):
if int(train.iloc[i].at['Sold Price']) > 50 * (10 ** 6):
print(train.iloc[i].at['Id'])
print(train.iloc[i].at['Sold Price'], train.iloc[i].at['Tax assessed value'])

plt.text(train.iloc[i].at['Sold Price'], train.iloc[i].at['Tax assessed value'], train.iloc[i].at['Id'], fontsize=12, verticalalignment='top')

    plt.text(train.iloc[i].at['Sold Price'], train.iloc[i].at['Tax assessed value'], '1')

fig.show()