【发布时间】:2015-11-20 16:48:05
【问题描述】:
我正在使用 dict vectorize 将我的分类变量转换为稀疏矩阵。然后使用逻辑回归和随机森林来训练模型。我的问题是,下次有新数据进来时,如何将其转换为稀疏矩阵框架,然后使用训练好的模型进行预测?
这是我的代码示例:
dv_x, y = dictVectorizeData(inputData, header)
# dv_x is a <740051x1112 sparse matrix of type '<type 'numpy.float64'>'
# with 9620663 stored elements in Compressed Sparse Row format>
lr_cv = LogisticRegressionCV(penalty='l1', solver='liblinear', Cs=[10**i for i in range(-4,2)], cv=5, refit=True)
lr_cv.fit(dv_X, Y)
现在有一个新数据,格式如下:
{
'banner_position': '0',
'connspeed': 'broadband',
'creative_format': '728x90',
'creative_id': '4688677',
'day_hour_etc': '1',
'domain': 'cdn.bitmedianetwork.com',
'exch': 'cox',
'home_bus': 'business',
'is_mobile': 'non-mobile',
'os_family': 'windows',
'os_major': '8',
'ua_family': 'ie',
'ua_major': '9'
}
【问题讨论】:
标签: python scikit-learn sparse-matrix