You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ss...@apache.org on 2013/06/02 21:36:47 UTC
svn commit: r1488775 - in /mahout/trunk: CHANGELOG
examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java
examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java
Author: ssc
Date: Sun Jun 2 19:36:47 2013
New Revision: 1488775
URL: http://svn.apache.org/r1488775
Log:
MAHOUT-1196 LogisticModelParameters uses csv.getTargetCategories() even if csv is not used.
Added:
mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java
Modified:
mahout/trunk/CHANGELOG
mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java
Modified: mahout/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/mahout/trunk/CHANGELOG?rev=1488775&r1=1488774&r2=1488775&view=diff
==============================================================================
--- mahout/trunk/CHANGELOG (original)
+++ mahout/trunk/CHANGELOG Sun Jun 2 19:36:47 2013
@@ -2,6 +2,8 @@ Mahout Change Log
Release 0.8 - unreleased
+ MAHOUT-1196: LogisticModelParameters uses csv.getTargetCategories() even if csv is not used. (Vineet Krishnan via ssc)
+
__MAHOUT-1224: Add the option of running a StreamingKMeans pass in the Reducer before BallKMeans (dfilimon)
MAHOUT-993: Some vector dumper flags are expecting arguments. (Andrew Look via robinanil)
Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java?rev=1488775&r1=1488774&r2=1488775&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/LogisticModelParameters.java Sun Jun 2 19:36:47 2013
@@ -92,10 +92,8 @@ public class LogisticModelParameters imp
* Saves a model to an output stream.
*/
public void saveTo(OutputStream out) throws IOException {
- if (lr != null) {
- lr.close();
- }
- targetCategories = csv.getTargetCategories();
+ Closeables.close(lr, false);
+ targetCategories = getCsvRecordFactory().getTargetCategories();
write(new DataOutputStream(out));
}
@@ -133,9 +131,14 @@ public class LogisticModelParameters imp
out.writeInt(numFeatures);
out.writeBoolean(useBias);
out.writeInt(maxTargetCategories);
- out.writeInt(targetCategories.size());
- for (String category : targetCategories) {
- out.writeUTF(category);
+
+ if (targetCategories == null) {
+ out.writeInt(0);
+ } else {
+ out.writeInt(targetCategories.size());
+ for (String category : targetCategories) {
+ out.writeUTF(category);
+ }
}
out.writeDouble(lambda);
out.writeDouble(learningRate);
Added: mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java?rev=1488775&view=auto
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java (added)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/LogisticModelParametersTest.java Sun Jun 2 19:36:47 2013
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package org.apache.mahout.classifier.sgd;
+
+import org.apache.mahout.common.MahoutTestCase;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+
+public class LogisticModelParametersTest extends MahoutTestCase {
+
+ @Test
+ public void serializationWithoutCsv() throws IOException {
+ LogisticModelParameters params = new LogisticModelParameters();
+ params.setTargetVariable("foo");
+ params.setTypeMap(Collections.<String, String>emptyMap());
+ params.setTargetCategories(Arrays.asList("foo", "bar"));
+ params.setNumFeatures(1);
+ params.createRegression();
+
+ //MAHOUT-1196 should work without "csv" being set
+ params.saveTo(new ByteArrayOutputStream());
+ }
+
+}