Wrap-up quizz Q1 find min max

Hello.

I understood the code given in the solution.

I had a similar code but surprisingly when I asked to print max and min, the values of the form 1e18 were not printed.
However if I just print the coefs_ (and not coefs.max()) I see in the arrays that values are here.
Do you have an explanation ? can you check if my code is correct ?

Thank you very much !

Geoffrey

Here’s my code :

model = Pipeline([("SimpleImputer", SimpleImputer()), 
                  ("StandardScaler", StandardScaler()), 
                  ("LinarRegression", LinearRegression())])

cv_res = cross_validate(model, data_numerical, target, cv=10, 
                        return_estimator=True)
estimators = cv_res['estimator']

for estimator in estimators:
    print(estimator["LinarRegression"].coef_.max())
    print(estimator["LinarRegression"].coef_.min())

Hi, i got min max this way:

coefs = [est[-1].coef_ for est in cv_results["estimator"]]
print(max(max(c) for c in coefs))
print(min(min(c) for c in coefs))
1 Like

Hi, nice, thank you for your reply ! but im still a bit confused about why my code did not give the values expressed with exponential, it’s strange ^^

I recall that we used the scientific notation because it is shown in this manner when plotting the coefficient with matplotlib.

When using print, I don’t recall which notation will be used: depending if you use a Python function (e.g. min, max) or the Pandas/NumPy counterpart that might have different display.

This is also something that can be changed: Format / Suppress Scientific Notation from Python Pandas Aggregation Results - Stack Overflow

Ok I see, thank you