Chuẩn bị bảng biểu đồ insight của biến dự đoán

Nhập môn Phân tích Dự đoán với Python

Nele Verbiest, Ph.D

Data Scientist @PythonPredictions

Bảng biểu đồ insight của biến dự đoán

disc_mean_gift Tần suất Quy mô
[2, 78] 0.013042 20013
(78, 87] 0.029554 19997
(87, 94] 0.040831 20034
(94, 103] 0.063563 20405
(103, 197] 0.103524 19551
Nhập môn Phân tích Dự đoán với Python

Tính bảng biểu đồ insight của biến dự đoán

# Load the numpy module
import numpy as np
# Function that calculates the predictor insight graph table
def create_pig_table(df, target, variable):

# Group by the variable you want to plot groups = df[[target,variable]].groupby(variable)
# Calculate the size and incidence of each group pig_table = groups[target].agg(Incidence = 'mean').reset_index() return pig_table
print(create_pig_table(basetable,"target","country")
country    Incidence    Size
India    0.050934    49849
UK    0.050512    10057
USA    0.048486    40094
Nhập môn Phân tích Dự đoán với Python

Tính nhiều bảng biểu đồ insight của biến dự đoán

variables = ["country", "gender", "disc_mean_gift", "age"]

# Empty dictionary. pig_tables = {}
# Loop over all variables for variable in variables:
# Create the predictor insight graph table pig_table = create_pig_table(basetable, "target", variable)
# Store the table in the dictionary pig_tables[variable] = pig_table
print(create_pig_table(basetable,"target","country")
country    Incidence    Size
India    0.050934    49849
UK    0.050512    10057
USA    0.048486    40094
Nhập môn Phân tích Dự đoán với Python

Cùng luyện tập nào!

Nhập môn Phân tích Dự đoán với Python

Preparing Video For Download...