श्रेणीबद्ध डेटा को अनाम बनाना

Python में डेटा प्राइवेसी और अज्ञातिकरण

Rebeca Gonzalez

Instructor

सामान्यीकरण

    Age    Gender    Department    Condition
0    30    F         Finance       Anxiety disorders
1    42    M         Production    Bronchitis
2    35    F         Marketing     Dysthymia
3    39    F         Production    Dysthymia
4    40    M         Marketing     Flu
    Age    Gender    Department    Condition
0    <40   F         Finance       Anxiety disorders
1    >=40  M         Production    Bronquitis
2    <40   F         Finance       Dysthymia
3    <40   F         Production    Dysthymia
4    >=40  M         Marketing     Flu
Python में डेटा प्राइवेसी और अज्ञातिकरण

श्रेणीबद्ध डेटा का सामान्यीकरण

# See the dataset
hr.head()
    Age    BusinessTravel        Department                EducationField    EmployeeNumber
0    41    Travel_Rarely         Sales                     Life Sciences     1
1    49    Travel_Frequently     Research & Development    Life Sciences     2
2    37    Travel_Rarely         Research & Development    Other             4
3    33    Travel_Frequently     Research & Development    Life Sciences     5
4    27    Travel_Rarely         Research & Development    Medical           7
Python में डेटा प्राइवेसी और अज्ञातिकरण

श्रेणीबद्ध डेटा

संभावित मान सीमित या तय होते हैं.

  • नस्ल
  • लिंग
  • गृह नगर
  • आयु समूह
  • शैक्षिक स्तर
  • पसंदीदा फ़िल्में और प्राथमिकताएँ
Python में डेटा प्राइवेसी और अज्ञातिकरण

श्रेणीबद्ध डेटा को अनाम बनाना

Education Field में श्रेणी मानों का हिस्टोग्राम

Python में डेटा प्राइवेसी और अज्ञातिकरण

श्रेणीबद्ध डेटा को अनाम बनाना

     Department                EducationField
0    Sales                     Life Sciences
1    Research & Development    Life Sciences
2    Research & Development    Other
3    Research & Development    Life Sciences
4    Research & Development    Medical

मूल डेटासेट

     Department                EducationField
0    Sales                     Medical
1    Research & Development    Marketing
2    Research & Development    Life Sciences
3    Research & Development    Other
4    Research & Development    Life Sciences

मूल डेटासेट में educationField कॉलम के प्रायिकता वितरण से सैंपलिंग के बाद प्राप्त डेटासेट.

Python में डेटा प्राइवेसी और अज्ञातिकरण

डेटा से सैंपल लें

U.S. Census नागरिकों के बारे में एकत्र डेटा के सैंपल सार्वजनिक करता है.

बड़े पैमाने के सांख्यिकीय पैटर्न की गणना सक्षम होती है:

  • औसत
  • वैरिएंस
  • क्लस्टर
Python में डेटा प्राइवेसी और अज्ञातिकरण

वितरण देखें

# Show the absolute frequencies of each unique value
hr['EducationField'].value_counts()
Life Sciences       606
Medical             464
Marketing           159
Technical Degree    132
Other                82
Human Resources      27
Name: EducationField, dtype: int64
Python में डेटा प्राइवेसी और अज्ञातिकरण

वितरण देखें

# Generate a bar plot for the categories
df['BusinessTravel'].value_counts().plot(kind='bar')

Business Travel कॉलम में श्रेणी मानों का बार प्लॉट

Python में डेटा प्राइवेसी और अज्ञातिकरण

वितरण देखें

# Obtain the absolute frequencies of each unique value
counts = hr['EducationField'].value_counts()

# Print the list of indexes
print(counts.index)
Index(['Life Sciences', 'Medical', 'Marketing', 
      'Technical Degree', 'Other', 'Human Resources'],
       dtype='object')
Python में डेटा प्राइवेसी और अज्ञातिकरण

वितरण देखें

# Probability distributions of each unique value
counts = df['EducationField'].value_counts(normalize=True)
Life Sciences       0.412245
Medical             0.315646
Marketing           0.108163
Technical Degree    0.089796
Other               0.055782
Human Resources     0.018367
Name: EducationField, dtype: float64
Python में डेटा प्राइवेसी और अज्ञातिकरण

वितरण देखें

# Values of the frequencies of each unique value
df['EducationField'].value_counts(normalize=True).values
array([0.4122449 , 0.31564626, 0.10816327, 0.08979592, 0.05578231,
       0.01836735])
Python में डेटा प्राइवेसी और अज्ञातिकरण

उसी वितरण से सैंपलिंग

# Sample from a probability distribution
hr_sample['EducationField']= np.random.choice(counts.index, 
                                              p=counts.values, 
                                              size=len(hr))


# See resulting dataset hr.head()
    Age    BusinessTravel        Department                EducationField    EmployeeNumber
0    41    Travel_Rarely         Sales                     Life Sciences     1
1    49    Travel_Frequently     Research & Development    Medical           2
2    37    Travel_Rarely         Research & Development    Marketing         4
3    33    Travel_Frequently     Research & Development    Technical Degree  5
4    27    Travel_Rarely         Research & Development    Medical           7
Python में डेटा प्राइवेसी और अज्ञातिकरण

उसी वितरण से सैंपलिंग

# Show the absolute frequencies of each category
hr['EducationField'].value_counts()
Life Sciences       606
Medical             464
Marketing           159
Technical Degree    132
Other                82
Human Resources      27
Name: EducationField, dtype: int64
# Show the frequencies of the resulting column
hr_sample['EducationField'].value_counts()
Life Sciences       604
Medical             493
Marketing           158
Technical Degree    120
Other                61
Human Resources      34
Name: EducationField, dtype: int64
Python में डेटा प्राइवेसी और अज्ञातिकरण

अभ्यास करते हैं!

Python में डेटा प्राइवेसी और अज्ञातिकरण

Preparing Video For Download...