2017-10-06 1 views
0

私は42のアパートからの面積と価格のデータセットを持っています。私はdatabricksでpythonを使用しており、カラムの区切り文字として,のcsvファイルをロードしました。後で、私は倍精度として整数と価格として領域を指定しました。それから私は、グラフのライブラリをインポートし、回帰を実行します。Fit関数は柔軟なタイプのreduceを実行できません

import matplotlib.pyplot as plt 
from sklearn import linear_model 

後、私は私のデータベース読む:次の行を含む

aptos=sqlContext.read.format('csv').options(header='true', 
interSchema='true').load('/FileStore/tables/yl3r1mgv1507304115516/aptos_dataset-5ad32.csv') 
display(aptos) 

を、私は、データベースからの列と入力変数を作成しました:

X=aptos.select("area").collect() 
Y=aptos.select("precio").collect() 

次に、私の回帰モデルを作成します。

regr = linear_model.LinearRegression() 

この時点で私は問題ありません。私は次の行を実行する場合でも:

regr.fit(X,Y) 

を私はエラーを取得:

TypeError: cannot perform reduce with flexible type 

私はより多くの細部を見ることができます:

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<command-2158797891361999> in <module>() 
     1 
     2 
----> 3 regr.fit(X,Y) 

/databricks/python/local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in fit(self, X, y, sample_weight) 
    517   X, y, X_offset, y_offset, X_scale = self._preprocess_data(
    518    X, y, fit_intercept=self.fit_intercept, normalize=self.normalize, 
--> 519    copy=self.copy_X, sample_weight=sample_weight) 
    520 
    521   if sample_weight is not None: 

/databricks/python/local/lib/python2.7/site-packages/sklearn/linear_model/base.pyc in _preprocess_data(X, y, fit_intercept, normalize, copy, sample_weight, return_mean) 
    197    else: 
    198     X_scale = np.ones(X.shape[1]) 
--> 199   y_offset = np.average(y, axis=0, weights=sample_weight) 
    200   y = y - y_offset 
    201  else: 

/databricks/python/local/lib/python2.7/site-packages/numpy/lib/function_base.pyc in average(a, axis, weights, returned) 
    933 
    934  if weights is None: 
--> 935   avg = a.mean(axis) 
    936   scl = avg.dtype.type(a.size/avg.size) 
    937  else: 

/databricks/python/local/lib/python2.7/site-packages/numpy/core/_methods.pyc in _mean(a, axis, dtype, out, keepdims) 
    63   dtype = mu.dtype('f8') 
    64 
---> 65  ret = umr_sum(arr, axis, dtype, out, keepdims) 
    66  if isinstance(ret, mu.ndarray): 
    67   ret = um.true_divide(

TypeError: cannot perform reduce with flexible type 

私は謝るが、私は自分のデータベースを共有することはできません。私はPythonで新しいです、私はRの専門知識を持っています。私はあなたの助けに感謝します。

+0

をインポートしたデータのスキーマは何ですか?おそらく 'X'と' Y'の文字列があります。また、 'interSchema = 'true'ではなく' inferSchema = 'true' 'です。 – Abdou

答えて

0

アブドゥーに感謝します。私のデータベースを読んでタイピングエラーが、これは正しい方法で、ありました:

aptos=sqlContext.read.format('csv').options(header='true', inferSchema='true').load('/FileStore/tables/yl3r1mgv1507304115516/aptos_dataset-5ad32.csv') 

今回帰が働いている:

regr.fit(X,Y) 
Out[4]: LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) 
関連する問題