forked from haifengl/smile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,318,029 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.haifengl</groupId> | ||
<artifactId>smile-benchmark</artifactId> | ||
<version>1.0.4</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>Smile Benchmark</name> | ||
<description>Statistical Machine Intelligence and Learning Engine -- Benchmark</description> | ||
<url>http://github.com/haifengl/smile</url> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<name>Haifeng Li</name> | ||
<email>[email protected]</email> | ||
<url>http://haifengl.wordpress.com</url> | ||
<roles> | ||
<role>architect</role> | ||
<role>developer</role> | ||
</roles> | ||
<timezone>America/New_York</timezone> | ||
<properties> | ||
<twitter>@haifengl</twitter> | ||
</properties> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<connection>scm:git:[email protected]:haifengl/smile.git</connection> | ||
<developerConnection>scm:git:[email protected]:haifengl/smile.git</developerConnection> | ||
<url>[email protected]:haifengl/smile.git</url> | ||
</scm> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.haifengl</groupId> | ||
<artifactId>smile-core</artifactId> | ||
<version>1.0.4</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.3</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2010 Haifeng Li | ||
* | ||
* Licensed 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 smile.classification; | ||
|
||
import smile.sort.QuickSort; | ||
import smile.data.Attribute; | ||
import smile.math.Math; | ||
import smile.validation.LOOCV; | ||
import smile.data.parser.ArffParser; | ||
import smile.data.AttributeDataset; | ||
import smile.data.NominalAttribute; | ||
import smile.data.parser.DelimitedTextParser; | ||
|
||
/** | ||
* | ||
* @author Haifeng Li | ||
*/ | ||
public class Benchmark { | ||
|
||
public Benchmark() { | ||
} | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Random Forest benchmark"); | ||
DelimitedTextParser parser = new DelimitedTextParser(); | ||
parser.setDelimiter(","); | ||
parser.setColumnNames(true); | ||
parser.setResponseIndex(new NominalAttribute("class"), 8); | ||
try { | ||
AttributeDataset train = parser.parse("Benchmark Train", this.getClass().getResourceAsStream("/smile/data/benchm-ml/train-1m.csv")); | ||
AttributeDataset test = parser.parse("Benchmark Test", this.getClass().getResourceAsStream("/smile/data/benchm-ml/test.csv")); | ||
|
||
double[][] x = train.toArray(new double[train.size()][]); | ||
int[] y = train.toArray(new int[train.size()]); | ||
double[][] testx = test.toArray(new double[test.size()][]); | ||
int[] testy = test.toArray(new int[test.size()]); | ||
|
||
long start = System.currentTimeMillis(); | ||
RandomForest forest = new RandomForest(x, y, 100); | ||
long end = System.currentTimeMillis(); | ||
System.out.format("Random forest 100 trees training time: %.2f%% s\n", (end-start)/1000.0); | ||
|
||
int error = 0; | ||
for (int i = 0; i < testx.length; i++) { | ||
if (forest.predict(testx[i]) != testy[i]) { | ||
error++; | ||
} | ||
} | ||
|
||
System.out.format("Benchmark OOB error rate = %.2f%%\n", 100.0 * forest.error()); | ||
System.out.format("Benchmark error rate = %.2f%%\n", 100.0 * error / testx.length); | ||
} catch (Exception ex) { | ||
System.err.println(ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.