python中的多重线性回归将不起作用

问题描述 投票:-2回答:1

我有一个包含三个变量的CSV文件(SAT GPA Rand 1,2,3)GPA是因变量SAT和兰德1,2,3是自变量兰德1,2,3没有很强的解释力除了最后三行,一切都在工作

import math
import numpy as np
import pandas as pd
import scipy
import statsmodels.api as sm
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn
sns.set()

data = pd.read_csv(r'E:\The Data Science Course 2019 - All Resources\Part_5_Advanced_Statistical_Methods_(Machine_Learning)\S33_L195\1.02. Multiple linear regression.csv')

data.describe()
SAT         GPA         Rand 1,2,3
count   84.000000   84.000000   84.000000
mean    1845.273810 3.330238    2.059524
std 104.530661  0.271617    0.855192
min 1634.000000 2.400000    1.000000
25% 1772.000000 3.190000    1.000000
50% 1846.000000 3.380000    2.000000
75% 1934.000000 3.502500    3.000000
max 2050.000000 3.810000    3.000000   
y= ["GPA"]
x1 = [["SAT", "Rand 1,2,3"]]
5 - 
x = sm.add_constant(x1) # add the intercept
results = sm.OLS(y,x).fit()
results.summary() 

TypeError:无法使用灵活类型执行归约问题出在数据框中我使用了这段代码,现在可以正常工作了y =数据['GPA']x1 = data [['SAT','Rand 1,2,3']]

python pandas statistics linear-regression
1个回答
0
投票

问题出在我使用此代码的数据框中,现在可以正常工作了y =数据['GPA']x1 = data [['SAT','Rand 1,2,3']]

© www.soinside.com 2019 - 2024. All rights reserved.