Source code for ads.feature_engineering.feature_type.text
#!/usr/bin/env python# -*- coding: utf-8 -*--# Copyright (c) 2021, 2022 Oracle and/or its affiliates.# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/"""The module that represents a Text feature type.Classes: Text The Text feature type."""importmatplotlib.pyplotaspltimportpandasaspdfromads.feature_engineering.feature_type.stringimportStringfromads.feature_engineering.utilsimportrandom_color_func,SchemeNeutralfromads.commonimportutils,loggerfromads.common.decorator.runtime_dependencyimport(runtime_dependency,OptionalDependency,)
[docs]classText(String):""" Type representing text values. Attributes ---------- description: str The feature type description. name: str The feature type name. warning: FeatureWarning Provides functionality to register warnings and invoke them. validator Provides functionality to register validators and invoke them. Methods -------- feature_plot(x: pd.Series) -> plt.Axes Shows distributions of datasets using wordcloud. """
[docs]@staticmethod@runtime_dependency(module="wordcloud",install_from=OptionalDependency.TEXT)deffeature_plot(x:pd.Series)->plt.Axes:""" Shows distributions of datasets using wordcloud. Examples -------- >>> text = pd.Series(['S', 'C', 'S', 'S', 'S', 'Q', 'S', 'S', 'S', 'C', 'S', 'S', 'S', 'S', 'S', 'S', 'Q', 'S', 'S', '', np.NaN, None], name='text') >>> text.ads.feature_type = ['text'] >>> text.ads.feature_plot() Returns ------- matplotlib.axes._subplots.AxesSubplot Plot object for the series based on the Text feature type. """col_name=x.nameifx.nameelse"text"df=x.to_frame(col_name)words=df[col_name].dropna().to_list()words=" ".join([sforsinwordsifisinstance(s,str)])ifnotwords:returnfromwordcloudimportWordCloudwc=WordCloud(background_color=SchemeNeutral.BACKGROUND_LIGHT,color_func=random_color_func,).generate(words)_,ax=plt.subplots(facecolor=SchemeNeutral.BACKGROUND_LIGHT)ax.imshow(wc)plt.axis("off")returnax