Comments (5)
feature_names_out
is part of the upcoming v1.1 release of sklearn (see https://scikit-learn.org/dev/modules/generated/sklearn.preprocessing.FunctionTransformer.html and scikit-learn/scikit-learn@d23d589) and not yet available if you use the latest official release.
from handson-ml3.
Hi @ageron , Thanks a lot for the update.
from handson-ml3.
I have tried to use python3.8 too still I get the same exception
from handson-ml3.
Many thanks @FriedrichFroebel , After upgrading the sklearn I was able to run the code.
However I encountered another error now.
Error rise in this line
print(preprocessing.get_feature_names_out())
Exception
Traceback (most recent call last):
File "F:\****\Python Projects\ML-Book-Practice\CHAPTER2-END_TO_END_PROJECT\final-example.py", line 60, in <module>
print(preprocessing.get_feature_names_out())
File "F:\****\Python Projects\ML-Book-Practice\venv\lib\site-packages\sklearn\compose\_column_transformer.py", line 479, in get_feature_names_out
feature_names_out = self._get_feature_name_out_for_transformer(
File "F:\****\Python Projects\ML-Book-Practice\venv\lib\site-packages\sklearn\compose\_column_transformer.py", line 451, in _get_feature_name_out_for_transformer
return trans.get_feature_names_out(names)
File "F:\****\Python Projects\ML-Book-Practice\venv\lib\site-packages\sklearn\pipeline.py", line 733, in get_feature_names_out
feature_names_out = transform.get_feature_names_out(feature_names_out)
File "F:\****\Python Projects\ML-Book-Practice\venv\lib\site-packages\sklearn\utils\metaestimators.py", line 129, in <lambda>
out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs) # noqa
File "F:\****\Python Projects\ML-Book-Practice\venv\lib\site-packages\sklearn\preprocessing\_function_transformer.py", line 277, in get_feature_names_out
names_out = self.feature_names_out(self, input_features)
TypeError: ratio_pipeline.<locals>.<lambda>() takes 1 positional argument but 2 were given
(20640, 25)
Process finished with exit code 1
These are list of packages installed
from handson-ml3.
Hi @alme7airbi93 ,
Thanks for your feedback. The new feature name tracking in Scikit-Learn is great but it's not entirely finished (as of Scikit-Learn 1.0.2). Since I expect that it will be finished by the time the 3rd edition of my book is released, I chose to anticipate what's coming, and write the book as if everything already works. To ensure that everything works well, I have added the following function to the Colab notebook:
def monkey_patch_get_signature_names_out():
"""Monkey patch some classes which did not handle get_feature_names_out()
correctly in 1.0.0."""
from inspect import Signature, signature, Parameter
import pandas as pd
from sklearn.impute import SimpleImputer
from sklearn.pipeline import make_pipeline, Pipeline
from sklearn.preprocessing import FunctionTransformer, StandardScaler
default_get_feature_names_out = StandardScaler.get_feature_names_out
if not hasattr(SimpleImputer, "get_feature_names_out"):
print("Monkey-patching SimpleImputer.get_feature_names_out()")
SimpleImputer.get_feature_names_out = default_get_feature_names_out
if not hasattr(FunctionTransformer, "get_feature_names_out"):
print("Monkey-patching FunctionTransformer.get_feature_names_out()")
orig_init = FunctionTransformer.__init__
orig_sig = signature(orig_init)
def __init__(*args, feature_names_out=None, **kwargs):
orig_sig.bind(*args, **kwargs)
orig_init(*args, **kwargs)
args[0].feature_names_out = feature_names_out
__init__.__signature__ = Signature(
list(signature(orig_init).parameters.values()) + [
Parameter("feature_names_out", Parameter.KEYWORD_ONLY)])
def get_feature_names_out(self, names=None):
if self.feature_names_out is None:
return default_get_feature_names_out(self, names)
elif callable(self.feature_names_out):
return self.feature_names_out(names)
else:
return self.feature_names_out
FunctionTransformer.__init__ = __init__
FunctionTransformer.get_feature_names_out = get_feature_names_out
monkey_patch_get_signature_names_out()
After you run this code, the code in the book should work fine.
Note: I believe this is the only place in the book where the code won't run without some tweaks. But if you do run into any other problem, please make sure to check out the notebook: it should contain working code.
Hope this helps!
from handson-ml3.
Related Issues (20)
- [QUESTION] Clarification about likelihood and PDF HOT 1
- Chapter 16: Downloading Shakespeare model: I get exception downloading the shakespeare_model HOT 2
- [QUESTION] Chapter 14: Asking about GoogLeNet's archietcture
- [QUESTION] Chapter 2: Definition of `similarities` is subject to information leakage? HOT 2
- [QUESTION] Use of Normalization layer with keras_tuner
- [IDEA] Add instructions on how to build TF from source to make notebooks more accessible to those who have different GPUs HOT 1
- [QUESTION] "Installing and Starting TensorFlow Serving" in chapter 19 HOT 1
- [QUESTION] CHAPTER 2: Custom Transformer Issue with Joblib
- [QUESTION] Creating a Prediction Service on Vertex AI (chapter 19: training_and_deploying_at_scale.ipynb)
- [QUESTION] Figure 4-8
- Graphviz installation (Windows)
- [BUG] Chapter 10: number of output arguments of model.evaluate(...) for multiple outputs
- [BUG] Chapter 10: Syntax for saving/restoring keras model has changed
- [QUESTION]
- [BUG] Unable to run `docker compose` following the instructions: /opt/conda/envs/homl3/bin/jupyter directory missing HOT 2
- [invalid] CH11 - Faster Optimizations: incorrect use of momentum instead of just SGD
- [BUG] folder "datasets" is missing from the repo HOT 2
- [BUG] Chapter 15: pandas-implementation for 'resample' has changed
- [QUESTION] What is the correct form of Equation 4-13 in CH. 4 Logistic Regression?
- [BUG] Instead of underperforming it is written outperforming in 07_ensemble_learning_and_random_forests.ipynb HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handson-ml3.