Example code for creating features from time series data, such as lag features and window features? 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.timeseries.forecasting import LagFeatures # create range of monthly dates download_dates = pd.date_range(start=’2019-01-01′, end=’2020-01-01′, freq=’MS’) # URL from ..
Category : Python
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 code for handling outlier with 3 methods of feature-engine. Winsorizer Caps maximum and/or minimum values of a variable at automatically determined values.[ref:https://feature-engine.readthedocs.io/en/latest/user_guide/outliers/Winsorizer.html] 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.outliers import Winsorizer # Load dataset def load_titanic(): data = pd.read_csv(‘https://www.openml.org/data/get_csv/16826755/phpMYEkMl’) data = data.replace(‘?’, ..
The sample code shows you how to encode categorical data and answer the following questions: One hot encoder Replaces the categorical variable by a group of binary variables which take value 0 or 1, to indicate if a certain category is present in an observation. Example code import numpy as np import pandas as pd ..
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 ..
The following example shows you how to draw multiple subplots with different widths and heights. It also tells you the answers to some other questions. How to do technical analysis of a stock? How to draw double y-axis plot? How to set height of a subplot? import numpy as np import talib import emoji import ..
The first step in using stock data for financial analysis is to download price data from yahoo Finance. Below is a very simple example for downloading data. import yfinance as yf import pandas as pd startDay=”2020-06-18″ endDay=”2020-06-20″ fnlist=’nasdqIntheUSAMostActiveStocks.txt’ #symbols fns=pd.read_csv(fnlist) toPath=’NASDQ/’ for fn0 in fns.Symbols: stockName=fn0.replace(‘ ‘,”) toFile=toPath+stockName+’.csv’ toFile=toFile.replace(‘ ‘,”) data = yf.download(stockName, start=startDay, end=endDay) ..
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? ..