File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 6
6
extension : .md
7
7
format_name : markdown
8
8
format_version : ' 1.3'
9
- jupytext_version : 1.14 .1
9
+ jupytext_version : 1.16 .1
10
10
kernelspec :
11
- display_name : Python 3
11
+ display_name : Python 3 (ipykernel)
12
12
language : python
13
13
name : python3
14
14
language_info :
@@ -20,7 +20,7 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.8.8
23
+ version : 3.10.0
24
24
plotly :
25
25
description : Visualize regression in scikit-learn with Plotly.
26
26
display_as : ai_ml
@@ -412,6 +412,7 @@ import pandas as pd
412
412
import plotly.express as px
413
413
import plotly.graph_objects as go
414
414
from sklearn.linear_model import LassoCV
415
+ from sklearn.preprocessing import StandardScaler
415
416
416
417
N_FOLD = 6
417
418
@@ -421,9 +422,13 @@ X = df.drop(columns=['lifeExp', 'iso_num'])
421
422
X = pd.get_dummies(X, columns = [' country' , ' continent' , ' iso_alpha' ])
422
423
y = df[' lifeExp' ]
423
424
425
+ # Normalize the data
426
+ scaler = StandardScaler()
427
+ X_scaled = scaler.fit_transform(X)
428
+
424
429
# 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)
427
432
mean_alphas = model.mse_path_.mean(axis = - 1 )
428
433
429
434
fig = go.Figure([
You can’t perform that action at this time.
0 commit comments