<jupyter_start><jupyter_text>Experimental Comparison Between FastGradRidgeLogit And Sklearn  About Data Data Name:  SPAM E-mail Data Description:Number of Instances: 4601 (1813 Spam = 39.4%)Number of Attributes: 58 (57 continuous, 1 nominal class label)The last column of 'spambase.data' denotes whether the e-mail was considered spam (1) or not (0)To explore full documentation of the data set, please check [https://statweb.stanford.edu/~tibs/ElemStatLearn/datasets/spam.info.txt](https://statweb.stanford.edu/~tibs/ElemStatLearn/datasets/spam.info.txt) Data Process Before Model Training<jupyter_code>import pandas as pd
import numpy as np
import sklearn.preprocessing

spam = pd.read_table('https://statweb.stanford.edu/~tibs/ElemStatLearn/datasets/spam.data', sep=' ', header=None)
test_indicator = pd.read_table('https://statweb.stanford.edu/~tibs/ElemStatLearn/datasets/spam.traintest', sep=' ',
                               header=None)

x = np.asarray(spam)[:, 0:-1]
y = np.asarray(spam)[:, -1]*2 - 1  # Convert to +/- 1
test_indicator = np.array(test_indicator).T[0]

# Divide the data into train, test sets
x_train = x[test_indicator == 0, :]
x_test = x[test_indicator == 1, :]
y_train = y[test_indicator == 0]
y_test = y[test_indicator == 1]

# Standardize the data. 
scaler = sklearn.preprocessing.StandardScaler()
scaler.fit(x_train)
x_train = scaler.transform(x_train)
x_test = scaler.transform(x_test)<jupyter_output><empty_output><jupyter_text>Train Model Using FastGradRidgeLogit<jupyter_code>from fgrlogit import FastGradRidgeLogit

fg = FastGradRidgeLogit()
fg.fit(lambduh = 0.1,x = x_train,y = y_train)<jupyter_output>Start fast gradient descent:
Fast gradient iteration 100
Fast gradient iteration 200
Fast gradient iteration 300<jupyter_text>Compare Results With Sklearn**Beta**Beta values of FastGradRidgeLogit at the last iteration:<jupyter_code>fg.opt_betas<jupyter_output><empty_output><jupyter_text>Sklearn result:<jupyter_code>import sklearn.linear_model

lambduh = 0.1
n_train = len(y_train)

lr = sklearn.linear_model.LogisticRegression(penalty='l2', C=1/(2*lambduh*n_train), fit_intercept=False, tol=10e-8, max_iter=1000)
lr.fit(x_train, y_train)
print(lr.coef_)<jupyter_output>[[ 0.02117345 -0.03877587  0.09773771  0.05503819  0.15256401  0.13534366
   0.28352681  0.15114461  0.11280873  0.06183421  0.10502022 -0.04219962
   0.03472887  0.02859174  0.10917878  0.27363777  0.17373109  0.12517347
   0.1290986   0.12243222  0.2240522   0.10833277  0.24549208  0.16655949
  -0.14754037 -0.10493049 -0.1149898  -0.06087818 -0.04741795 -0.06626914
  -0.02882511 -0.0151532  -0.07621369 -0.0159425  -0.04245255 -0.01357162
  -0.07700499 -0.03415877 -0.07954035  0.01733619 -0.04772964 -0.09082759
  -0.06004341 -0.06969745 -0.11271606 -0.11263913 -0.0321344  -0.06206727
  -0.05727232 -0.0425365  -0.02823825  0.15484338  0.26205747  0.05893876
   0.06871901  0.12509356  0.14818851]]<jupyter_text>**Objective value:**Objective value of FastGradRidgeLogit:<jupyter_code>fg.objective(beta = fg.opt_betas, lambduh = 0.1, x = x_train, y = y_train)<jupyter_output><empty_output><jupyter_text>Objective value of sklearn:<jupyter_code>fg.objective(beta = lr.coef_.flatten(), lambduh = 0.1, x = x_train, y = y_train)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12133251833740831, 'fraction_numerical': 0.171760391198044, 'mean_word_length': 4.9945054945054945, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '244013', 'license': 'MIT', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1322, 'n_words': 247, 'path': 'Experimental Comparison to Sklearn.ipynb', 'repo_name': 'wangbeiqi199159/fast-gradient-logit', 'size': '3272'}