cross_validation不推荐使用该模块。新模块
model_selection已取代它。因此,您所做的一切
cross_validation。现在可在中使用
model_selection。然后,您上面的代码将变为:
feature = [df['age'], df['job'], df['marital'], df['education'], df['default'], df['housing'], df['loan'], df['contact'], df['month'], df['day_of_week'], df['campaign'], df['pdays'], df['previous'], df['emp.var.rate'], df['cons.price.idx'], df['cons.conf.idx'], df['euribor3m'], df['nr.employed']]label = [df['y']]from sklearn.model_selection import train_test_splitfrom sklearn.model_selection import cross_val_score
现在,就声明X和y而言,为什么要将它们包装在列表中。像这样使用它们:
feature = df[['age', 'job', 'marital', 'education', 'default', 'housing', 'loan', 'contact', 'month', 'day_of_week', 'campaign', 'pdays', 'previous', 'emp.var.rate', 'cons.price.idx', 'cons.conf.idx', 'euribor3m', 'nr.employed']]label = df['y']
然后,您可以简单地使用您的代码,而无需进行任何更改。
# Model Training x = feature[:]y = labelx_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.5)
对于您关于交叉验证折叠的最后一个问题,sklearn中有多个类可以做到这一点(取决于任务)。请看一下:
- http://scikit-learn.org/stable/modules/classes.html#splitter-classes
其中包含折叠迭代器。请记住,所有这些都在
model_selection包装中。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)