Example code to transform continuous numerical variables into discrete variables with different methods. It cab also answer the following questions. Prepare data and load functions Code import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from feature_engine.discretisation import EqualFrequencyDiscretiser from feature_engine.discretisation import EqualWidthDiscretiser from feature_engine.discretisation import ArbitraryDiscretiser from ..
Tag : Python
Example code for creating and adding new features to a data frame using the feature-engine. It also answer following questions: Math features Code import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from feature_engine.creation import MathFeatures from feature_engine.creation import RelativeFeatures from feature_engine.creation import CyclicalFeatures # create range of ..
Example code about how to extract several date and time features from datetime variables with feature-engine. It can answer following questions: import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from feature_engine import transformation as vt # create range of monthly dates download_dates = pd.date_range(start=’2019-01-01′, end=’2020-01-01′, freq=’MS’) # ..
Example code for log,reciprocal,arcsin ,power transformers of feature-engine. You can find answer to the following question as well: import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split from feature_engine import transformation as vt # Load dataset # create range of monthly dates download_dates = pd.date_range(start=’2019-01-01′, end=’2020-01-01′, freq=’MS’) # ..
Example python code for handling missing data (ref:Python feature engineering cookbook ). Also answer the following questions: import pandas as pd from sklearn.model_selection import train_test_split from sklearn.impute import SimpleImputer from feature_engine.missing_data_imputers import MeanMedianImputer from feature_engine.imputation import ArbitraryNumberImputer from feature_engine.imputation import EndTailImputer from feature_engine.imputation import CategoricalImputer from feature_engine.imputation import RandomSampleImputer from feature_engine.imputation import AddMissingIndicator from feature_engine.imputation ..
Sample code for multiple-level treemap generation.This example also includes some methods on pandas data processing, such as: How to create a pandas dataframe? How to append several dataframe to construct a bigger dataframe? How to build a hierarchical dataframe? import pandas as pd import numpy as np import plotly.express as px import plotly.graph_objects as go ..
We often need to draw multiple similar maps using the same colorbar. A good way is to use the AxesGrid from the Cartopy package. Below is one of my examples of sharing colorbars for 4 submaps. This example can also answer other questions: How to add ocean, river, lakes,coastline and province border to a map? ..
The following python program show you the method to draw a rectangular area in a map and mark state or province name on the map. Answer to other questions: How to add ocean, lake, river, coastline, province border to map? How to set map extent? How to set xtick or ytick intervals? # Ignore warnings ..
A very very very beautiful Chinese ink and wash painting of a long shot view of sunrise shining through gaps of painted clouds over precipitous mountains with rugged cliffs and shere peaks of strange shape stones along a winding river full of clear clean transparent crystal blue water and covered by evergreen trees and scattered ..
Ignore warnings # Ignore warnings import sys import warnings if not sys.warnoptions: warnings.simplefilter(‘ignore’) Ignore some errors # function FN does not work when there are nan in X try: mktest=FN(X) trend=mktest except: trend=np.nan From my original code:Indexes_ERA5_GreatLakesRegion_sens_s..