# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.7 ('base')
#     language: python
#     name: python3
# ---

# +
# import required packages
import pandas as pd

import statsmodels.api as sm
# -

# read the data
df = pd.read_csv('D:\\Password-Analysis\\Datasets\\top_200_password_2020_by_country_extended.csv')
df.head()

# creating dummy variables for country column since it is categorical data
df = pd.get_dummies(df, columns=['country'])

df.columns

# ## Linear Model for Length Attribute

# defining the X and Y 
x_length = df[['country_China', 'country_Russia', 'country_Spain',
       'country_United States', 'country_Vietnam']]
y_length = df['length']

# ### Linear Model with Standard Errors

# +
# adding the constant term
x_length = sm.add_constant(x_length)
  
# performing the regression and fitting the model
length_model_fit_1 = sm.WLS(y_length, x_length, df['User_count']).fit()
  
# printing the summary table
print(length_model_fit_1.summary())
# -

# ### Linear Model with Robust Standard Errors

# +
# adding the constant term
x_length = sm.add_constant(x_length)
  
# performing the regression and fitting the model
length_model_fit_2 = sm.WLS(y_length, x_length, df['User_count']).fit(cov_type='HC3')
  
# printing the summary table
print(length_model_fit_2.summary())
# -

# ## Linear model for Unique Characters Attribute

# defining the X and Y 
x_unique_chars = df[['country_China', 'country_Russia', 'country_Spain',
       'country_United States', 'country_Vietnam']]
y_unique_chars = df['unique_chars']

# ### Linear Model with Standard Errors

# +
# adding the constant term
x_unique_chars = sm.add_constant(x_unique_chars)
  
# performing the regression and fitting the model
unique_chars_model_fit_1 = sm.WLS(y_unique_chars, x_unique_chars, df['User_count']).fit()
  
# printing the summary table
print(unique_chars_model_fit_1.summary())
# -

# ### Linear Model with Robust Standard Errors

# +
# adding the constant term
x_unique_chars = sm.add_constant(x_unique_chars)
  
# performing the regression and fitting the model
unique_chars_model_fit_2 = sm.WLS(y_unique_chars, x_unique_chars, df['User_count']).fit(cov_type='HC3')
  
# printing the summary table
print(unique_chars_model_fit_2.summary())
# -

# ## Linear Model for Number of #s Attribute

# defining the X and Y 
x_numbers = df[['country_China', 'country_Russia', 'country_Spain',
       'country_United States', 'country_Vietnam']]
y_numbers = df['numbers']

# ### Linear Model with Standard Errors

# +
# adding the constant term
x_numbers = sm.add_constant(x_numbers)
  
# performing the regression and fitting the model
numbers_model_fit_1 = sm.WLS(y_numbers, x_numbers, df['User_count']).fit()
  
# printing the summary table
print(numbers_model_fit_1.summary())
# -

# ### Linear Model with Robust Standard Errors

# +
# adding the constant term
x_numbers = sm.add_constant(x_numbers)
  
# performing the regression and fitting the model
numbers_model_fit_2 = sm.WLS(y_numbers, x_numbers, df['User_count']).fit(cov_type='HC3')
  
# printing the summary table
print(numbers_model_fit_2.summary())
# -

# ## Linear Model for Sequentials Attribute

# defining the X and Y 
x_sequentials = df[['country_China', 'country_Russia', 'country_Spain',
       'country_United States', 'country_Vietnam']]
y_sequentials = df['sequentials']

# ### Linear Model with Standard Errors

# +
# adding the constant term
x_sequentials = sm.add_constant(x_sequentials)
  
# performing the regression and fitting the model
sequentials_model_fit_1 = sm.WLS(y_sequentials, x_sequentials, df['User_count']).fit()
  
# printing the summary table
print(sequentials_model_fit_1.summary())
# -

# ### Linear Model with Robust Standard Errors

# +
# adding the constant term
x_sequentials = sm.add_constant(x_sequentials)
  
# performing the regression and fitting the model
sequentials_model_fit_2 = sm.WLS(y_sequentials, x_sequentials, df['User_count']).fit(cov_type='HC3')
  
# printing the summary table
print(sequentials_model_fit_2.summary())

StarcoderdataJupyterScriptsDedupFiltered