実現したいこと
最小二乗法の計算をし、単回帰の線を引く
発生している問題
TypeError: No loop matching the specified signature and casting
was found for ufunc lstsq_n というエラーが発生しうまくいきません。
試したこと
同様のエラーを調べるとfloatに変える意見があったので、
X = np.array([[value, 1] for value in X])を
X = np.array([[value, 1] for value in X], dtype = np.float64 )に変えるなどしましたが、うまくいきませんでした。
よろしくお願いいたします。
###該当のソースコード
python
1import numpy as np 2import pandas as pd 3from pandas import Series, DataFrame 4import matplotlib.pyplot as plt 5import seaborn as sns 6sns.set_style('whitegrid') 7%matplotlib inline 8 9from sklearn.datasets import load_boston 10boston = load_boston() 11boston_df = DataFrame(boston.data) 12boston_df.columns = boston.feature_names 13boston_df['Price'] = boston.target 14X = boston_df.RM 15X = np.vstack(boston_df.RM) 16 17Y = boston_df.Price 18X = np.array([[value, 1] for value in X]) 19a, b = np.linalg.lstsq(X, Y)[0]
pyhon
1C:\Users\neiso\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: `rcond` parameter will change to the default of machine precision times ``max(M, N)`` where M and N are the input matrix dimensions. 2To use the future default and silence this warning we advise to pass `rcond=None`, to keep using the old, explicitly pass `rcond=-1`. 3 """Entry point for launching an IPython kernel. 4--------------------------------------------------------------------------- 5TypeError Traceback (most recent call last) 6<ipython-input-36-6700a4df6204> in <module> 7----> 1 a, b = np.linalg.lstsq(X, Y)[0] 8 9~\Anaconda3\lib\site-packages\numpy\linalg\linalg.py in lstsq(a, b, rcond) 10 2234 # lapack can't handle n_rhs = 0 - so allocate the array one larger in that axis 11 2235 b = zeros(b.shape[:-2] + (m, n_rhs + 1), dtype=b.dtype) 12-> 2236 x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj) 13 2237 if m == 0: 14 2238 x[...] = 0 15 16TypeError: No loop matching the specified signature and casting 17was found for ufunc lstsq_n

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/10/29 13:29