E.g I have a dataframe: df [['A'],['B'],['C'],['D'],['E'],['F'],['G']] with 7 feathers(X_train) and a target(Y_train)

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

E.g I have a dataframe: df [['A'],['B'],['C'],['D'],['E'],['F'],['G']] with 7 feathers(X_train) and a target(Y_train)

Post by answerhappygod »

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?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply