class_docstr: The StringSimilarityEncoder() replaces categorical variables with a set of float
  variables that capture the similarity between the category names. The new variables
  have values between 0 and 1, where 0 indicates no similarity and 1 is an exact
  match between the names of the categories.
  
  The similarity measure is a float in the range [0, 1]. It is defined as 2 * M / T,
  where T is the total number of elements in both categories being compared, and M is
  the number of matches. Note that this is 1 if the sequences are identical, and 0 if
  they have nothing in common.
  
  For example, the similarity between the categories "dog" and "dig" is 0.66. T is the
  total number of elements in both categories, that is 6. There are 2 matches between
  the words, the letters d and g, so: 2 * M / T = 2 * 2 / 6 = 0.66.
  
  This encoding is similar to one-hot encoding, in the sense that each category is
  encoded as a new variable. But the values, instead of 1 or 0, are the similarity
  between the observation's category and the dummy variable.
  
  For example, if a variable has 3 categories, dog, dig and cat,
  StringSimilarityEncoder() will create 3 new variables, var_dog, var_dig and var_cat
  and the values would be for the observation dog: 1, 0.66 , 0. For the observation
  dig they would be 0.66, 1, 0. And for cat, they would be 0, 0, 1.
  
  The encoder has the option to generate similarity variables only  for the most
  popular categories, that is, the categories present in most observations. This
  behaviour can be specified with the parameter `top_categories`.
  
  **Missing values**
  
  StringSimilarityEncoder() will rreplace missing data with an empty string and
  then return the similarity to the remaining variables by default. Alternatively,
  it can be set to return an error if the variable has missing values, or to ignore
  them.
  
  **Unseen categories**
  
  StringSimilarityEncoder() handles unseen categories out-of-the-box by assigning a
  similarity measure to the other categories that were seen during `fit()`.
  
  **Categorical variables**
  
  The encoder will encode only categorical variables by default (type 'object' or
  'categorical'). You can pass a list of variables to encode. Alternatively, the
  encoder will find and encode all categorical variables.
  
  **Numerical variables**
  
  With `ignore_format=True` you have the option to encode numerical variables as well.
  Encoding numerical variables with similarity measures make sense for example for
  variables like barcodes. In this case, you can either enter the list of variables
  to encode (recommended), or the transformer will automatically select all variables.
  
  More details in the :ref:`User Guide <string_similarity>`.
  
  Parameters
  ----------
  top_categories: int, default=None
      If None, dummy variables will be created for each unique category of the
      variable. Alternatively, we can indicate in the number of most frequent
      categories to encode. In this case, similarity variables will be created
      only for those popular categories.
  
  missing_values: str, default='impute'
      Indicates if missing values should be ignored, raised or imputed. If 'raise' the
      transformer will return an error if the datasets to `fit` or `transform`
      contain missing values. If 'ignore', missing data will be ignored when learning
      parameters or performing the transformation. If 'impute', the transformer will
      replace missing values with an empty string, '', and then return the similarity
      measures.
  
  keywords: dict, default=None
      Dictionary with a set of keywords to be used to create the similarity variables.
      The format should be: dict(feature: [keyword1, keyword2, ...]). The encoder will
      use these keywords to create the similarity variables. The dictionary can be
      defined for all the features to encode, or only for a subset of them. In this
      case, for the features not specified in the dictionary, the encoder will
      identify the categories from the data.
  
  {variables}
  
  {ignore_format}
  
  Attributes
  ----------
  encoder_dict_:
      Dictionary with the categories for which dummy variables will be created.
  
  {variables_}
  
  {feature_names_in_}
  
  {n_features_in_}
  
  Methods
  -------
  fit:
      Learn the unique categories per variable.
  
  {fit_transform}
  
  transform:
      Replace the categorical variables by the distance variables.
  
  Notes
  -----
  This encoder will encode unseen categories by measuring string similarity between
  seen and unseen categories.
  
  No text preprocessing is applied before calculating the similarity.
  
  The original categorical variables are removed from the returned dataset after the
  transformation. In their place, the binary variables are returned.
  
  See Also
  --------
  feature_engine.encoding.OneHotEncoder
  dirty_cat.SimilarityEncoder
  
  References
  ----------
  .. [1] Cerda P, Varoquaux G, Kégl B. "Similarity encoding for learning with dirty
     categorical variables". Machine Learning, Springer Verlag, 2018.
  .. [2] Cerda P, Varoquaux G. "Encoding high-cardinality string categorical
     variables". IEEE Transactions on Knowledge & Data Engineering, 2020.
  
  Examples
  --------
  
  >>> import pandas as pd
  >>> from feature_engine.encoding import StringSimilarityEncoder
  >>> X = pd.DataFrame(dict(x1 = [1,2,3,4], x2 = ["dog", "dig", "dagger", "hi"]))
  >>> sse = StringSimilarityEncoder()
  >>> sse.fit(X)
  >>> sse.transform(X)
     x1    x2_dog    x2_dig  x2_dagger  x2_hi
  0   1  1.000000  0.666667   0.444444    0.0
  1   2  0.666667  1.000000   0.444444    0.4
  2   3  0.444444  0.444444   1.000000    0.0
  3   4  0.000000  0.400000   0.000000    1.0
