【发布时间】:2020-06-21 10:31:30
【问题描述】:
对于我的项目,我想构建一个分类器,根据结构 MRI 数据中的体素值特征集来预测我的受试者的类别(患者与健康对照)。我使用sklearn.linear_model.LogisticRegression 作为分类器。由于年龄和性别对 sMRI 数据中的体素强度有影响,因此我想将它们作为协变量包含在我的分类任务中。我怎样才能在 scikit-learn 中做到这一点?我只是将它们添加到我的功能集中吗?如果是,我该如何处理协变量的不同尺度(年龄是连续的,性别是分类的)?
这是一个简单的虚拟示例:
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
rng = np.random.RandomState(42)
# dummy feature set (columns represent voxels)
X = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
# dummy labels (1 = patients, 0= healthy controls)
y = np.array([1,0,1,0])
# dummy covariates (age and gender) - These should be included in my classification task
age = np.array([18,25,31,55])
gender = np.array([1,1,0,0])
# z-standardize features
scaler = StandardScaler()
X = scaler.fit_transform(X)
# classification task
lr = LogisticRegression(random_state=rng)
lr.fit(X, y)
predictions = lr.predict(X)
这篇文章可能与earlier one相关
【问题讨论】:
标签: scikit-learn