statsmodels - Python OLS with categorical label
问题描述
I have a dataset where I am trying to predict the type of car based off of a number of features. I would like to an OLS regression to see
import statsmodels.api as sm
X = features
# where 0 = sedan, 1 = minivan , etc
y = [0,0,1,0,2,....]
X2 = sm.add_constant(np.array(X))
est = sm.OLS(np.array(y), X2)
est2 = est.fit()
^ I don't feel like doing this is correct because I am not specifying that it is categorical, I feel like the functional form should change. Was wondering if anyone had any insight on this.
解决方案
Ordinary least squares regression assumes a numerical dependent variable, you cannot use it to predict categorical outcomes.
To predict categorical outcomes with a regression model, you want to use multinomial logistic regression, for example using sklearn.
推荐阅读
- c# - 如何创建 C# OTA 代码以根据 ALM 中的测试计划中 Excel 中提供的路径创建文件夹。你能帮我解决这个问题吗?
- point-cloud-library - PCL TransformEstimationSVD 评估
- javascript - iOS chrome - 翻译页面时 xhr.timeout 抛出错误
- javascript - 返回对象时,实时数据库事务似乎不起作用
- ios - iOS:后台上传大文件的问题
- python - 将列表列表转换为 Python 中的数据框?
- swift - 在 Swift 中调用函数
- networking - 使用 Cypress 捕获所有网络请求并将其响应时间写入文件
- android-studio - 在 Android Studio 中使用 Vysor 在 Google Glass 2 上远程开发应用程序
- c# - C# 和 Moq:如何验证实例方法正在调用正确的辅助实例方法?