Skip to content

Commit e0b22d8

Browse files
committed
Update ml-regression.md
1 parent 1dfcb3e commit e0b22d8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

doc/python/ml-regression.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.1
9+
jupytext_version: 1.16.1
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.8.8
23+
version: 3.10.0
2424
plotly:
2525
description: Visualize regression in scikit-learn with Plotly.
2626
display_as: ai_ml
@@ -412,6 +412,7 @@ import pandas as pd
412412
import plotly.express as px
413413
import plotly.graph_objects as go
414414
from sklearn.linear_model import LassoCV
415+
from sklearn.preprocessing import StandardScaler
415416

416417
N_FOLD = 6
417418

@@ -421,9 +422,13 @@ X = df.drop(columns=['lifeExp', 'iso_num'])
421422
X = pd.get_dummies(X, columns=['country', 'continent', 'iso_alpha'])
422423
y = df['lifeExp']
423424

425+
# Normalize the data
426+
scaler = StandardScaler()
427+
X_scaled = scaler.fit_transform(X)
428+
424429
# Train model to predict life expectancy
425-
model = LassoCV(cv=N_FOLD, normalize=True)
426-
model.fit(X, y)
430+
model = LassoCV(cv=N_FOLD)
431+
model.fit(X_scaled, y)
427432
mean_alphas = model.mse_path_.mean(axis=-1)
428433

429434
fig = go.Figure([

0 commit comments

Comments
 (0)