Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

looping through models and plotting their performance

models = {"Linear Regression": LinearRegression(), "Ridge": Ridge(alpha=0.1), "Lasso": Lasso(alpha=0.1)}
results = []

# Loop through the models' values
for model in models.values():
  kf = KFold(n_splits=6, random_state=42, shuffle=True)
  
  # Perform cross-validation
  cv_scores = cross_val_score(model, X_train, y_train, cv=kf)
  
  # Append the results
  results.append(cv_scores)
  
# Create a box plot of the results
plt.boxplot(results, labels=models.keys())
plt.show()
# Import mean_squared_error
from sklearn.metrics import mean_squared_error

for name, model in models.items():
  
  # Fit the model to the training dat
  model.fit(X_train_scaled, y_train)
  
  # Make predictions on the test set
  y_pred = model.predict(X_test_scaled)
  
  # Calculate the test_rmse
  test_rmse = mean_squared_error(y_test, y_pred, squared=False)
  print("{} Test Set RMSE: {}".format(name, test_rmse))
Comment

PREVIOUS NEXT
Code Example
Python :: Collecting package metadata (repodata.json): done Solving environment: failed ResolvePackageNotFound: - python==3.9.13 
Python :: update value in xml python 
Python :: 1041 uri solution 
Python :: create list python 
Python :: ex: git push new local repo 
Python :: Horizontal concatication 
Python :: iterate over batch of dict keys at once python 
Python :: How to draw a Ninja Design using python turtle 
Python :: how to increase width of line in graph of linear regression in matplotlib 
Python :: find mean of list python 
Python :: change form type flask from text to selection flask admin 
Python :: pandas set index integer not float 
Python :: examples of function decorators in Python 
Python :: python import file from same level 
Python :: how to get foregine key field from models 
Python :: python stopwords not defined 
Python :: access nested set with array params python 
Python :: python script superuser 
Python :: how to dynamically search for a class variable in python 
Python :: visual studio code python indent shortcut 
Python :: ModelCheckpoint 
Python :: np.nditer 
Python :: import data from website pandas python medium 
Python :: how to get only non-blank entry of list in python 
Python :: timedelta64 total_mins 
Python :: python compactar arquivo antes de exportar 
Python :: python class definition 
Python :: boolean for duplicate values in a column 
Python :: os get directory from string 
Python :: elevando numero ao quadrado em python 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =