1010
1111# Single lambda
1212print ("\n \n Single lambda" )
13- model = ns .RidgeRegressor (lambda_ = 1.0 )
13+ model = ns .RidgeRegressor (reg_lambda = 1.0 )
1414start = time ()
1515model .fit (X_train , y_train )
1616predictions = model .predict (X_test )
1717end = time ()
1818print (f"Time taken: { end - start } seconds" )
1919print (f"coefs: { model .coef_ } " )
20+ print (f"Test RMSE: { np .sqrt (np .mean ((predictions - y_test )** 2 ))} " )
21+
2022# Access criteria
21- print (f"GCV scores: { model .GCV_ } " )
22- print (f"HKB estimate: { model .HKB_ } " )
23- print (f"LW estimate: { model .LW_ } " )
23+ # print(f"GCV scores: {model.GCV_}")
24+ # print(f"HKB estimate: {model.HKB_}")
25+ # print(f"LW estimate: {model.LW_}")
2426
2527
2628# Multiple lambdas
27- print ("\n \n Multiple lambdas" )
28- model = ns .RidgeRegressor (lambda_ = [0.1 , 1.0 , 10.0 ])
29- start = time ()
30- model .fit (X_train , y_train )
31- end = time ()
32- print (f"Time taken: { end - start } seconds" )
33- predictions = model .predict (X_test ) # Returns predictions for each lambda
34- print (f"coefs: { model .coef_ } " )
35- # Access criteria
36- print (f"GCV scores: { model .GCV_ } " )
37- print (f"HKB estimate: { model .HKB_ } " )
38- print (f"LW estimate: { model .LW_ } " )
29+ # print("\n\n Multiple lambdas")
30+ # model = ns.RidgeRegressor(lambda_=[0.1, 1.0, 10.0])
31+ # start = time()
32+ # model.fit(X_train, y_train)
33+ # end = time()
34+ # print(f"Time taken: {end - start} seconds")
35+ # predictions = model.predict(X_test) # Returns predictions for each lambda
36+ # print(f"coefs: {model.coef_}")
37+ # # Access criteria
38+ # print(f"GCV scores: {model.GCV_}")
39+ # print(f"HKB estimate: {model.HKB_}")
40+ # print(f"LW estimate: {model.LW_}")
3941
40- # Compare coefficients for lambda=1.0
41- print ("\n Comparing coefficients for lambda=1.0:" )
42- print ("Single lambda coefs:" , model .coef_ )
43- print ("Multiple lambda coefs (middle column):" , model .coef_ [:, 1 ])
42+ # # Compare coefficients for lambda=1.0
43+ # print("\nComparing coefficients for lambda=1.0:")
44+ # print("Single lambda coefs:", model.coef_)
45+ # print("Multiple lambda coefs (middle column):", model.coef_[:, 1])
4446
45- # With GPU acceleration
46- #model = RidgeRegressor(lambda_=1.0, backend="gpu")
47+ # # With GPU acceleration
48+ # # model = RidgeRegressor(lambda_=1.0, backend="gpu")
0 commit comments