2017-12-26 13 views
1

Apache sparkを使用してAx = b問題を解決するにはどうしたらいいですか?私の入力座標行列である:Ax = bソルバーの座標行列Apache Spark

import numpy as np 
import scipy 
from scipy import sparse 
row = np.array([0, 3, 1, 0]) 
col = np.array([0, 3, 1, 2]) 
data = np.array([4, 5, 7, 9]) 
A = sparse.coo_matrix((data, (row, col)), shape=(4, 4)) 
#take the first column of A 
b = sparse.coo_matrix((data, (row, 1)), shape=(4, 1)) 

#Solve Ax = b 
np.linalg.solve(A,b) 

は、今は解決策がなければならないので、ApacheのスパークフレームワークのPythonライブラリを使用して、Ax = bの中のxを解くために必要[1,0,0,0] B以来Aの第1列です

以下はApache Sparkの線形回帰です。ここで、入力が座標行列(A)と座標ベクトル(b)であるように問題を設定するにはどうすればよいですか?

from pyspark.ml.regression import LinearRegression 

# Load training data 
training = spark.read.format("libsvm")\ 
    .load("data/mllib/sample_linear_regression_data.txt") 

lr = LinearRegression(maxIter=10, regParam=0.3, elasticNetParam=0.8) 

# Fit the model 
lrModel = lr.fit(training) 

# Print the coefficients and intercept for linear regression 
print("Coefficients: %s" % str(lrModel.coefficients)) 
print("Intercept: %s" % str(lrModel.intercept)) 

# Summarize the model over the training set and print out some metrics 
trainingSummary = lrModel.summary 
print("numIterations: %d" % trainingSummary.totalIterations) 
print("objectiveHistory: %s" % str(trainingSummary.objectiveHistory)) 
trainingSummary.residuals.show() 
print("RMSE: %f" % trainingSummary.rootMeanSquaredError) 
print("r2: %f" % trainingSummary.r2) 

答えて

1

どのように私は、Apacheの火花を使用してAx = bの問題を解決することができます。

直接(分析的に)することはできません。 Sparkは線形代数ライブラリを提供していません。

間接的に - pyspark.ml.regressionを使用して、OLSの問題をほぼ解決してください。あなたは参照することができます:

関連する問題