<commit_before>from sklearn.base import TransformerMixin, BaseEstimator
import numpy as np
import scipy as sp
from scipy.misc import comb
from scipy.sparse import csr_matrix, coo_matrix
from code import interact

"""
For John:

The new mappings don't contain D.
Could you aso do first and second degrees to include the diagonal?


"""

"""
1. Create the feature matrix, include the original matrix in it - the rest will start out all zeros.
2. Iterate with as many nested loops as needed. This is the part that will have a different method for each degree.
"""


"""

(0, 1) = 0
(0, 2) = 1
(1, 2) = 2
(0, 3) = 3

x 0 1 3
x x 2 4
x x x 5
x x x x


we want

0 1 3 6
x 2 4 7
x x 5 8
x x x 9

"""

class SparsePolynomialFeatures(TransformerMixin, BaseEstimator):
    def __init__(self, degree, interaction_only=False, include_bias=False):
    
        if degree > 3:
            raise Exception("SparsePolynomialFeatures currently supports degrees of 2 or 3.")
            
        self.degree = degree
        self.interaction_only = interaction_only
        self.include_bias = include_bias<commit_msg>added 2 and 3 deg poly<commit_after>from sklearn.base import TransformerMixin, BaseEstimator
import numpy as np
import scipy as sp
from scipy.misc import comb
from scipy.sparse import csr_matrix, coo_matrix
from code import interact

#TODO add include_bias support

class SparsePolynomialFeatures(TransformerMixin, BaseEstimator):
    def __init__(self, degree, interaction_only=False, include_bias=False):
    
        if degree > 3:
            raise Exception("SparsePolynomialFeatures currently supports degrees of 2 or 3.")
            
        self.degree = degree
        self.interaction_only = interaction_only
        self.include_bias = include_bias
{'fraction_non_alphanumeric': 0.06363636363636363, 'fraction_numerical': 0.02159090909090909, 'mean_word_length': 3.3374384236453203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '6770351', 'n_tokens_mistral': 568, 'n_tokens_neox': 524, 'n_words': 218}