以下のように実行させると、pd.DataFrameでエラーとなってしまいます。
データの形式がおかしいのでしょうか?
お詳しい方、ご指導をお願いします。
clf = svm.SVC(C=1, gamma=0.1,kernel='linear') lr = clf lr.fit(x_train_std,y_train) print("coefficient = ", lr.coef_)
coefficient = [[-1.08612794e-04 -7.38426885e-05 1.97218963e-01 -5.17674248e-01 -3.53402272e-01 -5.99362153e-04 6.74791189e-01 -2.11873712e-01 -6.47116086e-01 -4.58126579e-04]]
importance = pd.DataFrame({ '変数' :df_X.columns, '重要度' :lr.coef_}) importance
Exception Traceback (most recent call last) <ipython-input-38-684db6aece34> in <module> ----> 1 importance = pd.DataFrame({ '変数' :df_X.columns, '重要度' :lr.coef_}) 2 importance ~\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, data, index, columns, dtype, copy) 390 dtype=dtype, copy=copy) 391 elif isinstance(data, dict): --> 392 mgr = init_dict(data, index, columns, dtype=dtype) 393 elif isinstance(data, ma.MaskedArray): 394 import numpy.ma.mrecords as mrecords ~\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in init_dict(data, index, columns, dtype) 210 arrays = [data[k] for k in keys] 211 --> 212 return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) 213 214 ~\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype) 54 55 # don't force copy because getting jammed in an ndarray anyway ---> 56 arrays = _homogenize(arrays, index, dtype) 57 58 # from BlockManager perspective ~\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in _homogenize(data, index, dtype) 275 val = lib.fast_multiget(val, oindex.values, default=np.nan) 276 val = sanitize_array(val, index, dtype=dtype, copy=False, --> 277 raise_cast_failure=False) 278 279 homogenized.append(val) ~\Anaconda3\lib\site-packages\pandas\core\internals\construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure) 656 elif subarr.ndim > 1: 657 if isinstance(data, np.ndarray): --> 658 raise Exception('Data must be 1-dimensional') 659 else: 660 subarr = com.asarray_tuplesafe(data, dtype=dtype) Exception: Data must be 1-dimensional
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。