aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/python
diff options
context:
space:
mode:
authorXusen Yin <yinxusen@gmail.com>2015-11-17 13:59:59 -0800
committerXiangrui Meng <meng@databricks.com>2015-11-17 13:59:59 -0800
commit328eb49e6222271337e09188853b29c8f32fb157 (patch)
treeddebcfb1f3430cfd084e901af71b71ba7259d1d9 /examples/src/main/python
parentfa603e08de641df16d066302be5d5f92a60a923e (diff)
downloadspark-328eb49e6222271337e09188853b29c8f32fb157.tar.gz
spark-328eb49e6222271337e09188853b29c8f32fb157.tar.bz2
spark-328eb49e6222271337e09188853b29c8f32fb157.zip
[SPARK-11729] Replace example code in ml-linear-methods.md using include_example
JIRA link: https://issues.apache.org/jira/browse/SPARK-11729 Author: Xusen Yin <yinxusen@gmail.com> Closes #9713 from yinxusen/SPARK-11729.
Diffstat (limited to 'examples/src/main/python')
-rw-r--r--examples/src/main/python/ml/linear_regression_with_elastic_net.py44
-rw-r--r--examples/src/main/python/ml/logistic_regression_with_elastic_net.py44
2 files changed, 88 insertions, 0 deletions
diff --git a/examples/src/main/python/ml/linear_regression_with_elastic_net.py b/examples/src/main/python/ml/linear_regression_with_elastic_net.py
new file mode 100644
index 0000000000..b027827633
--- /dev/null
+++ b/examples/src/main/python/ml/linear_regression_with_elastic_net.py
@@ -0,0 +1,44 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from __future__ import print_function
+
+from pyspark import SparkContext
+from pyspark.sql import SQLContext
+# $example on$
+from pyspark.ml.regression import LinearRegression
+# $example off$
+
+if __name__ == "__main__":
+ sc = SparkContext(appName="LinearRegressionWithElasticNet")
+ sqlContext = SQLContext(sc)
+
+ # $example on$
+ # Load training data
+ training = sqlContext.read.format("libsvm").load("data/mllib/sample_libsvm_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: " + str(lrModel.coefficients))
+ print("Intercept: " + str(lrModel.intercept))
+ # $example off$
+
+ sc.stop()
diff --git a/examples/src/main/python/ml/logistic_regression_with_elastic_net.py b/examples/src/main/python/ml/logistic_regression_with_elastic_net.py
new file mode 100644
index 0000000000..b0b1d27e13
--- /dev/null
+++ b/examples/src/main/python/ml/logistic_regression_with_elastic_net.py
@@ -0,0 +1,44 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from __future__ import print_function
+
+from pyspark import SparkContext
+from pyspark.sql import SQLContext
+# $example on$
+from pyspark.ml.classification import LogisticRegression
+# $example off$
+
+if __name__ == "__main__":
+ sc = SparkContext(appName="LogisticRegressionWithElasticNet")
+ sqlContext = SQLContext(sc)
+
+ # $example on$
+ # Load training data
+ training = sqlContext.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt")
+
+ lr = LogisticRegression(maxIter=10, regParam=0.3, elasticNetParam=0.8)
+
+ # Fit the model
+ lrModel = lr.fit(training)
+
+ # Print the coefficients and intercept for logistic regression
+ print("Coefficients: " + str(lrModel.coefficients))
+ print("Intercept: " + str(lrModel.intercept))
+ # $example off$
+
+ sc.stop()