E.g I have a dataframe: df[['A'],['B'],['C'],['D'],['E'],['F'],['G']] with7 feathers(X_train) and a target(Y_train) y[]. I want tocalculate the model score or R-square for each univariateregression. How do I write the loop in python?
from sklearn.linear_model import LinearRegression
model = LinearRegression()
X, y = df[['A']], target
model.fit(X,y)
r_squared = model.score(df[['age']], target)
print(r_squared)
Code above just calculate one feature. How to use a loop tocalculate all features' R square value and rankthem?
E.g I have a dataframe: df [['A'],['B'],['C'],['D'],['E'],['F'],['G']] with 7 feathers(X_train) and a target(Y_train)
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am