class_docstr_tok: ["The","StringSimilarityEncoder","(",")","replaces","categorical","variables","with","a","set","of","float","variables","that","capture","the","similarity","between","the","category","names",".","The","new","variables","have","values","between","0","and","1",",","where","0","indicates","no","similarity","and","1","is","an","exact","match","between","the","names","of","the","categories",".","The","similarity","measure","is","a","float","in","the","range","[","0",",","1","]",".","It","is","defined","as","2","*","M","\/","T",",","where","T","is","the","total","number","of","elements","in","both","categories","being","compared",",","and","M","is","the","number","of","matches",".","Note","that","this","is","1","if","the","sequences","are","identical",",","and","0","if","they","have","nothing","in","common",".","For","example",",","the","similarity","between","the","categories","``","dog","''","and","``","dig","''","is","0.66",".","T","is","the","total","number","of","elements","in","both","categories",",","that","is","6",".","There","are","2","matches","between","the","words",",","the","letters","d","and","g",",","so",":","2","*","M","\/","T","=","2","*","2","\/","6","=","0.66",".","This","encoding","is","similar","to","one-hot","encoding",",","in","the","sense","that","each","category","is","encoded","as","a","new","variable",".","But","the","values",",","instead","of","1","or","0",",","are","the","similarity","between","the","observation","'s","category","and","the","dummy","variable",".","For","example",",","if","a","variable","has","3","categories",",","dog",",","dig","and","cat",",","StringSimilarityEncoder","(",")","will","create","3","new","variables",",","var_dog",",","var_dig","and","var_cat","and","the","values","would","be","for","the","observation","dog",":","1",",","0.66",",","0",".","For","the","observation","dig","they","would","be","0.66",",","1",",","0",".","And","for","cat",",","they","would","be","0",",","0",",","1",".","The","encoder","has","the","option","to","generate","similarity","variables","only","for","the","most","popular","categories",",","that","is",",","the","categories","present","in","most","observations",".","This","behaviour","can","be","specified","with","the","parameter","`","top_categories","`",".","*","*","Missing","values","*","*","StringSimilarityEncoder","(",")","will","rreplace","missing","data","with","an","empty","string","and","then","return","the","similarity","to","the","remaining","variables","by","default",".","Alternatively",",","it","can","be","set","to","return","an","error","if","the","variable","has","missing","values",",","or","to","ignore","them",".","*","*","Unseen","categories","*","*","StringSimilarityEncoder","(",")","handles","unseen","categories","out-of-the-box","by","assigning","a","similarity","measure","to","the","other","categories","that","were","seen","during","`","fit","(",")","`",".","*","*","Categorical","variables","*","*","The","encoder","will","encode","only","categorical","variables","by","default","(","type","'object","'","or","'categorical","'",")",".","You","can","pass","a","list","of","variables","to","encode",".","Alternatively",",","the","encoder","will","find","and","encode","all","categorical","variables",".","*","*","Numerical","variables","*","*","With","`","ignore_format=True","`","you","have","the","option","to","encode","numerical","variables","as","well",".","Encoding","numerical","variables","with","similarity","measures","make","sense","for","example","for","variables","like","barcodes",".","In","this","case",",","you","can","either","enter","the","list","of","variables","to","encode","(","recommended",")",",","or","the","transformer","will","automatically","select","all","variables",".","More","details","in","the",":","ref",":","`","User","Guide","<","string_similarity",">","`",".","Parameters","--","--","--","--","--","top_categories",":","int",",","default=None","If","None",",","dummy","variables","will","be","created","for","each","unique","category","of","the","variable",".","Alternatively",",","we","can","indicate","in","the","number","of","most","frequent","categories","to","encode",".","In","this","case",",","similarity","variables","will","be","created","only","for","those","popular","categories",".","missing_values",":","str",",","default='impute'","Indicates","if","missing","values","should","be","ignored",",","raised","or","imputed",".","If","'raise","'","the","transformer","will","return","an","error","if","the","datasets","to","`","fit","`","or","`","transform","`","contain","missing","values",".","If","'ignore","'",",","missing","data","will","be","ignored","when","learning","parameters","or","performing","the","transformation",".","If","'impute","'",",","the","transformer","will","replace","missing","values","with","an","empty","string",",","``",",","and","then","return","the","similarity","measures",".","keywords",":","dict",",","default=None","Dictionary","with","a","set","of","keywords","to","be","used","to","create","the","similarity","variables",".","The","format","should","be",":","dict","(","feature",":","[","keyword1",",","keyword2",",","...","]",")",".","The","encoder","will","use","these","keywords","to","create","the","similarity","variables",".","The","dictionary","can","be","defined","for","all","the","features","to","encode",",","or","only","for","a","subset","of","them",".","In","this","case",",","for","the","features","not","specified","in","the","dictionary",",","the","encoder","will","identify","the","categories","from","the","data",".","{","variables","}","{","ignore_format","}","Attributes","--","--","--","--","--","encoder_dict_",":","Dictionary","with","the","categories","for","which","dummy","variables","will","be","created",".","{","variables_","}","{","feature_names_in_","}","{","n_features_in_","}","Methods","--","--","--","-","fit",":","Learn","the","unique","categories","per","variable",".","{","fit_transform","}","transform",":","Replace","the","categorical","variables","by","the","distance","variables",".","Notes","--","--","-","This","encoder","will","encode","unseen","categories","by","measuring","string","similarity","between","seen","and","unseen","categories",".","No","text","preprocessing","is","applied","before","calculating","the","similarity",".","The","original","categorical","variables","are","removed","from","the","returned","dataset","after","the","transformation",".","In","their","place",",","the","binary","variables","are","returned",".","See","Also","--","--","--","--","feature_engine.encoding.OneHotEncoder","dirty_cat.SimilarityEncoder","References","--","--","--","--","--","..","[","1","]","Cerda","P",",","Varoquaux","G",",","K\u00e9gl","B",".","``","Similarity","encoding","for","learning","with","dirty","categorical","variables","''",".","Machine","Learning",",","Springer","Verlag",",","2018",".","..","[","2","]","Cerda","P",",","Varoquaux","G.","``","Encoding","high-cardinality","string","categorical","variables","''",".","IEEE","Transactions","on","Knowledge","&","Data","Engineering",",","2020",".","Examples","--","--","--","--",">",">",">","import","pandas","as","pd",">",">",">","from","feature_engine.encoding","import","StringSimilarityEncoder",">",">",">","X","=","pd.DataFrame","(","dict","(","x1","=","[","1,2,3,4","]",",","x2","=","[","``","dog","''",",","``","dig","''",",","``","dagger","''",",","``","hi","''","]",")",")",">",">",">","sse","=","StringSimilarityEncoder","(",")",">",">",">","sse.fit","(","X",")",">",">",">","sse.transform","(","X",")","x1","x2_dog","x2_dig","x2_dagger","x2_hi","0","1","1.000000","0.666667","0.444444","0.0","1","2","0.666667","1.000000","0.444444","0.4","2","3","0.444444","0.444444","1.000000","0.0","3","4","0.000000","0.400000","0.000000","1.0"]
docstr: Creates new features names and removes original categorical variables.
docstr_tok: ["Creates","new","features","names","and","removes","original","categorical","variables","."]
code: def _add_new_feature_names(
      self, feature_names: List[str]
  ) -> List[str]:
      """Creates new features names and removes original categorical variables."""
      feature_names = feature_names + self._get_new_features_name()
      feature_names = [
          f for f in feature_names if f not in self.variables_
      ]
  
      return feature_names
  
imports: from difflib import SequenceMatcher
  from typing import Optional, Union, List
  import numpy
  import pandas
  from sklearn.utils.validation import check_is_fitted
  from feature_engine._docstrings.fit_attributes import _feature_names_in_docstring, _n_features_in_docstring, _variables_attribute_docstring
  from feature_engine._docstrings.init_parameters import _ignore_format_docstring, _variables_categorical_docstring
  from feature_engine._docstrings.methods import _fit_transform_docstring
  from feature_engine._docstrings.substitute import Substitution
  from feature_engine.dataframe_checks import _check_contains_na, check_X
  from feature_engine.encoding.base_encoder import CategoricalInitMixin, CategoricalMethodsMixin
label_desc: Use image node_id 5 for calling the StringSimilarityEncoder obj's underlying member method code with example usage: obj._add_new_feature_names(feature_names) and returns: feature_names