2016-06-23 87 views
-1

我正在使用數據集來查看工資與大學GPA之間的關係。我正在使用sklearn線性迴歸模型。我認爲這些係數應該是攔截和關閉的。相應功能的值。但該模型給出了單一的價值。sklearn線性迴歸係數具有單個值輸出

from sklearn.cross_validation import train_test_split 
from sklearn.linear_model import LinearRegression 

# Use only one feature : CollegeGPA 
labour_data_gpa = labour_data[['collegeGPA']] 

# salary as a dependent variable 
labour_data_salary = labour_data[['Salary']] 

# Split the data into training/testing sets 
gpa_train, gpa_test, salary_train, salary_test = train_test_split(labour_data_gpa, labour_data_salary) 

# Create linear regression object 
regression = LinearRegression() 

# Train the model using the training sets (first parameter is x) 
regression.fit(gpa_train, salary_train) 

#coefficients 
regression.coef_ 

The output is : Out[12]: array([[ 3235.66359637]]) 

回答

0
salary_pred = regression.predict(gpa_test) 
print salary_pred 
print salary_test 

我覺得小號alary_pred = regression.coef_*salary_test。 試試通過pyplot打印salary_predsalary_test。圖可以解釋每一件事情。