当引用 grid_search 的 param_grid 中的 ColumnTransformer (它是管道的一部分)中包含的单个预处理器时,我想找出正确的命名约定。
环境和样本数据:
import seaborn as sns
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder, KBinsDiscretizer, MinMaxScaler
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
df = sns.load_dataset('titanic')[['survived', 'age', 'embarked']]
X_train, X_test, y_train, y_test = train_test_split(df.drop(columns='survived'), df['survived'], test_size=0.2,
random_state=123)
Run Code Online (Sandbox Code Playgroud)
管道:
num = ['age']
cat = ['embarked']
num_transformer = Pipeline(steps=[('imputer', SimpleImputer()),
('discritiser', KBinsDiscretizer(encode='ordinal', strategy='uniform')),
('scaler', MinMaxScaler())])
cat_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='constant', fill_value='missing')),
('onehot', OneHotEncoder(handle_unknown='ignore'))])
preprocessor = ColumnTransformer(transformers=[('num', num_transformer, …Run Code Online (Sandbox Code Playgroud) 有许多资源可以解释为什么%matplotlib inline需要内联显示图。例如%matplotlib inline 的目的。但是,我觉得如果我们在您的 Jupyter Notebook 中使用更高版本的 IPython,则不再需要。这是因为我可以在运行或不运行的情况下内嵌显示图%matplotlib inline(每次我重新启动内核时,我使用的 IPython 版本是 7.17.0)。我的预感是,最近版本可能默认激活内联后端。
当我运行%matplotlib以检查新会话的当前后端时,它显示Qt5Agg。运行后%matplotlib inline,当我通过运行再次检查时%matplotlib,它显示相同的Qt5Agg。这让我认为这%matplotlib inline是多余的,因为它没有改变任何东西。顺便说一句,我自己没有更改任何 IPython 配置。
但是,我没有看到任何官方文档说默认情况下会为 IPython 版本 xxx+ 激活内联后端。我发现这个和这个Github 问题与我试图找到的很接近,但它没有完全确认“%matplotlib inline如果你的 IPython 版本是 xxx+,你不再需要运行,因为它是默认行为”。我查看了 IPython 最近的发行说明,但似乎没有证实这个假设。
我的预感对吗?如果是这样,不需要哪些 IPython 版本?有没有官方文件这么说?如果没有,我怎么能在不运行的情况下进行内联绘图%matplotlib inline?
这可能看起来像是在我的 jupyter 笔记本中为什么不需要“%matplotlib inline”的可能重复?. 我无法从这个线程中确认我的预感。