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 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
412412import plotly.express as px
413413import plotly.graph_objects as go
414414from sklearn.linear_model import LassoCV
415+ from sklearn.preprocessing import StandardScaler
415416
416417N_FOLD = 6
417418
@@ -421,9 +422,13 @@ X = df.drop(columns=['lifeExp', 'iso_num'])
421422X = pd.get_dummies(X, columns = [' country' , ' continent' , ' iso_alpha' ])
422423y = 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)
427432mean_alphas = model.mse_path_.mean(axis = - 1 )
428433
429434fig = go.Figure([
You can’t perform that action at this time.
0 commit comments