當前位置: 首頁>>代碼示例>>Python>>正文


Python LinearRegression.save方法代碼示例

本文整理匯總了Python中pyspark.ml.regression.LinearRegression.save方法的典型用法代碼示例。如果您正苦於以下問題:Python LinearRegression.save方法的具體用法?Python LinearRegression.save怎麽用?Python LinearRegression.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyspark.ml.regression.LinearRegression的用法示例。


在下文中一共展示了LinearRegression.save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_linear_regression

# 需要導入模塊: from pyspark.ml.regression import LinearRegression [as 別名]
# 或者: from pyspark.ml.regression.LinearRegression import save [as 別名]
 def test_linear_regression(self):
     lr = LinearRegression(maxIter=1)
     path = tempfile.mkdtemp()
     lr_path = path + "/lr"
     lr.save(lr_path)
     lr2 = LinearRegression.load(lr_path)
     self.assertEqual(lr2.uid, lr2.maxIter.parent,
                      "Loaded LinearRegression instance uid (%s) did not match Param's uid (%s)"
                      % (lr2.uid, lr2.maxIter.parent))
     self.assertEqual(lr._defaultParamMap[lr.maxIter], lr2._defaultParamMap[lr2.maxIter],
                      "Loaded LinearRegression instance default params did not match " +
                      "original defaults")
     try:
         rmtree(path)
     except OSError:
         pass
開發者ID:Bella-Lin,項目名稱:spark,代碼行數:18,代碼來源:tests.py

示例2: print

# 需要導入模塊: from pyspark.ml.regression import LinearRegression [as 別名]
# 或者: from pyspark.ml.regression.LinearRegression import save [as 別名]
lm_transform = lm_model_fit.transform(testDf)
results = lm_transform.select(lm_transform['prediction'], lm_transform['label'])
MSE = results.map(lambda (p,l):(p-l)**2).reduce(lambda x,y:x+y)/results.count()
print("Linear Regression testing Mean Squared Error = " + str(MSE))

res = results.collect()
predsAndLabels = sc.parallelize([i.asDict().values() for i in res])
metrics = RegressionMetrics(predsAndLabels)


print metrics.meanSquaredError
print metrics.rootMeanSquaredError
print metrics.r2
print metrics.explainedVariance

lm_model.save(sc, "LinerRegressionModel")



# LASSO

lasso_model = LinearRegression(featuresCol="features", predictionCol="prediction", maxIter=100, regParam=1.0, elasticNetParam=0.0, tol=1e-6)
lasso_model_fit = lasso_model.fit(trainDf)
lasso_transform = lasso_model_fit.transform(trainDf) #change to a test model
lasso_results = lasso_transform.select(lasso_transform['prediction'], lasso_transform['label'])
lasso_MSE = lasso_results.map(lambda (p,l):(p-l)**2).reduce(lambda x,y:x+y)/results.count()
print("LASSO training Mean Squared Error = " + str(lasso_MSE))

lasso_transform = lasso_model_fit.transform(testDf) #change to a test model
lasso_results = lasso_transform.select(lasso_transform['prediction'], lasso_transform['label'])
lasso_MSE = lasso_results.map(lambda (p,l):(p-l)**2).reduce(lambda x,y:x+y)/results.count()
開發者ID:arifyali,項目名稱:Yelp,代碼行數:33,代碼來源:arif_hive_spark.py


注:本文中的pyspark.ml.regression.LinearRegression.save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。