Scikit learn sklearn SVC投掷;“整形误差”;行刑时
上下文 我尝试在我自己的数据上使用交叉验证中的方法(从csv导入,无缺失值,所有插值,无缺失,一些0,一些负到正范围,大部分是正范围)。由于使用shift进行偏移,初始数据缺少页眉和页脚行,但通过train_test_split函数中的[1:,][:-1]进行处理 无论我如何尝试在自己的数据中包含代码,都会抛出一个错误。我可以使用train_test_split函数为大多数其他函数分割数据,我怀疑错误与数据的结构方式有关 到csv 被解读为Scikit learn sklearn SVC投掷;“整形误差”;行刑时,scikit-learn,svm,sklearn-pandas,Scikit Learn,Svm,Sklearn Pandas,上下文 我尝试在我自己的数据上使用交叉验证中的方法(从csv导入,无缺失值,所有插值,无缺失,一些0,一些负到正范围,大部分是正范围)。由于使用shift进行偏移,初始数据缺少页眉和页脚行,但通过train_test_split函数中的[1:,][:-1]进行处理 无论我如何尝试在自己的数据中包含代码,都会抛出一个错误。我可以使用train_test_split函数为大多数其他函数分割数据,我怀疑错误与数据的结构方式有关 到csv 被解读为 input_file = "parsed.csv"
input_file = "parsed.csv"
df = pd.read_csv(input_file, header = 0)
x = df.loc[0:,[
...
]]
我最初尝试过。
clf = svm.SVC(kernel='linear', C=1).fit(X_train,y_train)
引发错误的
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py:578: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
---------------------------------------------------------------------------
ValueError
Traceback (most recent call last)
<ipython-input-435-eae5045a136b> in <module>
ValueError Traceback (most recent call last)
<ipython-input-433-9ef18f8c2bef> in <module>
90 #np.array(y_train).flatten()
91 #dir(model_training)
---> 92 clf = svm.SVC(kernel='linear', C=1).fit(np.array(X_train).flatten(), np.array(y_train).flatten())
93
94 #deltas
/opt/conda/lib/python3.6/site-packages/sklearn/svm/base.py in fit(self, X, y, sample_weight)
147 self._sparse = sparse and not callable(self.kernel)
148
--> 149 X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
150 y = self._validate_targets(y)
151
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
571 X = check_array(X, accept_sparse, dtype, order, copy, force_all_finite,
572 ensure_2d, allow_nd, ensure_min_samples,
--> 573 ensure_min_features, warn_on_dtype, estimator)
574 if multi_output:
575 y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
439 "Reshape your data either using array.reshape(-1, 1) if "
440 "your data has a single feature or array.reshape(1, -1) "
--> 441 "if it contains a single sample.".format(array))
442 array = np.atleast_2d(array)
443 # To ensure that array flags are maintained
ValueError: Expected 2D array, got 1D array instead:
array=[ 9.60040000e+01 9.86000000e+01 1.58631818e+01 ..., 4.20250000e+00
1.56299000e+02 -7.67852077e-03].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
产生
(285, 47)
(285, 1)
CSUSHPISA CUUR0000SETB01 DCOILBRENTEU RECPROUSM156N CPIHOSNS \
149 96.004 98.600 15.863182 0.02 164.100
272 148.031 220.542 67.646190 0.34 217.178
171 111.653 132.800 25.657143 32.02 175.400
187 123.831 120.900 26.651364 0.52 181.700
309 143.607 322.934 111.710870 0.02 223.708
CPALTT01USM661S PAYNSA CUUR0000SEHA CPIAUCSL LNS12300060 ... \
149 70.037170 130150 177.100 166.000 81.4 ...
272 91.074058 130589 248.965 215.861 75.1 ...
171 74.425041 132349 190.200 176.400 80.9 ...
187 76.154875 130356 200.200 180.500 79.3 ...
309 97.730543 135649 262.707 231.638 76.1 ...
CUUR0000SEHA CPIAUCSL LNS12300060 GS5 CUUR0000SETA01 \
149 31293.570000 27556.000000 6625.96 31.6064 20363.250000
272 61999.504985 46506.173145 5677.56 6.0909 18043.950080
171 36061.920000 31064.040000 6577.17 22.0864 20377.560000
187 39999.960000 32490.000000 6272.63 12.5349 19154.470000
309 68677.126647 53511.852570 5783.60 0.4757 20697.980975
CPILFESL CPILFENS PCECTPICTM CSUSHPINSA CSUSHPINSA
149 31169.900000 31187.560000 4.2025 96.393 -0.010515
272 48271.560320 48341.204652 4.2025 149.631 0.006909
171 34187.970000 34391.680000 4.2025 111.248 -0.007727
187 36404.550000 36347.300000 4.2025 124.729 -0.008424
309 53287.764816 53373.875280 4.2025 143.977 0.002688
[5 rows x 47 columns]
CSUSHPINSA
149 0.008579
272 -0.006950
171 0.008584
187 0.006125
309 -0.000042
---------------------------------------------------------------------------
错误
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py:578: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
---------------------------------------------------------------------------
ValueError
Traceback (most recent call last)
<ipython-input-435-eae5045a136b> in <module>
ValueError Traceback (most recent call last)
<ipython-input-433-9ef18f8c2bef> in <module>
90 #np.array(y_train).flatten()
91 #dir(model_training)
---> 92 clf = svm.SVC(kernel='linear', C=1).fit(np.array(X_train).flatten(), np.array(y_train).flatten())
93
94 #deltas
/opt/conda/lib/python3.6/site-packages/sklearn/svm/base.py in fit(self, X, y, sample_weight)
147 self._sparse = sparse and not callable(self.kernel)
148
--> 149 X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
150 y = self._validate_targets(y)
151
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
571 X = check_array(X, accept_sparse, dtype, order, copy, force_all_finite,
572 ensure_2d, allow_nd, ensure_min_samples,
--> 573 ensure_min_features, warn_on_dtype, estimator)
574 if multi_output:
575 y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,
/opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
439 "Reshape your data either using array.reshape(-1, 1) if "
440 "your data has a single feature or array.reshape(1, -1) "
--> 441 "if it contains a single sample.".format(array))
442 array = np.atleast_2d(array)
443 # To ensure that array flags are maintained
ValueError: Expected 2D array, got 1D array instead:
array=[ 9.60040000e+01 9.86000000e+01 1.58631818e+01 ..., 4.20250000e+00
1.56299000e+02 -7.67852077e-03].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
ValueError回溯(最近一次调用)
在里面
90#np.数组(y#u列).flatten()
91#署长(模范大学训练)
--->92 clf=svm.SVC(kernel='linear',C=1).fit(np.array(X_列).flatten(),np.array(y_列).flatten())
93
94#三角洲
/opt/conda/lib/python3.6/site-packages/sklearn/svm/base.py in-fit(self,X,y,sample_-weight)
147 self.\u sparse=稀疏且不可调用(self.kernel)
148
-->149 X,y=check_X_y(X,y,dtype=np.float64,order='C',accept_sparse='csr')
150 y=自我验证目标(y)
151
/检查X_y中的opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py(X,y,接受稀疏,数据类型,顺序,复制,强制所有有限,确保2d,允许nd,多输出,确保最小样本,确保最小特征,y数字,警告数据类型,估计器)
571 X=检查数组(X,接受稀疏,数据类型,顺序,复制,强制所有有限,
572确保2d,允许nd,确保最小样本,
-->573确保功能、警告(数据类型、估计器)
574如果多输出:
575 y=检查数组(y,'csr',强制所有有限=真,确保2d=假,
/检查数组中的opt/conda/lib/python3.6/site-packages/sklearn/utils/validation.py(数组、接受稀疏、数据类型、顺序、复制、强制所有有限、确保2d、允许nd、确保最小样本、确保最小特征、警告数据类型、估计器)
439“使用数组重塑您的数据。如果”
440“您的数据只有一个特征或数组。重塑(1,-1)”
-->441“如果它包含单个样本。”。格式(数组))
442阵列=np.至少2维(阵列)
443#确保保留阵列标志
ValueError:应为2D数组,而应为1D数组:
数组=[9.600040000E+01 9.86000000e+01 1.58631818e+01…,4.20250000e+00
1.56299000e+02-7.67852077e-03]。
使用数组重塑数据。如果数据具有单个特征或数组,则重塑(-1,1)。如果数据包含单个样本,则重塑(1,-1)。
使用:
你能告诉我们Xtrain和Ytrain是什么样子的吗?这样我们就可以重现错误了?你需要什么?我认为总指挥已经足够了。类型命令?指向原始csv的链接?理想情况下,DataFrame构造函数会有所帮助,否则很难从head()转到DataFrame.df=pd.read\u csv(输入文件,header=0)。。。88#pd.数据帧。从#记录(Delta)89类型(Delta)-->90 y#U列。重塑(len(y#U列),1)/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py在#getattr#(self,name)4374如果self.#信息轴中。可以保存#标识符#并且#保存#名称#:4375->4376返回对象。uuuu getattribute_uuuuuu(self,name)4377 4378 def uuuuu setattr_uuuuu(self,name,value):AttributeError:'DataFrame'对象没有属性'Reforme'DataFrame.values.Reforme(),如果它是DataFrame.clf=svm.SVC(kernel='linear',=1).fit(X_train,y_train.values.Reforme(len(y(y_train),1))/opt/conda/lib/python3.6/site packages/sklearn/utils/validation.py:578:DataConversionWarning:1d数组时传递了列向量y。请将y的形状更改为(n_samples,),例如使用ravel()。y=column_或_1d(y,warn=True)--------------------------------------------------------------------------------------ValueError(谷歌硬盘url和parsed.csv)set1和yfutureyield是如何构造的?好的,当运行简化版本clf=svm.SVC(kernel='linear',C=1)时,我刚刚播放了所有代码。fit(X_train,y_train),我得到了一个与分类器相关的不同错误,它抱怨SVC不能处理连续变量,这是有意义的,因为它是一个分类器和输出变量continuos,我将它更改为SVR,它是回归器,并且起作用。
clf = svm.SVR(kernel='linear', C=1).fit(X_train,y_train.values.flatten())