本文介绍了错误:__ init __()获得了意外的关键字参数'n_splits'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我将对加利福尼亚州的住房数据集执行 ShuffleSplit()方法(来源: https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html )以适合SGD回归。 但是,应用方法时会发生 n_splits错误。 代码如下:I am going to perform ShuffleSplit() method for California housing dataset (Source: https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html) to fit SGD regression.However, the 'n_splits' error is occurred when method is applied.The code is following:from sklearn import cross_validation, grid_search, linear_model, metricsimport numpy as npimport pandas as pdfrom sklearn.preprocessing import scalefrom sklearn.cross_validation import ShuffleSplithousing_data = pd.read_csv('cal_housing.csv', header = 0, sep = ',')housing_data.fillna(housing_data.mean(), inplace=True)df=pd.get_dummies(housing_data)y_target = housing_data['median_house_value'].valuesx_features = housing_data.drop(['median_house_value'], axis = 1)from sklearn.cross_validation import train_test_splitfrom sklearn import model_selectiontrain_x, test_x, train_y, test_y = model_selection.train_test_split(x_features, y_target, test_size=0.2, random_state=4)reg = linear_model.SGDRegressor(random_state=0)cv = ShuffleSplit(n_splits = 10, test_size = 0.2, random_state = 0)错误如下:---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-22-8f8760b04f8c> in <module>()----> 1 cv = ShuffleSplit(n_splits = 10, test_size = 0.2, random_state = 0)TypeError: __init__() got an unexpected keyword argument 'n_splits'我用 0.18版本更新了scikit-learn。I updated scikit-learn with 0.18 version. Anaconda版本: 4.5.8Anaconda version: 4.5.8您能对此问题提供建议吗?Could you please advise on this issue?推荐答案您正在混淆两个不同的模块。You are mixing up two different modules.在0.18之前,cross_validation用于ShuffleSplit。因此,不存在 n_splits 。 n 用于定义拆分数Before 0.18, cross_validation was used for ShuffleSplit. In that, n_splits was not present. n was used to define the number of splits但是由于您现在已更新为0.18,因此 cross_validation 和 grid_search 。But since you have updated to 0.18 now, cross_validation and grid_search has been deprecated in favor of model_selection.在此处的文档中提到,并且这些模块将从版本0.20This is mentioned in docs here, and these modules will be removed from version 0.20所以代替此:from sklearn.cross_validation import ShuffleSplitfrom sklearn.cross_validation import train_test_split这样做:from sklearn.model_selection import ShuffleSplitfro m sklearn.model_selection import train_test_splitm sklearn.model_selection import train_test_split然后您可以使用 n_splits 。cv = ShuffleSplit(n_splits = 10, test_size = 0.2, random_state = 0) 这篇关于错误:__ init __()获得了意外的关键字参数'n_splits'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-20 18:55