How are feature_importances in RandomForestClassifier determined?

There are indeed several ways to get feature “importances”. As often, there is no strict consensus about what this word means. In scikit-learn, we implement the importance as described in [1] (often cited, but unfortunately rarely read…). It is sometimes called “gini importance” or “mean decrease impurity” and is defined as the total decrease in … Read more

Parameter “stratify” from method “train_test_split” (scikit Learn)

This stratify parameter makes a split so that the proportion of values in the sample produced will be the same as the proportion of values provided to parameter stratify. For example, if variable y is a binary categorical variable with values 0 and 1 and there are 25% of zeros and 75% of ones, stratify=y … Read more

How can I plot a confusion matrix? [duplicate]

you can use plt.matshow() instead of plt.imshow() or you can use seaborn module’s heatmap (see documentation) to plot the confusion matrix import seaborn as sn import pandas as pd import matplotlib.pyplot as plt array = [[33,2,0,0,0,0,0,0,0,1,3], [3,31,0,0,0,0,0,0,0,0,0], [0,4,41,0,0,0,0,0,0,0,1], [0,1,0,30,0,6,0,0,0,0,1], [0,0,0,0,38,10,0,0,0,0,0], [0,0,0,3,1,39,0,0,0,0,4], [0,2,2,0,4,1,31,0,0,0,2], [0,1,0,0,0,0,0,36,0,2,0], [0,0,0,0,0,0,1,5,37,5,1], [3,0,0,0,0,0,0,0,0,39,0], [0,0,0,0,0,0,0,0,0,0,38]] df_cm = pd.DataFrame(array, index = [i for i in … Read more

What is exactly sklearn.pipeline.Pipeline?

Transformer in scikit-learn – some class that have fit and transform method, or fit_transform method. Predictor – some class that has fit and predict methods, or fit_predict method. Pipeline is just an abstract notion, it’s not some existing ml algorithm. Often in ML tasks you need to perform sequence of different transformations (find set of … Read more

Can anyone explain me StandardScaler?

Intro I assume that you have a matrix X where each row/line is a sample/observation and each column is a variable/feature (this is the expected input for any sklearn ML function by the way — X.shape should be [number_of_samples, number_of_features]). Core of method The main idea is to normalize/standardize i.e. μ = 0 and σ … Read more

How to convert a Scikit-learn dataset to a Pandas dataset

Manually, you can use pd.DataFrame constructor, giving a numpy array (data) and a list of the names of the columns (columns). To have everything in one DataFrame, you can concatenate the features and the target into one numpy array with np.c_[…] (note the []): import numpy as np import pandas as pd from sklearn.datasets import … Read more

RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility

According to MAINT: silence Cython warnings about changes dtype/ufunc size. – numpy/numpy: These warnings are visible whenever you import scipy (or another package) that was compiled against an older numpy than is installed. and the checks are inserted by Cython (hence are present in any module compiled with it). Long story short, these warnings should … Read more

what is the difference between ‘transform’ and ‘fit_transform’ in sklearn

In scikit-learn estimator api, fit() : used for generating learning model parameters from training data transform() : parameters generated from fit() method,applied upon model to generate transformed data set. fit_transform() : combination of fit() and transform() api on same data set Checkout Chapter-4 from this book & answer from stackexchange for more clarity