簡體   English   中英

需要 Python 返回 R 平方

[英]Need Python to Return R Squared

我的回歸 model 正在返回系數,但我無法弄清楚如何讓它告訴我 R 平方和調整后的 R 平方。 我需要這些數字以及截距的系數。 任何見解表示贊賞

# import the needed libraries
import pandas as pd
from sklearn.linear_model import LinearRegression

# Import the data
data = pd.read_csv("NBA.csv")

# Specify the features and the target
target = 'Margin'
features = list(data.columns) # This is the column names of your data as a list
features.remove(target) # We remove the target from the list of features

# Train the model
model = LinearRegression() # Instantiate the model
model.fit(data[features].values, data[target].values) # fit the model to the data
print(features) # Returns the name of each feature
print(model.coef_) # Returns the coefficients for each feature (in the same order of your features)

弄清楚了。

    # import the needed libraries
import pandas as pd
from sklearn.linear_model import LinearRegression

# Import the data
data = pd.read_csv("NBA.csv")

# Specify the features and the target
target = 'Margin'
features = list(data.columns) # This is the column names of your data as a list
features.remove(target) # We remove the target from the list of features

# Train the model
model = LinearRegression() # Instantiate the model

model.fit(data[features].values, data[target].values) # fit the model to the data
model.score(data[features].values, data[target].values)
print(features) # Returns the name of each feature
print(model.coef_) # Returns the coefficients for each feature (in the same order of your features)
print(model.score(data[features].values, data[target].values))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM